~ubuntu-branches/ubuntu/utopic/nautilus/utopic-proposed

« back to all changes in this revision

Viewing changes to .pc/ubuntu_backspace_behaviour.patch/src/nautilus-query-editor.c

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher
  • Date: 2014-02-03 18:18:01 UTC
  • Revision ID: package-import@ubuntu.com-20140203181801-d5ahikqlkqfvxv7k
Tags: 1:3.10.1-0ubuntu3
debian/patches/ubuntu_backspace_behaviour.patch: restore backspace 
behaviour, as a back button, thanks Xavier Claessens (lp: #1108637)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
 
2
/*
 
3
 * Copyright (C) 2005 Red Hat, Inc.
 
4
 *
 
5
 * Nautilus is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License as
 
7
 * published by the Free Software Foundation; either version 2 of the
 
8
 * License, or (at your option) any later version.
 
9
 *
 
10
 * Nautilus is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public
 
16
 * License along with this program; see the file COPYING.  If not,
 
17
 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
18
 * Boston, MA 02111-1307, USA.
 
19
 *
 
20
 * Author: Alexander Larsson <alexl@redhat.com>
 
21
 *
 
22
 */
 
23
 
 
24
#include <config.h>
 
25
#include "nautilus-query-editor.h"
 
26
 
 
27
#include <string.h>
 
28
#include <glib/gi18n.h>
 
29
#include <gio/gio.h>
 
30
#include <gdk/gdkkeysyms.h>
 
31
#include <gtk/gtk.h>
 
32
 
 
33
#include <eel/eel-glib-extensions.h>
 
34
#include <libnautilus-private/nautilus-file-utilities.h>
 
35
 
 
36
typedef enum {
 
37
        NAUTILUS_QUERY_EDITOR_ROW_TYPE,
 
38
        
 
39
        NAUTILUS_QUERY_EDITOR_ROW_LAST
 
40
} NautilusQueryEditorRowType;
 
41
 
 
42
typedef struct {
 
43
        NautilusQueryEditorRowType type;
 
44
        NautilusQueryEditor *editor;
 
45
        GtkWidget *toolbar;
 
46
        GtkWidget *hbox;
 
47
        GtkWidget *combo;
 
48
 
 
49
        GtkWidget *type_widget;
 
50
} NautilusQueryEditorRow;
 
51
 
 
52
 
 
53
typedef struct {
 
54
        const char *name;
 
55
        GtkWidget * (*create_widgets)      (NautilusQueryEditorRow *row);
 
56
        void        (*add_to_query)        (NautilusQueryEditorRow *row,
 
57
                                            NautilusQuery          *query);
 
58
        void        (*add_rows_from_query) (NautilusQueryEditor *editor,
 
59
                                            NautilusQuery *query);
 
60
} NautilusQueryEditorRowOps;
 
61
 
 
62
struct NautilusQueryEditorDetails {
 
63
        GtkWidget *entry;
 
64
        gboolean change_frozen;
 
65
        guint typing_timeout_id;
 
66
 
 
67
        GtkWidget *search_current_button;
 
68
        GtkWidget *search_all_button;
 
69
        char *current_uri;
 
70
 
 
71
        GList *rows;
 
72
 
 
73
        NautilusQuery *query;
 
74
};
 
75
 
 
76
enum {
 
77
        ACTIVATED,
 
78
        CHANGED,
 
79
        CANCEL,
 
80
        LAST_SIGNAL
 
81
}; 
 
82
 
 
83
static guint signals[LAST_SIGNAL];
 
84
 
 
85
static void entry_activate_cb (GtkWidget *entry, NautilusQueryEditor *editor);
 
86
static void entry_changed_cb  (GtkWidget *entry, NautilusQueryEditor *editor);
 
87
static void nautilus_query_editor_changed_force (NautilusQueryEditor *editor,
 
88
                                                 gboolean             force);
 
89
static void nautilus_query_editor_changed (NautilusQueryEditor *editor);
 
90
static NautilusQueryEditorRow * nautilus_query_editor_add_row (NautilusQueryEditor *editor,
 
91
                                                               NautilusQueryEditorRowType type);
 
92
 
 
93
static GtkWidget *type_row_create_widgets      (NautilusQueryEditorRow *row);
 
94
static void       type_row_add_to_query        (NautilusQueryEditorRow *row,
 
95
                                                NautilusQuery          *query);
 
96
static void       type_add_rows_from_query     (NautilusQueryEditor    *editor,
 
97
                                                NautilusQuery          *query);
 
98
 
 
99
 
 
100
 
 
101
static NautilusQueryEditorRowOps row_type[] = {
 
102
        { N_("File Type"),
 
103
          type_row_create_widgets,
 
104
          type_row_add_to_query,
 
105
          type_add_rows_from_query
 
106
        },
 
107
};
 
108
 
 
109
G_DEFINE_TYPE (NautilusQueryEditor, nautilus_query_editor, GTK_TYPE_BOX);
 
110
 
 
111
gboolean
 
112
nautilus_query_editor_handle_event (NautilusQueryEditor *editor,
 
113
                                    GdkEventKey         *event)
 
114
{
 
115
        GtkWidget *toplevel;
 
116
        GtkWidget *old_focus;
 
117
        GdkEvent *new_event;
 
118
        gboolean retval;
 
119
 
 
120
        /* if we're focused already, no need to handle the event manually */
 
121
        if (gtk_widget_has_focus (editor->details->entry)) {
 
122
                return FALSE;
 
123
        }
 
124
 
 
125
        /* never handle these events */
 
126
        if (event->keyval == GDK_KEY_slash || event->keyval == GDK_KEY_Delete) {
 
127
                return FALSE;
 
128
        }
 
129
 
 
130
        /* don't activate search for these events */
 
131
        if (!gtk_widget_get_visible (GTK_WIDGET (editor)) && event->keyval == GDK_KEY_space) {
 
132
                return FALSE;
 
133
        }
 
134
 
 
135
        /* if it's not printable we don't need it */
 
136
        if (!g_unichar_isprint (gdk_keyval_to_unicode (event->keyval))) {
 
137
                return FALSE;
 
138
        }
 
139
 
 
140
        if (!gtk_widget_get_realized (editor->details->entry)) {
 
141
                gtk_widget_realize (editor->details->entry);
 
142
        }
 
143
 
 
144
        toplevel = gtk_widget_get_toplevel (GTK_WIDGET (editor));
 
145
        if (gtk_widget_is_toplevel (toplevel)) {
 
146
                old_focus = gtk_window_get_focus (GTK_WINDOW (toplevel));
 
147
        } else {
 
148
                old_focus = NULL;
 
149
        }
 
150
 
 
151
        /* input methods will typically only process events after getting focus */
 
152
        gtk_widget_grab_focus (editor->details->entry);
 
153
 
 
154
        new_event = gdk_event_copy ((GdkEvent *) event);
 
155
        g_object_unref (((GdkEventKey *) new_event)->window);
 
156
        ((GdkEventKey *) new_event)->window = g_object_ref
 
157
                (gtk_widget_get_window (editor->details->entry));
 
158
        retval = gtk_widget_event (editor->details->entry, new_event);
 
159
        gdk_event_free (new_event);
 
160
 
 
161
        if (!retval && old_focus) {
 
162
                gtk_widget_grab_focus (old_focus);
 
163
        }
 
164
 
 
165
        return retval;
 
166
}
 
167
 
 
168
static void
 
169
row_destroy (NautilusQueryEditorRow *row)
 
170
{
 
171
        gtk_widget_destroy (row->toolbar);
 
172
        g_free (row);
 
173
}
 
174
 
 
175
static void
 
176
nautilus_query_editor_dispose (GObject *object)
 
177
{
 
178
        NautilusQueryEditor *editor;
 
179
 
 
180
        editor = NAUTILUS_QUERY_EDITOR (object);
 
181
 
 
182
        if (editor->details->typing_timeout_id > 0) {
 
183
                g_source_remove (editor->details->typing_timeout_id);
 
184
                editor->details->typing_timeout_id = 0;
 
185
        }
 
186
 
 
187
        g_clear_object (&editor->details->query);
 
188
 
 
189
        g_list_free_full (editor->details->rows, (GDestroyNotify) row_destroy);
 
190
        editor->details->rows = NULL;
 
191
 
 
192
        G_OBJECT_CLASS (nautilus_query_editor_parent_class)->dispose (object);
 
193
}
 
194
 
 
195
static void
 
196
nautilus_query_editor_grab_focus (GtkWidget *widget)
 
197
{
 
198
        NautilusQueryEditor *editor = NAUTILUS_QUERY_EDITOR (widget);
 
199
 
 
200
        if (gtk_widget_get_visible (widget) && !gtk_widget_is_focus (editor->details->entry)) {
 
201
                /* avoid selecting the entry text */
 
202
                gtk_widget_grab_focus (editor->details->entry);
 
203
                gtk_editable_set_position (GTK_EDITABLE (editor->details->entry), -1);
 
204
        }
 
205
}
 
206
 
 
207
static void
 
208
nautilus_query_editor_class_init (NautilusQueryEditorClass *class)
 
209
{
 
210
        GObjectClass *gobject_class;
 
211
        GtkWidgetClass *widget_class;
 
212
        GtkBindingSet *binding_set;
 
213
 
 
214
        gobject_class = G_OBJECT_CLASS (class);
 
215
        gobject_class->dispose = nautilus_query_editor_dispose;
 
216
 
 
217
        widget_class = GTK_WIDGET_CLASS (class);
 
218
        widget_class->grab_focus = nautilus_query_editor_grab_focus;
 
219
 
 
220
        signals[CHANGED] =
 
221
                g_signal_new ("changed",
 
222
                              G_TYPE_FROM_CLASS (class),
 
223
                              G_SIGNAL_RUN_LAST,
 
224
                              G_STRUCT_OFFSET (NautilusQueryEditorClass, changed),
 
225
                              NULL, NULL,
 
226
                              g_cclosure_marshal_generic,
 
227
                              G_TYPE_NONE, 2, NAUTILUS_TYPE_QUERY, G_TYPE_BOOLEAN);
 
228
 
 
229
        signals[CANCEL] =
 
230
                g_signal_new ("cancel",
 
231
                              G_TYPE_FROM_CLASS (class),
 
232
                              G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
 
233
                              G_STRUCT_OFFSET (NautilusQueryEditorClass, cancel),
 
234
                              NULL, NULL,
 
235
                              g_cclosure_marshal_VOID__VOID,
 
236
                              G_TYPE_NONE, 0);
 
237
 
 
238
        signals[ACTIVATED] =
 
239
                g_signal_new ("activated",
 
240
                              G_TYPE_FROM_CLASS (class),
 
241
                              G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
 
242
                              G_STRUCT_OFFSET (NautilusQueryEditorClass, activated),
 
243
                              NULL, NULL,
 
244
                              g_cclosure_marshal_VOID__VOID,
 
245
                              G_TYPE_NONE, 0);
 
246
 
 
247
        binding_set = gtk_binding_set_by_class (class);
 
248
        gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "cancel", 0);
 
249
 
 
250
        g_type_class_add_private (class, sizeof (NautilusQueryEditorDetails));
 
251
}
 
252
 
 
253
GFile *
 
254
nautilus_query_editor_get_location (NautilusQueryEditor *editor)
 
255
{
 
256
        GFile *file = NULL;
 
257
        if (editor->details->current_uri != NULL)
 
258
                file = g_file_new_for_uri (editor->details->current_uri);
 
259
        return file;
 
260
}
 
261
 
 
262
static void
 
263
entry_activate_cb (GtkWidget *entry, NautilusQueryEditor *editor)
 
264
{
 
265
        g_signal_emit (editor, signals[ACTIVATED], 0);
 
266
}
 
267
 
 
268
static gboolean
 
269
typing_timeout_cb (gpointer user_data)
 
270
{
 
271
        NautilusQueryEditor *editor;
 
272
 
 
273
        editor = NAUTILUS_QUERY_EDITOR (user_data);
 
274
        editor->details->typing_timeout_id = 0;
 
275
 
 
276
        nautilus_query_editor_changed (editor);
 
277
 
 
278
        return FALSE;
 
279
}
 
280
 
 
281
#define TYPING_TIMEOUT 250
 
282
 
 
283
static void
 
284
entry_changed_cb (GtkWidget *entry, NautilusQueryEditor *editor)
 
285
{
 
286
        if (editor->details->change_frozen) {
 
287
                return;
 
288
        }
 
289
 
 
290
        if (editor->details->typing_timeout_id > 0) {
 
291
                g_source_remove (editor->details->typing_timeout_id);
 
292
        }
 
293
 
 
294
        editor->details->typing_timeout_id =
 
295
                g_timeout_add (TYPING_TIMEOUT,
 
296
                               typing_timeout_cb,
 
297
                               editor);
 
298
}
 
299
 
 
300
/* Type */
 
301
 
 
302
static gboolean
 
303
type_separator_func (GtkTreeModel      *model,
 
304
                     GtkTreeIter       *iter,
 
305
                     gpointer           data)
 
306
{
 
307
        char *text;
 
308
        gboolean res;
 
309
        
 
310
        gtk_tree_model_get (model, iter, 0, &text, -1);
 
311
 
 
312
        res = text != NULL && strcmp (text, "---") == 0;
 
313
        
 
314
        g_free (text);
 
315
        return res;
 
316
}
 
317
 
 
318
struct {
 
319
        char *name;
 
320
        char *mimetypes[20];
 
321
} mime_type_groups[] = {
 
322
        { N_("Documents"),
 
323
          { "application/rtf",
 
324
            "application/msword",
 
325
            "application/vnd.sun.xml.writer",
 
326
            "application/vnd.sun.xml.writer.global",
 
327
            "application/vnd.sun.xml.writer.template",
 
328
            "application/vnd.oasis.opendocument.text",
 
329
            "application/vnd.oasis.opendocument.text-template",
 
330
            "application/x-abiword",
 
331
            "application/x-applix-word",
 
332
            "application/x-mswrite",
 
333
            "application/docbook+xml",
 
334
            "application/x-kword",
 
335
            "application/x-kword-crypt",
 
336
            "application/x-lyx",
 
337
            NULL
 
338
          }
 
339
        },
 
340
        { N_("Music"),
 
341
          { "application/ogg",
 
342
            "audio/x-vorbis+ogg",
 
343
            "audio/ac3",
 
344
            "audio/basic",
 
345
            "audio/midi",
 
346
            "audio/x-flac",
 
347
            "audio/mp4",
 
348
            "audio/mpeg",
 
349
            "audio/x-mpeg",
 
350
            "audio/x-ms-asx",
 
351
            "audio/x-pn-realaudio",
 
352
            NULL
 
353
          }
 
354
        },
 
355
        { N_("Video"),
 
356
          { "video/mp4",
 
357
            "video/3gpp",
 
358
            "video/mpeg",
 
359
            "video/quicktime",
 
360
            "video/vivo",
 
361
            "video/x-avi",
 
362
            "video/x-mng",
 
363
            "video/x-ms-asf",
 
364
            "video/x-ms-wmv",
 
365
            "video/x-msvideo",
 
366
            "video/x-nsv",
 
367
            "video/x-real-video",
 
368
            NULL
 
369
          }
 
370
        },
 
371
        { N_("Picture"),
 
372
          { "application/vnd.oasis.opendocument.image",
 
373
            "application/x-krita",
 
374
            "image/bmp",
 
375
            "image/cgm",
 
376
            "image/gif",
 
377
            "image/jpeg",
 
378
            "image/jpeg2000",
 
379
            "image/png",
 
380
            "image/svg+xml",
 
381
            "image/tiff",
 
382
            "image/x-compressed-xcf",
 
383
            "image/x-pcx",
 
384
            "image/x-photo-cd",
 
385
            "image/x-psd",
 
386
            "image/x-tga",
 
387
            "image/x-xcf",
 
388
            NULL
 
389
          }
 
390
        },
 
391
        { N_("Illustration"),
 
392
          { "application/illustrator",
 
393
            "application/vnd.corel-draw",
 
394
            "application/vnd.stardivision.draw",
 
395
            "application/vnd.oasis.opendocument.graphics",
 
396
            "application/x-dia-diagram",
 
397
            "application/x-karbon",
 
398
            "application/x-killustrator",
 
399
            "application/x-kivio",
 
400
            "application/x-kontour",
 
401
            "application/x-wpg",
 
402
            NULL
 
403
          }
 
404
        },
 
405
        { N_("Spreadsheet"),
 
406
          { "application/vnd.lotus-1-2-3",
 
407
            "application/vnd.ms-excel",
 
408
            "application/vnd.stardivision.calc",
 
409
            "application/vnd.sun.xml.calc",
 
410
            "application/vnd.oasis.opendocument.spreadsheet",
 
411
            "application/x-applix-spreadsheet",
 
412
            "application/x-gnumeric",
 
413
            "application/x-kspread",
 
414
            "application/x-kspread-crypt",
 
415
            "application/x-quattropro",
 
416
            "application/x-sc",
 
417
            "application/x-siag",
 
418
            NULL
 
419
          }
 
420
        },
 
421
        { N_("Presentation"),
 
422
          { "application/vnd.ms-powerpoint",
 
423
            "application/vnd.sun.xml.impress",
 
424
            "application/vnd.oasis.opendocument.presentation",
 
425
            "application/x-magicpoint",
 
426
            "application/x-kpresenter",
 
427
            NULL
 
428
          }
 
429
        },
 
430
        { N_("Pdf / Postscript"),
 
431
          { "application/pdf",
 
432
            "application/postscript",
 
433
            "application/x-dvi",
 
434
            "image/x-eps",
 
435
            NULL
 
436
          }
 
437
        },
 
438
        { N_("Text File"),
 
439
          { "text/plain",
 
440
            NULL
 
441
          }
 
442
        }
 
443
};
 
444
 
 
445
static void
 
446
type_add_custom_type (NautilusQueryEditorRow *row,
 
447
                      const char *mime_type,
 
448
                      const char *description,
 
449
                      GtkTreeIter *iter)
 
450
{
 
451
        GtkTreeModel *model;
 
452
        GtkListStore *store;
 
453
        
 
454
        model = gtk_combo_box_get_model (GTK_COMBO_BOX (row->type_widget));
 
455
        store = GTK_LIST_STORE (model);
 
456
 
 
457
        gtk_list_store_append (store, iter);
 
458
        gtk_list_store_set (store, iter,
 
459
                            0, description,
 
460
                            2, mime_type,
 
461
                            -1);
 
462
}
 
463
 
 
464
 
 
465
static void
 
466
type_combo_changed (GtkComboBox *combo_box, NautilusQueryEditorRow *row)
 
467
{
 
468
        GtkTreeIter iter;
 
469
        gboolean other;
 
470
        GtkTreeModel *model;
 
471
 
 
472
        if (!gtk_combo_box_get_active_iter  (GTK_COMBO_BOX (row->type_widget),
 
473
                                             &iter)) {
 
474
                return;
 
475
        }
 
476
 
 
477
        model = gtk_combo_box_get_model (GTK_COMBO_BOX (row->type_widget));
 
478
        gtk_tree_model_get (model, &iter, 3, &other, -1);
 
479
 
 
480
        if (other) {
 
481
                GList *mime_infos, *l;
 
482
                GtkWidget *dialog;
 
483
                GtkWidget *scrolled, *treeview;
 
484
                GtkListStore *store;
 
485
                GtkTreeViewColumn *column;
 
486
                GtkCellRenderer *renderer;
 
487
                GtkWidget *toplevel;
 
488
                GtkTreeSelection *selection;
 
489
 
 
490
                mime_infos = g_content_types_get_registered ();
 
491
 
 
492
                store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
 
493
                for (l = mime_infos; l != NULL; l = l->next) {
 
494
                        GtkTreeIter iter;
 
495
                        char *mime_type = l->data;
 
496
                        char *description;
 
497
 
 
498
                        description = g_content_type_get_description (mime_type);
 
499
                        if (description == NULL) {
 
500
                                description = g_strdup (mime_type);
 
501
                        }
 
502
                        
 
503
                        gtk_list_store_append (store, &iter);
 
504
                        gtk_list_store_set (store, &iter,
 
505
                                            0, description,
 
506
                                            1, mime_type,
 
507
                                            -1);
 
508
                        
 
509
                        g_free (mime_type);
 
510
                        g_free (description);
 
511
                }
 
512
                g_list_free (mime_infos);
 
513
                
 
514
 
 
515
                
 
516
                toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
 
517
                dialog = gtk_dialog_new_with_buttons (_("Select type"),
 
518
                                                      GTK_WINDOW (toplevel),
 
519
                                                      0,
 
520
                                                      _("_Cancel"), GTK_RESPONSE_CANCEL,
 
521
                                                      _("Select"), GTK_RESPONSE_OK,
 
522
                                                      NULL);
 
523
                gtk_window_set_default_size (GTK_WINDOW (dialog), 400, 600);
 
524
                        
 
525
                scrolled = gtk_scrolled_window_new (NULL, NULL);
 
526
                gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
 
527
                                                GTK_POLICY_AUTOMATIC,
 
528
                                                GTK_POLICY_AUTOMATIC);
 
529
                gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
 
530
                                                     GTK_SHADOW_IN);
 
531
                
 
532
                gtk_widget_show (scrolled);
 
533
                gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), scrolled, TRUE, TRUE, 6);
 
534
 
 
535
                treeview = gtk_tree_view_new ();
 
536
                gtk_tree_view_set_model (GTK_TREE_VIEW (treeview),
 
537
                                         GTK_TREE_MODEL (store));
 
538
                gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), 0,
 
539
                                                      GTK_SORT_ASCENDING);
 
540
                
 
541
                selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
 
542
                gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
 
543
 
 
544
 
 
545
                renderer = gtk_cell_renderer_text_new ();
 
546
                column = gtk_tree_view_column_new_with_attributes ("Name",
 
547
                                                                   renderer,
 
548
                                                                   "text",
 
549
                                                                   0,
 
550
                                                                   NULL);
 
551
                gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
 
552
                gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
 
553
                
 
554
                gtk_widget_show (treeview);
 
555
                gtk_container_add (GTK_CONTAINER (scrolled), treeview);
 
556
 
 
557
                if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
 
558
                        char *mimetype, *description;
 
559
 
 
560
                        gtk_tree_selection_get_selected (selection, NULL, &iter);
 
561
                        gtk_tree_model_get (GTK_TREE_MODEL (store), &iter,
 
562
                                            0, &description,
 
563
                                            1, &mimetype,
 
564
                                            -1);
 
565
 
 
566
                        type_add_custom_type (row, mimetype, description, &iter);
 
567
                        gtk_combo_box_set_active_iter  (GTK_COMBO_BOX (row->type_widget),
 
568
                                                        &iter);
 
569
                } else {
 
570
                        gtk_combo_box_set_active (GTK_COMBO_BOX (row->type_widget), 0);
 
571
                }
 
572
 
 
573
                gtk_widget_destroy (dialog);
 
574
        }
 
575
        
 
576
        nautilus_query_editor_changed (row->editor);
 
577
}
 
578
 
 
579
static GtkWidget *
 
580
type_row_create_widgets (NautilusQueryEditorRow *row)
 
581
{
 
582
        GtkWidget *combo;
 
583
        GtkCellRenderer *cell;
 
584
        GtkListStore *store;
 
585
        GtkTreeIter iter;
 
586
        int i;
 
587
 
 
588
        store = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_BOOLEAN);
 
589
        combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
 
590
        g_object_unref (store);
 
591
        
 
592
        cell = gtk_cell_renderer_text_new ();
 
593
        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
 
594
        gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cell,
 
595
                                        "text", 0,
 
596
                                        NULL);
 
597
        gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo),
 
598
                                              type_separator_func,
 
599
                                              NULL, NULL);
 
600
 
 
601
        gtk_list_store_append (store, &iter);
 
602
        gtk_list_store_set (store, &iter, 0, _("Any"), -1);
 
603
        gtk_list_store_append (store, &iter);
 
604
        gtk_list_store_set (store, &iter, 0, "---",  -1);
 
605
 
 
606
        for (i = 0; i < G_N_ELEMENTS (mime_type_groups); i++) {
 
607
                gtk_list_store_append (store, &iter);
 
608
                gtk_list_store_set (store, &iter,
 
609
                                    0, gettext (mime_type_groups[i].name),
 
610
                                    1, mime_type_groups[i].mimetypes,
 
611
                                    -1);
 
612
        }
 
613
 
 
614
        gtk_list_store_append (store, &iter);
 
615
        gtk_list_store_set (store, &iter, 0, "---",  -1);
 
616
        gtk_list_store_append (store, &iter);
 
617
        gtk_list_store_set (store, &iter, 0, _("Other Type…"), 3, TRUE, -1);
 
618
 
 
619
        gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
 
620
        
 
621
        g_signal_connect (combo, "changed",
 
622
                          G_CALLBACK (type_combo_changed),
 
623
                          row);
 
624
 
 
625
        gtk_widget_show (combo);
 
626
        
 
627
        gtk_box_pack_start (GTK_BOX (row->hbox), combo, FALSE, FALSE, 0);
 
628
        
 
629
        return combo;
 
630
}
 
631
 
 
632
static void
 
633
type_row_add_to_query (NautilusQueryEditorRow *row,
 
634
                       NautilusQuery          *query)
 
635
{
 
636
        GtkTreeIter iter;
 
637
        char **mimetypes;
 
638
        char *mimetype;
 
639
        GtkTreeModel *model;
 
640
 
 
641
        if (!gtk_combo_box_get_active_iter  (GTK_COMBO_BOX (row->type_widget),
 
642
                                             &iter)) {
 
643
                return;
 
644
        }
 
645
 
 
646
        model = gtk_combo_box_get_model (GTK_COMBO_BOX (row->type_widget));
 
647
        gtk_tree_model_get (model, &iter, 1, &mimetypes, 2, &mimetype, -1);
 
648
 
 
649
        if (mimetypes != NULL) {
 
650
                while (*mimetypes != NULL) {
 
651
                        nautilus_query_add_mime_type (query, *mimetypes);
 
652
                        mimetypes++;
 
653
                }
 
654
        }
 
655
        if (mimetype) {
 
656
                nautilus_query_add_mime_type (query, mimetype);
 
657
                g_free (mimetype);
 
658
        }
 
659
}
 
660
 
 
661
static gboolean
 
662
all_group_types_in_list (char **group_types, GList *mime_types)
 
663
{
 
664
        GList *l;
 
665
        char **group_type;
 
666
        char *mime_type;
 
667
        gboolean found;
 
668
 
 
669
        group_type = group_types;
 
670
        while (*group_type != NULL) {
 
671
                found = FALSE;
 
672
 
 
673
                for (l = mime_types; l != NULL; l = l->next) {
 
674
                        mime_type = l->data;
 
675
 
 
676
                        if (strcmp (mime_type, *group_type) == 0) {
 
677
                                found = TRUE;
 
678
                                break;
 
679
                        }
 
680
                }
 
681
                
 
682
                if (!found) {
 
683
                        return FALSE;
 
684
                }
 
685
                group_type++;
 
686
        }
 
687
        return TRUE;
 
688
}
 
689
 
 
690
static GList *
 
691
remove_group_types_from_list (char **group_types, GList *mime_types)
 
692
{
 
693
        GList *l, *next;
 
694
        char **group_type;
 
695
        char *mime_type;
 
696
 
 
697
        group_type = group_types;
 
698
        while (*group_type != NULL) {
 
699
                for (l = mime_types; l != NULL; l = next) {
 
700
                        mime_type = l->data;
 
701
                        next = l->next;
 
702
 
 
703
                        if (strcmp (mime_type, *group_type) == 0) {
 
704
                                mime_types = g_list_remove_link (mime_types, l);
 
705
                                g_free (mime_type);
 
706
                                break;
 
707
                        }
 
708
                }
 
709
                
 
710
                group_type++;
 
711
        }
 
712
        return mime_types;
 
713
}
 
714
 
 
715
 
 
716
static void
 
717
type_add_rows_from_query (NautilusQueryEditor    *editor,
 
718
                          NautilusQuery          *query)
 
719
{
 
720
        GList *mime_types;
 
721
        char *mime_type;
 
722
        const char *desc;
 
723
        NautilusQueryEditorRow *row;
 
724
        GtkTreeIter iter;
 
725
        int i;
 
726
        GtkTreeModel *model;
 
727
        GList *l;
 
728
 
 
729
        mime_types = nautilus_query_get_mime_types (query);
 
730
 
 
731
        if (mime_types == NULL) {
 
732
                return;
 
733
        }
 
734
        
 
735
        for (i = 0; i < G_N_ELEMENTS (mime_type_groups); i++) {
 
736
                if (all_group_types_in_list (mime_type_groups[i].mimetypes,
 
737
                                             mime_types)) {
 
738
                        mime_types = remove_group_types_from_list (mime_type_groups[i].mimetypes,
 
739
                                                                   mime_types);
 
740
 
 
741
                        row = nautilus_query_editor_add_row (editor,
 
742
                                                             NAUTILUS_QUERY_EDITOR_ROW_TYPE);
 
743
 
 
744
                        model = gtk_combo_box_get_model (GTK_COMBO_BOX (row->type_widget));
 
745
 
 
746
                        gtk_tree_model_iter_nth_child (model, &iter, NULL, i + 2);
 
747
                        gtk_combo_box_set_active_iter  (GTK_COMBO_BOX (row->type_widget),
 
748
                                                        &iter);
 
749
                }
 
750
        }
 
751
 
 
752
        for (l = mime_types; l != NULL; l = l->next) {
 
753
                mime_type = l->data;
 
754
 
 
755
                desc = g_content_type_get_description (mime_type);
 
756
                if (desc == NULL) {
 
757
                        desc = mime_type;
 
758
                }
 
759
 
 
760
                row = nautilus_query_editor_add_row (editor,
 
761
                                                     NAUTILUS_QUERY_EDITOR_ROW_TYPE);
 
762
                
 
763
                type_add_custom_type (row, mime_type, desc, &iter);
 
764
                gtk_combo_box_set_active_iter  (GTK_COMBO_BOX (row->type_widget),
 
765
                                                &iter);
 
766
        }
 
767
 
 
768
        g_list_free_full (mime_types, g_free);
 
769
}
 
770
 
 
771
/* End of row types */
 
772
 
 
773
static NautilusQueryEditorRowType
 
774
get_next_free_type (NautilusQueryEditor *editor)
 
775
{
 
776
        NautilusQueryEditorRow *row;
 
777
        NautilusQueryEditorRowType type;
 
778
        gboolean found;
 
779
        GList *l;
 
780
 
 
781
        
 
782
        for (type = 0; type < NAUTILUS_QUERY_EDITOR_ROW_LAST; type++) {
 
783
                found = FALSE;
 
784
                for (l = editor->details->rows; l != NULL; l = l->next) {
 
785
                        row = l->data;
 
786
                        if (row->type == type) {
 
787
                                found = TRUE;
 
788
                                break;
 
789
                        }
 
790
                }
 
791
                if (!found) {
 
792
                        return type;
 
793
                }
 
794
        }
 
795
        return NAUTILUS_QUERY_EDITOR_ROW_TYPE;
 
796
}
 
797
 
 
798
static void
 
799
remove_row_cb (GtkButton *clicked_button, NautilusQueryEditorRow *row)
 
800
{
 
801
        NautilusQueryEditor *editor;
 
802
 
 
803
        editor = row->editor;
 
804
        editor->details->rows = g_list_remove (editor->details->rows, row);
 
805
        row_destroy (row);
 
806
 
 
807
        nautilus_query_editor_changed (editor);
 
808
}
 
809
 
 
810
static void
 
811
create_type_widgets (NautilusQueryEditorRow *row)
 
812
{
 
813
        row->type_widget = row_type[row->type].create_widgets (row);
 
814
}
 
815
 
 
816
static void
 
817
row_type_combo_changed_cb (GtkComboBox *combo_box, NautilusQueryEditorRow *row)
 
818
{
 
819
        NautilusQueryEditorRowType type;
 
820
 
 
821
        type = gtk_combo_box_get_active (combo_box);
 
822
 
 
823
        if (type == row->type) {
 
824
                return;
 
825
        }
 
826
 
 
827
        if (row->type_widget != NULL) {
 
828
                gtk_widget_destroy (row->type_widget);
 
829
                row->type_widget = NULL;
 
830
        }
 
831
 
 
832
        row->type = type;
 
833
        
 
834
        create_type_widgets (row);
 
835
 
 
836
        nautilus_query_editor_changed (row->editor);
 
837
}
 
838
 
 
839
static NautilusQueryEditorRow *
 
840
nautilus_query_editor_add_row (NautilusQueryEditor *editor,
 
841
                               NautilusQueryEditorRowType type)
 
842
{
 
843
        GtkWidget *hbox, *button, *image, *combo;
 
844
        GtkToolItem *item;
 
845
        NautilusQueryEditorRow *row;
 
846
        int i;
 
847
 
 
848
        row = g_new0 (NautilusQueryEditorRow, 1);
 
849
        row->editor = editor;
 
850
        row->type = type;
 
851
 
 
852
        /* create the toolbar and the box container for its contents */
 
853
        row->toolbar = gtk_toolbar_new ();
 
854
        gtk_box_pack_start (GTK_BOX (editor), row->toolbar, TRUE, TRUE, 0);
 
855
 
 
856
        item = gtk_tool_item_new ();
 
857
        gtk_tool_item_set_expand (item, TRUE);
 
858
        gtk_toolbar_insert (GTK_TOOLBAR (row->toolbar), item, -1);
 
859
 
 
860
        hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
 
861
        gtk_container_add (GTK_CONTAINER (item), hbox);
 
862
        row->hbox = hbox;
 
863
 
 
864
        /* create the criterion selector combobox */
 
865
        combo = gtk_combo_box_text_new ();
 
866
        row->combo = combo;
 
867
        for (i = 0; i < NAUTILUS_QUERY_EDITOR_ROW_LAST; i++) {
 
868
                gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), gettext (row_type[i].name));
 
869
        }
 
870
        gtk_box_pack_start (GTK_BOX (hbox), combo, FALSE, FALSE, 0);
 
871
 
 
872
        gtk_combo_box_set_active (GTK_COMBO_BOX (combo), row->type);
 
873
 
 
874
        editor->details->rows = g_list_append (editor->details->rows, row);
 
875
 
 
876
        g_signal_connect (combo, "changed",
 
877
                          G_CALLBACK (row_type_combo_changed_cb), row);
 
878
        
 
879
        create_type_widgets (row);
 
880
 
 
881
        /* create the remove row button */
 
882
        button = gtk_button_new ();
 
883
        gtk_style_context_add_class (gtk_widget_get_style_context (button),
 
884
                                     GTK_STYLE_CLASS_RAISED);
 
885
        gtk_widget_set_tooltip_text (button,
 
886
                                     _("Remove this criterion from the search"));
 
887
        gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
 
888
 
 
889
        image = gtk_image_new_from_icon_name ("window-close-symbolic",
 
890
                                              GTK_ICON_SIZE_MENU);
 
891
        gtk_container_add (GTK_CONTAINER (button), image);
 
892
 
 
893
        g_signal_connect (button, "clicked",
 
894
                          G_CALLBACK (remove_row_cb), row);
 
895
 
 
896
        /* show everything */
 
897
        gtk_widget_show_all (row->toolbar);
 
898
 
 
899
        return row;
 
900
}
 
901
 
 
902
static void
 
903
add_new_row_cb (GtkButton *clicked_button, NautilusQueryEditor *editor)
 
904
{
 
905
        nautilus_query_editor_add_row (editor, get_next_free_type (editor));
 
906
        nautilus_query_editor_changed (editor);
 
907
}
 
908
 
 
909
static void
 
910
nautilus_query_editor_init (NautilusQueryEditor *editor)
 
911
{
 
912
        editor->details = G_TYPE_INSTANCE_GET_PRIVATE (editor, NAUTILUS_TYPE_QUERY_EDITOR,
 
913
                                                       NautilusQueryEditorDetails);
 
914
 
 
915
        gtk_orientable_set_orientation (GTK_ORIENTABLE (editor), GTK_ORIENTATION_VERTICAL);
 
916
}
 
917
 
 
918
static void
 
919
on_location_button_toggled (GtkToggleButton     *button,
 
920
                       NautilusQueryEditor *editor)
 
921
{
 
922
        nautilus_query_editor_changed (editor);
 
923
}
 
924
 
 
925
static gboolean
 
926
entry_key_press_event_cb (GtkWidget           *widget,
 
927
                          GdkEventKey         *event,
 
928
                          NautilusQueryEditor *editor)
 
929
{
 
930
        if (event->keyval == GDK_KEY_Down) {
 
931
                nautilus_window_grab_focus (NAUTILUS_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (widget))));
 
932
        }
 
933
        return FALSE;
 
934
}
 
935
 
 
936
static void
 
937
setup_widgets (NautilusQueryEditor *editor)
 
938
{
 
939
        GtkToolItem *item;
 
940
        GtkWidget *toolbar, *button_box, *hbox;
 
941
        GtkWidget *button, *image;
 
942
 
 
943
        /* create the toolbar and the box container for its contents */
 
944
        toolbar = gtk_toolbar_new ();
 
945
        gtk_style_context_add_class (gtk_widget_get_style_context (toolbar),
 
946
                                     GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
 
947
        gtk_box_pack_start (GTK_BOX (editor), toolbar, TRUE, TRUE, 0);
 
948
 
 
949
        item = gtk_tool_item_new ();
 
950
        gtk_tool_item_set_expand (item, TRUE);
 
951
        gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
 
952
 
 
953
        hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
 
954
        gtk_container_add (GTK_CONTAINER (item), hbox);
 
955
 
 
956
        /* create the search entry */
 
957
        editor->details->entry = gtk_search_entry_new ();
 
958
        gtk_box_pack_start (GTK_BOX (hbox), editor->details->entry, TRUE, TRUE, 0);
 
959
 
 
960
        g_signal_connect (editor->details->entry, "key-press-event",
 
961
                          G_CALLBACK (entry_key_press_event_cb), editor);
 
962
        g_signal_connect (editor->details->entry, "activate",
 
963
                          G_CALLBACK (entry_activate_cb), editor);
 
964
        g_signal_connect (editor->details->entry, "changed",
 
965
                          G_CALLBACK (entry_changed_cb), editor);
 
966
 
 
967
        /* create the Current/All Files selector */
 
968
        editor->details->search_current_button = gtk_radio_button_new_with_label (NULL, _("Current"));
 
969
        gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (editor->details->search_current_button), FALSE);
 
970
        editor->details->search_all_button = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (editor->details->search_current_button),
 
971
                                                                                          _("All Files"));
 
972
        gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (editor->details->search_all_button), FALSE);
 
973
 
 
974
        /* connect to the signal only on one of the two, since they're mutually exclusive */
 
975
        g_signal_connect (editor->details->search_current_button, "toggled",
 
976
                          G_CALLBACK (on_location_button_toggled), editor);
 
977
 
 
978
        button_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
 
979
        gtk_box_pack_start (GTK_BOX (hbox), button_box, FALSE, FALSE, 0);
 
980
        gtk_style_context_add_class (gtk_widget_get_style_context (button_box),
 
981
                                     GTK_STYLE_CLASS_LINKED);
 
982
        gtk_style_context_add_class (gtk_widget_get_style_context (button_box),
 
983
                                     GTK_STYLE_CLASS_RAISED);
 
984
 
 
985
        gtk_box_pack_start (GTK_BOX (button_box), editor->details->search_current_button, FALSE, FALSE, 0);
 
986
        gtk_box_pack_start (GTK_BOX (button_box), editor->details->search_all_button, FALSE, FALSE, 0);
 
987
 
 
988
        /* finally, create the add new row button */
 
989
        button = gtk_button_new ();
 
990
        gtk_style_context_add_class (gtk_widget_get_style_context (button),
 
991
                                     GTK_STYLE_CLASS_RAISED);
 
992
        gtk_widget_set_tooltip_text (button,
 
993
                                     _("Add a new criterion to this search"));
 
994
        gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
 
995
 
 
996
        image = gtk_image_new_from_icon_name ("list-add-symbolic",
 
997
                                              GTK_ICON_SIZE_MENU);
 
998
        gtk_container_add (GTK_CONTAINER (button), image);
 
999
 
 
1000
        g_signal_connect (button, "clicked",
 
1001
                          G_CALLBACK (add_new_row_cb), editor);
 
1002
 
 
1003
        /* show everything */
 
1004
        gtk_widget_show_all (toolbar);
 
1005
}
 
1006
 
 
1007
static void
 
1008
nautilus_query_editor_changed_force (NautilusQueryEditor *editor, gboolean force_reload)
 
1009
{
 
1010
        NautilusQuery *query;
 
1011
 
 
1012
        if (editor->details->change_frozen) {
 
1013
                return;
 
1014
        }
 
1015
 
 
1016
        query = nautilus_query_editor_get_query (editor);
 
1017
        g_signal_emit (editor, signals[CHANGED], 0,
 
1018
                       query, force_reload);
 
1019
        g_object_unref (query);
 
1020
}
 
1021
 
 
1022
static void
 
1023
nautilus_query_editor_changed (NautilusQueryEditor *editor)
 
1024
{
 
1025
        nautilus_query_editor_changed_force (editor, TRUE);
 
1026
}
 
1027
 
 
1028
static void
 
1029
add_location_to_query (NautilusQueryEditor *editor,
 
1030
                       NautilusQuery       *query)
 
1031
{
 
1032
        char *uri;
 
1033
 
 
1034
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->details->search_all_button))) {
 
1035
                uri = nautilus_get_home_directory_uri ();
 
1036
        } else {
 
1037
                uri = g_strdup (editor->details->current_uri);
 
1038
        }
 
1039
 
 
1040
        nautilus_query_set_location (query, uri);
 
1041
        g_free (uri);
 
1042
}
 
1043
 
 
1044
NautilusQuery *
 
1045
nautilus_query_editor_get_query (NautilusQueryEditor *editor)
 
1046
{
 
1047
        const char *query_text;
 
1048
        NautilusQuery *query;
 
1049
        GList *l;
 
1050
        NautilusQueryEditorRow *row;
 
1051
 
 
1052
        if (editor == NULL || editor->details == NULL || editor->details->entry == NULL) {
 
1053
                return NULL;
 
1054
        }
 
1055
 
 
1056
        query_text = gtk_entry_get_text (GTK_ENTRY (editor->details->entry));
 
1057
 
 
1058
        query = nautilus_query_new ();
 
1059
        nautilus_query_set_text (query, query_text);
 
1060
 
 
1061
        add_location_to_query (editor, query);
 
1062
 
 
1063
        for (l = editor->details->rows; l != NULL; l = l->next) {
 
1064
                row = l->data;
 
1065
                
 
1066
                row_type[row->type].add_to_query (row, query);
 
1067
        }
 
1068
        
 
1069
        return query;
 
1070
}
 
1071
 
 
1072
GtkWidget *
 
1073
nautilus_query_editor_new (void)
 
1074
{
 
1075
        GtkWidget *editor;
 
1076
 
 
1077
        editor = g_object_new (NAUTILUS_TYPE_QUERY_EDITOR, NULL);
 
1078
        setup_widgets (NAUTILUS_QUERY_EDITOR (editor));
 
1079
 
 
1080
        return editor;
 
1081
}
 
1082
 
 
1083
static void
 
1084
update_location (NautilusQueryEditor *editor)
 
1085
{
 
1086
        NautilusFile *file;
 
1087
        GtkWidget *label;
 
1088
 
 
1089
        file = nautilus_file_get_by_uri (editor->details->current_uri);
 
1090
 
 
1091
        if (file != NULL) {
 
1092
                char *name;
 
1093
                if (nautilus_file_is_home (file)) {
 
1094
                        name = g_strdup (_("Home"));
 
1095
                } else {
 
1096
                        name = nautilus_file_get_display_name (file);
 
1097
                }
 
1098
 
 
1099
                gtk_button_set_label (GTK_BUTTON (editor->details->search_current_button), name);
 
1100
                g_free (name);
 
1101
 
 
1102
                label = gtk_bin_get_child (GTK_BIN (editor->details->search_current_button));
 
1103
                gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_MIDDLE);
 
1104
                g_object_set (label, "max-width-chars", 30, NULL);
 
1105
 
 
1106
                nautilus_file_unref (file);
 
1107
        }
 
1108
}
 
1109
 
 
1110
void
 
1111
nautilus_query_editor_set_location (NautilusQueryEditor *editor,
 
1112
                                    GFile               *location)
 
1113
{
 
1114
        g_free (editor->details->current_uri);
 
1115
        editor->details->current_uri = g_file_get_uri (location);
 
1116
        update_location (editor);
 
1117
}
 
1118
 
 
1119
static void
 
1120
update_rows (NautilusQueryEditor *editor,
 
1121
             NautilusQuery       *query)
 
1122
{
 
1123
        NautilusQueryEditorRowType type;
 
1124
 
 
1125
        /* if we were just created, set the rows from query,
 
1126
         * otherwise, re-use the query setting we have already.
 
1127
         */
 
1128
        if (query != NULL && editor->details->query == NULL) {
 
1129
                for (type = 0; type < NAUTILUS_QUERY_EDITOR_ROW_LAST; type++) {
 
1130
                        row_type[type].add_rows_from_query (editor, query);
 
1131
                }
 
1132
        } else if (query == NULL && editor->details->query != NULL) {
 
1133
                g_list_free_full (editor->details->rows, (GDestroyNotify) row_destroy);
 
1134
                editor->details->rows = NULL;
 
1135
        }
 
1136
}
 
1137
 
 
1138
void
 
1139
nautilus_query_editor_set_query (NautilusQueryEditor    *editor,
 
1140
                                 NautilusQuery          *query)
 
1141
{
 
1142
        char *text = NULL;
 
1143
        char *current_text = NULL;
 
1144
 
 
1145
        if (query != NULL) {
 
1146
                text = nautilus_query_get_text (query);
 
1147
        }
 
1148
 
 
1149
        if (!text) {
 
1150
                text = g_strdup ("");
 
1151
        }
 
1152
 
 
1153
        editor->details->change_frozen = TRUE;
 
1154
 
 
1155
        current_text = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (editor->details->entry))));
 
1156
        if (!g_str_equal (current_text, text)) {
 
1157
                gtk_entry_set_text (GTK_ENTRY (editor->details->entry), text);
 
1158
        }
 
1159
        g_free (current_text);
 
1160
 
 
1161
        g_free (editor->details->current_uri);
 
1162
        editor->details->current_uri = NULL;
 
1163
 
 
1164
        update_rows (editor, query);
 
1165
        g_clear_object (&editor->details->query);
 
1166
 
 
1167
        if (query != NULL) {
 
1168
                editor->details->query = g_object_ref (query);
 
1169
                editor->details->current_uri = nautilus_query_get_location (query);
 
1170
                update_location (editor);
 
1171
        }
 
1172
 
 
1173
        editor->details->change_frozen = FALSE;
 
1174
 
 
1175
        g_free (text);
 
1176
}