[gtk+] file chooser: Allow to limit search



commit ff87c6516bdfcf40a11ef56d8206d3b484563159
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Feb 14 00:48:26 2015 -0500

    file chooser: Allow to limit search
    
    Add a button to allow restricting search to the current
    folder (and subdirectories). This makes the search more
    useful, and makes the file chooser more similar to
    nautilus.

 gtk/gtkfilechooserwidget.c       |   23 +++++++++++++++++++++--
 gtk/ui/gtkfilechooserwidget.ui   |   24 ++++++++++++++++++++++++
 gtk/ui/gtkfilechooserwidget.ui.h |    2 ++
 3 files changed, 47 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index 7f97b8e..2bdd78d 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -67,6 +67,7 @@
 #include "gtksettings.h"
 #include "gtksizegroup.h"
 #include "gtksizerequest.h"
+#include "gtktogglebutton.h"
 #include "gtktoolbar.h"
 #include "gtktoolbutton.h"
 #include "gtktooltip.h"
@@ -235,6 +236,7 @@ struct _GtkFileChooserWidgetPrivate {
 
   /* OPERATION_MODE_SEARCH */
   GtkWidget *search_entry;
+  GtkWidget *current_location_radio;
   GtkSearchEngine *search_engine;
   GtkQuery *search_query;
   GtkFileSystemModel *search_model;
@@ -2539,6 +2541,7 @@ static void
 operation_mode_set_search (GtkFileChooserWidget *impl)
 {
   GtkFileChooserWidgetPrivate *priv = impl->priv;
+  gchar *current;
 
   g_assert (priv->search_model == NULL);
 
@@ -2548,6 +2551,12 @@ operation_mode_set_search (GtkFileChooserWidget *impl)
   gtk_entry_grab_focus_without_selecting (GTK_ENTRY (priv->search_entry));
   gtk_places_sidebar_set_location (GTK_PLACES_SIDEBAR (priv->places_sidebar), NULL);
   gtk_widget_set_sensitive (priv->filter_combo, FALSE);
+  if (priv->current_folder)
+    current = g_file_get_basename (priv->current_folder);
+  else
+    current = g_strdup (_("Home"));
+  gtk_button_set_label (GTK_BUTTON (priv->current_location_radio), current);
+  g_free (current);
 
   gtk_tree_view_column_set_visible (priv->list_location_column, TRUE);
 }
@@ -6257,7 +6266,7 @@ search_setup_model (GtkFileChooserWidget *impl)
 /* Creates a new query with the specified text and launches it */
 static void
 search_start_query (GtkFileChooserWidget *impl,
-                   const gchar           *query_text)
+                   const gchar          *query_text)
 {
   GtkFileChooserWidgetPrivate *priv = impl->priv;
 
@@ -6281,7 +6290,16 @@ search_start_query (GtkFileChooserWidget *impl,
       priv->search_query = _gtk_query_new ();
       _gtk_query_set_text (priv->search_query, query_text);
     }
-  
+
+  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->current_location_radio)) &&
+      priv->current_folder)
+    {
+      gchar *location;
+      location = g_file_get_uri (priv->current_folder);
+      _gtk_query_set_location (priv->search_query, location);
+      g_free (location);
+    }
+
   _gtk_search_engine_set_query (priv->search_engine, priv->search_query);
 
   g_signal_connect (priv->search_engine, "hits-added",
@@ -7478,6 +7496,7 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
   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_entry);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, current_location_radio);
   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);
   gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, list_name_renderer);
diff --git a/gtk/ui/gtkfilechooserwidget.ui b/gtk/ui/gtkfilechooserwidget.ui
index 1eb4332..83e095c 100644
--- a/gtk/ui/gtkfilechooserwidget.ui
+++ b/gtk/ui/gtkfilechooserwidget.ui
@@ -134,6 +134,30 @@
                                 <signal name="stop-search" handler="search_entry_stop_cb" swapped="yes"/>
                               </object>
                             </child>
+                            <child>
+                              <object class="GtkBox">
+                                <property name="visible">True</property>
+                                <style>
+                                  <class name="linked"/>
+                                </style>
+                                <child>
+                                  <object class="GtkRadioButton" id="current_location_radio">
+                                    <property name="visible">True</property>
+                                    <property name="draw-indicator">False</property>
+                                    <property name="label" translatable="yes">Home</property>
+                                    <signal name="toggled" handler="search_entry_activate_cb" swapped="yes"/>
+                                  </object>
+                                </child>
+                                <child>
+                                  <object class="GtkRadioButton">
+                                    <property name="visible">True</property>
+                                    <property name="draw-indicator">False</property>
+                                    <property name="group">current_location_radio</property>
+                                    <property name="label" translatable="yes">All Files</property>
+                                  </object>
+                                </child>
+                              </object>
+                            </child>
                           </object>
                           <packing>
                             <property name="name">search</property>
diff --git a/gtk/ui/gtkfilechooserwidget.ui.h b/gtk/ui/gtkfilechooserwidget.ui.h
index 76512b3..b29f3fa 100644
--- a/gtk/ui/gtkfilechooserwidget.ui.h
+++ b/gtk/ui/gtkfilechooserwidget.ui.h
@@ -1,4 +1,6 @@
 N_("Create Folder");
+N_("Home");
+N_("All Files");
 N_("Files");
 N_("Name");
 N_("Size");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]