From 1a38c4d066951c9b339e1d26423858cd03181156 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 18 Jan 2015 18:59:43 -0500 Subject: file chooser: Make search work again The last round of filechooser redesign work had left search somewhat dysfunctional. This commit fixes things up enough that search is once again a working feature of the file chooser. --- gtk/gtkfilechooserwidget.c | 70 +++++++++------------ gtk/ui/gtkfilechooserwidget.ui | 127 ++++++++++++++++++++++++++++++++------- gtk/ui/gtkfilechooserwidget.ui.h | 5 +- 3 files changed, 136 insertions(+), 66 deletions(-) diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c index 40c72806b1..44ff413915 100644 --- a/gtk/gtkfilechooserwidget.c +++ b/gtk/gtkfilechooserwidget.c @@ -229,7 +229,6 @@ struct _GtkFileChooserWidgetPrivate { StartupMode startup_mode; /* OPERATION_MODE_SEARCH */ - GtkWidget *search_bar; GtkWidget *search_entry; GtkSearchEngine *search_engine; GtkQuery *search_query; @@ -1972,7 +1971,14 @@ location_entry_create (GtkFileChooserWidget *impl) priv->location_entry = _gtk_file_chooser_entry_new (TRUE); if (priv->action == GTK_FILE_CHOOSER_ACTION_OPEN || priv->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) - gtk_entry_set_placeholder_text (GTK_ENTRY (priv->location_entry), _("Location")); + { +#if 0 + gtk_entry_set_icon_from_icon_name (GTK_ENTRY (priv->location_entry), GTK_ENTRY_ICON_PRIMARY, "folder-symbolic"); + gtk_entry_set_icon_activatable (GTK_ENTRY (priv->location_entry), GTK_ENTRY_ICON_PRIMARY, FALSE); +#endif + gtk_entry_set_placeholder_text (GTK_ENTRY (priv->location_entry), _("Location")); + } + g_signal_connect (priv->location_entry, "changed", G_CALLBACK (location_entry_changed_cb), impl); } @@ -2457,8 +2463,12 @@ operation_mode_stop (GtkFileChooserWidget *impl, OperationMode mode) static void operation_mode_set_enter_location (GtkFileChooserWidget *impl) { + GtkFileChooserWidgetPrivate *priv = impl->priv; + location_mode_set (impl, LOCATION_MODE_FILENAME_ENTRY); location_bar_update (impl); + gtk_stack_set_visible_child_name (GTK_STACK (priv->browse_header_stack), "pathbar"); + gtk_widget_set_sensitive (priv->filter_combo, TRUE); } static void @@ -2467,7 +2477,8 @@ operation_mode_set_browse (GtkFileChooserWidget *impl) GtkFileChooserWidgetPrivate *priv = impl->priv; location_bar_update (impl); - gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (priv->search_bar), FALSE); + gtk_stack_set_visible_child_name (GTK_STACK (priv->browse_header_stack), "pathbar"); + gtk_widget_set_sensitive (priv->filter_combo, TRUE); } static void @@ -2477,8 +2488,11 @@ operation_mode_set_search (GtkFileChooserWidget *impl) g_assert (priv->search_model == NULL); + location_bar_update (impl); search_setup_widgets (impl); - gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (priv->search_bar), TRUE); + gtk_stack_set_visible_child_name (GTK_STACK (priv->browse_header_stack), "search"); + gtk_widget_set_sensitive (priv->filter_combo, FALSE); + gtk_entry_grab_focus_without_selecting (GTK_ENTRY (priv->search_entry)); } static void @@ -2492,6 +2506,8 @@ operation_mode_set_recent (GtkFileChooserWidget *impl) file = g_file_new_for_uri ("recent:///"); gtk_places_sidebar_set_location (GTK_PLACES_SIDEBAR (priv->places_sidebar), file); g_object_unref (file); + gtk_stack_set_visible_child_name (GTK_STACK (priv->browse_header_stack), "pathbar"); + gtk_widget_set_sensitive (priv->filter_combo, TRUE); } static void @@ -6248,39 +6264,16 @@ search_entry_activate_cb (GtkEntry *entry, search_start_query (impl, text); } -static gboolean -focus_entry_idle_cb (GtkFileChooserWidget *impl) +static void +search_button_clicked_cb (GtkFileChooserWidget *impl) { - GtkFileChooserWidgetPrivate *priv = impl->priv; - - gdk_threads_enter (); - - g_source_destroy (priv->focus_entry_idle); - priv->focus_entry_idle = NULL; - - if (priv->search_entry) - gtk_widget_grab_focus (priv->search_entry); - - gdk_threads_leave (); - - return FALSE; + operation_mode_set (impl, OPERATION_MODE_SEARCH); } static void -focus_search_entry_in_idle (GtkFileChooserWidget *impl) +location_button_clicked_cb (GtkFileChooserWidget *impl) { - GtkFileChooserWidgetPrivate *priv = impl->priv; - - /* bgo#634558 - When the user clicks on the Search entry in the shortcuts - * pane, we get a selection-changed signal and we set up the search widgets. - * However, gtk_tree_view_button_press() focuses the treeview *after* making - * the change to the selection. So, we need to re-focus the search entry - * after the treeview has finished doing its work; we'll do that in an idle - * handler. - */ - - if (!priv->focus_entry_idle) - priv->focus_entry_idle = add_idle_while_impl_is_alive (impl, G_CALLBACK (focus_entry_idle_cb)); + operation_mode_set (impl, OPERATION_MODE_BROWSE); } /* Hides the path bar and creates the search entry */ @@ -6308,8 +6301,6 @@ search_setup_widgets (GtkFileChooserWidget *impl) } } - focus_search_entry_in_idle (impl); - /* FMQ: hide the filter combo? */ } @@ -6977,15 +6968,7 @@ desktop_folder_handler (GtkFileChooserWidget *impl) static void search_shortcut_handler (GtkFileChooserWidget *impl) { - GtkFileChooserWidgetPrivate *priv = impl->priv; - operation_mode_set (impl, OPERATION_MODE_SEARCH); - - /* we want the entry widget to grab the focus the first - * time, not the browse_files_tree_view widget. - */ - if (priv->search_entry) - gtk_widget_grab_focus (priv->search_entry); } /* Handler for the "recent-shortcut" keybinding signal */ @@ -7426,7 +7409,6 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class) gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, extra_align); gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, extra_and_filters); gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, location_entry_box); - gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, search_bar); gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, search_entry); gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, list_name_column); gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, list_pixbuf_renderer); @@ -7454,6 +7436,8 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class) gtk_widget_class_bind_template_callback (widget_class, places_sidebar_show_error_message_cb); gtk_widget_class_bind_template_callback (widget_class, places_sidebar_show_enter_location_cb); gtk_widget_class_bind_template_callback (widget_class, search_entry_activate_cb); + gtk_widget_class_bind_template_callback (widget_class, search_button_clicked_cb); + gtk_widget_class_bind_template_callback (widget_class, location_button_clicked_cb); } static void diff --git a/gtk/ui/gtkfilechooserwidget.ui b/gtk/ui/gtkfilechooserwidget.ui index 61b7635a2b..a783a5c0d5 100644 --- a/gtk/ui/gtkfilechooserwidget.ui +++ b/gtk/ui/gtkfilechooserwidget.ui @@ -63,7 +63,7 @@ True False - 12 + 6 6 @@ -79,11 +79,46 @@ - Create Fo_lder + Create Folder True True True + + + + True + list-add-symbolic + 1 + + + + + False + False + end + 1 + + + + + True + Search + True + True + + + + + True + edit-find-symbolic + 1 + + False @@ -102,16 +137,82 @@ True False True - 12 + 6 6 - + + True + Search + True + True + + + + + True + edit-find-symbolic + 1 + + + + + False + False + end + 1 + location + + + True + False + True + 6 + 6 + + + True + True + + + + + + True + Browse + True + True + + + + + True + folder-symbolic + 1 + + + + + False + False + end + 1 + + + + + search + + False @@ -126,24 +227,6 @@ 0 - - - True - 0 - - - True - True - - - - - - False - False - 1 - - True diff --git a/gtk/ui/gtkfilechooserwidget.ui.h b/gtk/ui/gtkfilechooserwidget.ui.h index 9c8a16ad2f..5872a159c3 100644 --- a/gtk/ui/gtkfilechooserwidget.ui.h +++ b/gtk/ui/gtkfilechooserwidget.ui.h @@ -1,4 +1,7 @@ -N_("Create Fo_lder"); +N_("Create Folder"); +N_("Search"); +N_("Search"); +N_("Browse"); N_("Files"); N_("Name"); N_("Size"); -- cgit v1.2.1