From f34720d57fd8cf1805630f9b9c39451bdd785bed Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 8 May 2007 00:11:45 +0100 Subject: Remember last search query Save the GtkQuery object when switching to browse mode, and free it only when destroying the GtkFileChooserDefault widget or when the search query changes. Signed-off-by: Emmanuele Bassi --- gtk/gtkfilechooserdefault.c | 58 +++++++++++++++++++++++++++++++++--------- 1 files changed, 45 insertions(+), 13 deletions(-) diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 885afcd..364589d 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -456,7 +456,8 @@ static void location_button_toggled_cb (GtkToggleButton *toggle, GtkFileChooserDefault *impl); static void location_switch_to_path_bar (GtkFileChooserDefault *impl); -static void search_stop_searching (GtkFileChooserDefault *impl); +static void search_stop_searching (GtkFileChooserDefault *impl, + gboolean destroy_query); static void search_clear_model (GtkFileChooserDefault *impl, gboolean remove_from_treeview); static gboolean search_should_respond (GtkFileChooserDefault *impl); @@ -5479,8 +5480,7 @@ gtk_file_chooser_default_dispose (GObject *object) impl->shortcuts_activate_iter_handle = NULL; } - if (impl->operation_mode == OPERATION_MODE_SEARCH) - search_stop_searching (impl); + search_stop_searching (impl, TRUE); remove_settings_signal (impl, gtk_widget_get_screen (GTK_WIDGET (impl))); @@ -8522,7 +8522,7 @@ search_engine_error_cb (GtkSearchEngine *engine, impl = GTK_FILE_CHOOSER_DEFAULT (data); - search_stop_searching (impl); + search_stop_searching (impl, TRUE); error_message (impl, _("Could not send the search request"), message); set_busy_cursor (impl, FALSE); @@ -8577,14 +8577,15 @@ search_clear_model (GtkFileChooserDefault *impl, /* Stops any ongoing searches; does not touch the search_model */ static void -search_stop_searching (GtkFileChooserDefault *impl) +search_stop_searching (GtkFileChooserDefault *impl, + gboolean remove_query) { - if (impl->search_query) + if (impl->search_query && remove_query) { g_object_unref (impl->search_query); impl->search_query = NULL; } - + if (impl->search_engine) { g_object_unref (impl->search_engine); @@ -8599,7 +8600,7 @@ search_switch_to_browse_mode (GtkFileChooserDefault *impl) if (impl->operation_mode == OPERATION_MODE_BROWSE) return; - search_stop_searching (impl); + search_stop_searching (impl, FALSE); search_clear_model (impl, TRUE); gtk_widget_destroy (impl->search_hbox); @@ -8720,7 +8721,7 @@ static void search_start_query (GtkFileChooserDefault *impl, const gchar *query_text) { - search_stop_searching (impl); + search_stop_searching (impl, FALSE); search_clear_model (impl, TRUE); search_setup_model (impl); set_busy_cursor (impl, TRUE); @@ -8735,8 +8736,12 @@ search_start_query (GtkFileChooserDefault *impl, return; } - impl->search_query = _gtk_query_new (); - _gtk_query_set_text (impl->search_query, query_text); + if (!impl->search_query) + { + impl->search_query = _gtk_query_new (); + _gtk_query_set_text (impl->search_query, query_text); + } + _gtk_search_engine_set_query (impl->search_engine, impl->search_query); g_signal_connect (impl->search_engine, "hits-added", @@ -8749,7 +8754,9 @@ search_start_query (GtkFileChooserDefault *impl, _gtk_search_engine_start (impl->search_engine); } -/* Callback used when the user presses Enter while typing on the search entry; starts the query */ +/* Callback used when the user presses Enter while typing on the search + * entry; starts the query + */ static void search_entry_activate_cb (GtkEntry *entry, gpointer data) @@ -8763,6 +8770,13 @@ search_entry_activate_cb (GtkEntry *entry, if (strlen (text) == 0) return; + /* reset any existing query object */ + if (impl->search_query) + { + g_object_unref (impl->search_query); + impl->search_query = NULL; + } + search_start_query (impl, text); } @@ -8791,11 +8805,29 @@ search_setup_widgets (GtkFileChooserDefault *impl) impl); gtk_box_pack_start (GTK_BOX (impl->search_hbox), impl->search_entry, TRUE, TRUE, 0); + /* if there already is a query, restart it */ + if (impl->search_query) + { + gchar *query = _gtk_query_get_text (impl->search_query); + + if (query) + { + gtk_entry_set_text (GTK_ENTRY (impl->search_entry), query); + search_start_query (impl, query); + + g_free (query); + } + else + { + g_object_unref (impl->search_query); + impl->search_query = NULL; + } + } + gtk_widget_hide (impl->browse_path_bar); gtk_widget_hide (impl->browse_new_folder_button); /* Box for search widgets */ - gtk_box_pack_start (GTK_BOX (impl->browse_path_bar_hbox), impl->search_hbox, TRUE, TRUE, 0); gtk_widget_show_all (impl->search_hbox); -- 1.4.4.2