[dconf-editor] Use an action to notify search change.



commit d00294e29e8928c75af30f8799f2390ff0140e5a
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu Jan 10 20:25:55 2019 +0100

    Use an action to notify search change.
    
    That is a bit hacky, but that makes less code in
    the various HeaderBar subclasses. And it's good.

 editor/browser-headerbar.vala | 26 -------------------
 editor/browser-window.vala    | 59 ++++++++++++++++++++++---------------------
 editor/pathentry.ui           |  7 +++++
 editor/pathentry.vala         | 14 ++++++----
 editor/pathwidget.ui          |  2 --
 editor/pathwidget.vala        | 21 ---------------
 6 files changed, 46 insertions(+), 83 deletions(-)
---
diff --git a/editor/browser-headerbar.vala b/editor/browser-headerbar.vala
index 681f3ed..c1f341c 100644
--- a/editor/browser-headerbar.vala
+++ b/editor/browser-headerbar.vala
@@ -70,8 +70,6 @@ private abstract class BrowserHeaderBar : BaseHeaderBar, AdaptativeWidget
         path_widget = new PathWidget ();
         path_widget.hexpand = false;
 
-        connect_path_widget_signals ();
-
         path_widget.visible = true;
         center_box.add (path_widget);
     }
@@ -89,36 +87,12 @@ private abstract class BrowserHeaderBar : BaseHeaderBar, AdaptativeWidget
             ((BrowserHeaderBar) _this).path_widget.hide ();
     }
 
-    /*\
-    * * path_widget proxy signals
-    \*/
-
-    internal signal void search_changed ();
-    internal signal void search_stopped ();
-
-    private void connect_path_widget_signals ()
-    {
-        path_widget.search_changed.connect (search_changed_cb);
-        path_widget.search_stopped.connect (search_stopped_cb);
-    }
-
-    private void search_changed_cb ()
-    {
-        search_changed ();
-    }
-
-    private void search_stopped_cb ()
-    {
-        search_stopped ();
-    }
-
     /*\
     * * path_widget proxy calls
     \*/
 
     [CCode (notify = false)] internal bool search_mode_enabled   { get { return 
path_widget.search_mode_enabled; }}
     [CCode (notify = false)] internal bool entry_has_focus       { get { return path_widget.entry_has_focus; 
}}
-    [CCode (notify = false)] internal string text                { get { return path_widget.text; }}
 
     internal void get_complete_path (out string complete_path)   { path_widget.get_complete_path (out 
complete_path); }
     internal void get_fallback_path_and_complete_path (out string fallback_path, out string complete_path)
diff --git a/editor/browser-window.vala b/editor/browser-window.vala
index 16cfdc3..4b10b78 100644
--- a/editor/browser-window.vala
+++ b/editor/browser-window.vala
@@ -35,9 +35,6 @@ private abstract class BrowserWindow : BaseWindow
         headerbar = (BrowserHeaderBar) nta_headerbar;
         main_view = (BrowserView) base_view;
 
-        headerbar.search_changed.connect (search_changed_cb);
-        headerbar.search_stopped.connect (search_stopped_cb);
-
         this.button_press_event.connect (on_button_press_event);
 
         install_browser_action_entries ();
@@ -102,7 +99,8 @@ private abstract class BrowserWindow : BaseWindow
 
         { "hide-search",        hide_search },
         { "show-search",        show_search },
-        { "toggle-search",      toggle_search, "b", "false" }
+        { "toggle-search",      toggle_search, "b", "false" },
+        { "search-changed",     search_changed, "ms" }
     };
 
     private void empty (/* SimpleAction action, Variant? variant */) {}
@@ -243,8 +241,17 @@ private abstract class BrowserWindow : BaseWindow
     }
     protected void stop_search ()
     {
-        if (headerbar.search_mode_enabled)
-            search_stopped_cb ();
+        if (!headerbar.search_mode_enabled)
+            return;
+
+        main_view.row_grab_focus ();
+
+        reload_search_action.set_enabled (false);
+        if (saved_type == ViewType.FOLDER)
+            request_folder (saved_view, saved_selection);
+        else
+            update_current_path (saved_type, strdup (saved_view));
+        init_next_search = true;
     }
 
     private void show_search (/* SimpleAction action, Variant? path_variant */)
@@ -273,6 +280,20 @@ private abstract class BrowserWindow : BaseWindow
             stop_search ();
     }
 
+    string last_search_entry_text = "";
+    private void search_changed (SimpleAction action, Variant? path_variant)
+        requires (path_variant != null)
+    {
+        Variant? variant = ((!) path_variant).get_maybe ();
+        if (variant == null)
+            stop_search ();
+        else
+        {
+            last_search_entry_text = ((!) variant).get_string ();
+            request_search ();
+        }
+    }
+
     /*\
     * * actions and callbacks helpers
     \*/
@@ -316,7 +337,7 @@ private abstract class BrowserWindow : BaseWindow
             init_search (local_search);
         if (mode != PathEntry.SearchMode.UNCLEAR)
             headerbar.prepare_search (mode, search);
-        string search_text = search == null ? headerbar.text : (!) search;
+        string search_text = search == null ? last_search_entry_text : (!) search;
         update_current_path (ViewType.SEARCH, search_text);
         if (mode != PathEntry.SearchMode.UNCLEAR)
             main_view.select_row (selected_row);
@@ -365,26 +386,6 @@ private abstract class BrowserWindow : BaseWindow
         else
             base.show_default_view ();
     }
-    /*\
-    * * search callbacks
-    \*/
-
-    private void search_changed_cb ()
-    {
-        request_search ();
-    }
-
-    private void search_stopped_cb ()
-    {
-        main_view.row_grab_focus ();
-
-        reload_search_action.set_enabled (false);
-        if (saved_type == ViewType.FOLDER)
-            request_folder (saved_view, saved_selection);
-        else
-            update_current_path (saved_type, strdup (saved_view));
-        init_next_search = true;
-    }
 
     /*\
     * * navigation methods
@@ -591,7 +592,7 @@ private abstract class BrowserWindow : BaseWindow
             init_next_search = true;
             request_search ();
         }
-        else if (headerbar.text.has_prefix ("/"))
+        else if (last_search_entry_text.has_prefix ("/"))
         {
             init_next_search = true;
             request_search (PathEntry.SearchMode.SEARCH);
@@ -625,7 +626,7 @@ private abstract class BrowserWindow : BaseWindow
             headerbar.entry_grab_focus (true);
         else if (search_is_local)
             stop_search ();
-        else if (headerbar.text.has_prefix ("/"))
+        else if (last_search_entry_text.has_prefix ("/"))
         {
             init_next_search = true;
             request_search (PathEntry.SearchMode.SEARCH, /* search term or null */ null, /* local search */ 
true);
diff --git a/editor/pathentry.ui b/editor/pathentry.ui
index 76d10cf..e61ddc0 100644
--- a/editor/pathentry.ui
+++ b/editor/pathentry.ui
@@ -18,6 +18,13 @@
         </style>
       </object>
     </child>
+    <child>
+      <object class="GtkButton" id="search_action_button">
+        <property name="visible">False</property>
+        <property name="action-name">browser.search-changed</property>
+        <property name="action-target">@ms nothing</property>
+      </object>
+    </child>
     <!-- child>
       <object class="GtkButton" id="search_options_button">
         <property name="visible">False</property>
diff --git a/editor/pathentry.vala b/editor/pathentry.vala
index f325e5e..ef8d0c2 100644
--- a/editor/pathentry.vala
+++ b/editor/pathentry.vala
@@ -24,10 +24,10 @@ private class PathEntry : Box, AdaptativeWidget
     [GtkChild] private Button       reload_search_button;
 
     [GtkChild] private SearchEntry  search_entry;
+    [GtkChild] private Button       search_action_button;
 
     private string current_path = "";
 
-    [CCode (notify = false)] internal string text { get { return search_entry.text; }}
     [CCode (notify = false)] internal bool entry_has_focus { get { return search_entry.has_focus; }}
 
     internal override void get_preferred_width (out int minimum_width, out int natural_width)
@@ -88,13 +88,17 @@ private class PathEntry : Box, AdaptativeWidget
     }
 
     private ulong search_changed_handler = 0;
-    internal signal void search_changed ();
-    internal signal void search_stopped ();
 
     construct
     {
-        search_changed_handler = search_entry.search_changed.connect (() => search_changed ()); 
-        search_entry.stop_search.connect (() => search_stopped ());
+        search_changed_handler = search_entry.search_changed.connect (() => {
+                search_action_button.set_action_target ("ms", search_entry.text);
+                search_action_button.clicked ();
+            });
+        search_entry.stop_search.connect (() => {
+                search_action_button.set_action_target ("ms", null);
+                search_action_button.clicked ();
+            });
     }
 
     internal void entry_grab_focus_without_selecting ()
diff --git a/editor/pathwidget.ui b/editor/pathwidget.ui
index 06f93ba..2ad8200 100644
--- a/editor/pathwidget.ui
+++ b/editor/pathwidget.ui
@@ -14,8 +14,6 @@
         <child>
           <object class="PathEntry" id="searchentry">
             <property name="visible">True</property>
-            <signal name="search-changed" handler="search_changed_cb"/>
-            <signal name="search-stopped" handler="search_stopped_cb"/>
           </object>
         </child>
         <child>
diff --git a/editor/pathwidget.vala b/editor/pathwidget.vala
index 0a1e3b6..7fc4698 100644
--- a/editor/pathwidget.vala
+++ b/editor/pathwidget.vala
@@ -30,9 +30,6 @@ private class PathWidget : Box, AdaptativeWidget
     [GtkChild] private Revealer             parent_revealer;
     [GtkChild] private ModelButton          parent_button;
 
-    internal signal void search_changed ();
-    internal signal void search_stopped ();
-
     private ThemedIcon search_icon = new ThemedIcon.from_names ({"edit-find-symbolic"});
     private ThemedIcon parent_icon = new ThemedIcon.from_names ({"go-up-symbolic"});
     construct
@@ -98,23 +95,6 @@ private class PathWidget : Box, AdaptativeWidget
         pathwidget_stack.set_visible_child (pathbar_grid);
     }
 
-    /*\
-    * * callbacks
-    \*/
-
-    [GtkCallback]
-    private void search_changed_cb ()
-    {
-        if (search_mode_enabled)
-            search_changed ();
-    }
-
-    [GtkCallback]
-    private void search_stopped_cb ()
-    {
-        search_stopped ();
-    }
-
     /*\
     * * proxy calls
     \*/
@@ -181,7 +161,6 @@ private class PathWidget : Box, AdaptativeWidget
     }
 
     /* path entry */
-    [CCode (notify = false)] internal string text           { get { return searchentry.text; }}
     [CCode (notify = false)] internal bool entry_has_focus  { get { return searchentry.entry_has_focus; }}
     internal void entry_grab_focus ()                       { searchentry.entry_grab_focus (); }
     internal void entry_grab_focus_without_selecting ()     { searchentry.entry_grab_focus_without_selecting 
(); }


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