[dconf-editor] Get search entry has_focus another way.



commit 38849ddb57d26dff3a2c62fa65d7a6d1fff65379
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu Jan 10 20:54:05 2019 +0100

    Get search entry has_focus another way.
    
    Instead of asking its parent, let's ask the window.

 editor/bookmarks-list.vala    |  4 +--
 editor/browser-headerbar.vala |  1 -
 editor/browser-window.vala    | 18 ++++++++---
 editor/dconf-window.vala      |  7 +----
 editor/pathentry.ui           |  2 +-
 editor/pathentry.vala         | 72 +++++++++++++++++++++++++++----------------
 editor/pathwidget.vala        |  1 -
 editor/registry-search.vala   |  2 +-
 8 files changed, 65 insertions(+), 42 deletions(-)
---
diff --git a/editor/bookmarks-list.vala b/editor/bookmarks-list.vala
index f920db6..393973b 100644
--- a/editor/bookmarks-list.vala
+++ b/editor/bookmarks-list.vala
@@ -135,7 +135,7 @@ private class BookmarksList : OverlayedList
         string [] unduplicated_bookmarks = {};
         foreach (string bookmark in all_bookmarks)
         {
-            if (DConfWindow.is_path_invalid (bookmark))
+            if (BrowserWindow.is_path_invalid (bookmark))
                 continue;
             if (bookmark in unduplicated_bookmarks)
                 continue;
@@ -164,7 +164,7 @@ private class BookmarksList : OverlayedList
         string [] unduplicated_bookmarks = new string [0];
         foreach (string bookmark in bookmarks)
         {
-            if (DConfWindow.is_path_invalid (bookmark))
+            if (BrowserWindow.is_path_invalid (bookmark))
                 continue;
             if (bookmark in unduplicated_bookmarks)
                 continue;
diff --git a/editor/browser-headerbar.vala b/editor/browser-headerbar.vala
index c1f341c..627b1ef 100644
--- a/editor/browser-headerbar.vala
+++ b/editor/browser-headerbar.vala
@@ -92,7 +92,6 @@ private abstract class BrowserHeaderBar : BaseHeaderBar, AdaptativeWidget
     \*/
 
     [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; 
}}
 
     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 ec42435..616dfeb 100644
--- a/editor/browser-window.vala
+++ b/editor/browser-window.vala
@@ -341,7 +341,7 @@ private abstract class BrowserWindow : BaseWindow
         update_current_path (ViewType.SEARCH, search_text);
         if (mode != PathEntry.SearchMode.UNCLEAR)
             main_view.select_row (selected_row);
-        if (!headerbar.entry_has_focus)
+        if (!search_entry_has_focus ())
             headerbar.entry_grab_focus (/* select text */ false); // FIXME keep cursor position
     }
     private void init_search (bool local_search)
@@ -353,6 +353,16 @@ private abstract class BrowserWindow : BaseWindow
     }
     protected abstract void reconfigure_search (bool local_search);
 
+    private bool search_entry_has_focus ()
+    {
+        return get_focus () is BrowserEntry;
+    }
+
+    public static bool is_path_invalid (string path)
+    {
+        return path.has_prefix ("/") && (path.contains ("//") || path.contains (" "));
+    }
+
     /*\
     * * window state
     \*/
@@ -585,7 +595,7 @@ private abstract class BrowserWindow : BaseWindow
             else
                 request_search (PathEntry.SearchMode.SEARCH);
         }
-        else if (!headerbar.entry_has_focus)
+        else if (!search_entry_has_focus ())
             headerbar.entry_grab_focus (true);
         else if (search_is_local)
         {
@@ -622,7 +632,7 @@ private abstract class BrowserWindow : BaseWindow
                                 /* search term or null */ null,
                                 /* local search */ current_path != "/");
         }
-        else if (!headerbar.entry_has_focus)
+        else if (!search_entry_has_focus ())
             headerbar.entry_grab_focus (true);
         else if (search_is_local)
             stop_search ();
@@ -748,7 +758,7 @@ private abstract class BrowserWindow : BaseWindow
         if (name == "Return" || name == "KP_Enter")
         {
             if (main_view.current_view == ViewType.SEARCH
-             && headerbar.entry_has_focus
+             && search_entry_has_focus ()
              && main_view.return_pressed ())
                 return true;
             return false;
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 8286d02..59014af 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -583,7 +583,7 @@ private class DConfWindow : BrowserWindow
                 update_bookmark_icon (bookmark, BookmarkIcon.SEARCH);
                 continue;
             }
-            if (is_path_invalid (bookmark)) // TODO broken folder and broken object
+            if (BrowserWindow.is_path_invalid (bookmark)) // TODO broken folder and broken object
                 continue;
 
             uint16 context_id;
@@ -932,11 +932,6 @@ private class DConfWindow : BrowserWindow
             show_default_view ();
     }
 
-    public static bool is_path_invalid (string path)
-    {
-        return path.has_prefix ("/") && (path.contains ("//") || path.contains (" "));
-    }
-
     protected override void request_config (string full_name)
     {
         main_view.prepare_object_view (full_name, ModelUtils.folder_context_id,
diff --git a/editor/pathentry.ui b/editor/pathentry.ui
index e61ddc0..ff46cdb 100644
--- a/editor/pathentry.ui
+++ b/editor/pathentry.ui
@@ -9,7 +9,7 @@
       <class name="linked"/>
     </style>
     <child>
-      <object class="GtkSearchEntry" id="search_entry">
+      <object class="BrowserEntry" id="search_entry">
         <property name="visible">True</property>
         <property name="hexpand">True</property>
         <!-- "next-match" (<ctrl>g) and "previous-match" (<ctrl>G) are handled in dconf-window.vala -->
diff --git a/editor/pathentry.vala b/editor/pathentry.vala
index 1e6821e..5000b21 100644
--- a/editor/pathentry.vala
+++ b/editor/pathentry.vala
@@ -17,19 +17,51 @@
 
 using Gtk;
 
+private class BrowserEntry : SearchEntry
+{
+    private StyleContext context;
+
+    construct
+    {
+        context = get_style_context ();
+    }
+
+    private bool has_error_class = false;
+    internal void check_error (ref string path)
+    {
+        bool is_invalid = BrowserWindow.is_path_invalid (path);
+        if (!has_error_class && is_invalid)
+        {
+            has_error_class = true;
+            context.add_class ("error");
+        }
+        else if (has_error_class && !is_invalid)
+        {
+            has_error_class = false;
+            context.remove_class ("error");
+        }
+    }
+
+    internal void set_is_thin_window (bool thin_window)
+    {
+        if (thin_window)
+            set_icon_from_pixbuf (EntryIconPosition.PRIMARY, null);
+        else
+            set_icon_from_icon_name (EntryIconPosition.PRIMARY, "edit-find-symbolic");
+    }
+}
+
 [GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/pathentry.ui")]
 private class PathEntry : Box, AdaptativeWidget
 {
     [GtkChild] private Button       hide_search_button;
     [GtkChild] private Button       reload_search_button;
 
-    [GtkChild] private SearchEntry  search_entry;
+    [GtkChild] private BrowserEntry search_entry;
     [GtkChild] private Button       search_action_button;
 
     private string current_path = "";
 
-    [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)
     {
         base.get_preferred_width (out minimum_width, out natural_width);
@@ -45,10 +77,10 @@ private class PathEntry : Box, AdaptativeWidget
             return;
         thin_window = _thin_window;
 
+        search_entry.set_is_thin_window (_thin_window);
+
         if (_thin_window)
         {
-            search_entry.set_icon_from_pixbuf (EntryIconPosition.PRIMARY, null);
-
             can_reload_handler = reload_search_button.notify ["sensitive"].connect (() => {
                     if (reload_search_button.sensitive)
                     {
@@ -70,8 +102,6 @@ private class PathEntry : Box, AdaptativeWidget
         }
         else
         {
-            search_entry.set_icon_from_icon_name (EntryIconPosition.PRIMARY, "edit-find-symbolic");
-
             reload_search_button.disconnect (can_reload_handler);
 
             hide_search_button.hide ();
@@ -105,7 +135,7 @@ private class PathEntry : Box, AdaptativeWidget
     {
         _entry_grab_focus_without_selecting (ref search_entry);
     }
-    private static void _entry_grab_focus_without_selecting (ref SearchEntry search_entry)
+    private static void _entry_grab_focus_without_selecting (ref BrowserEntry search_entry)
     {
         if (search_entry.text_length != 0)
         {
@@ -124,21 +154,11 @@ private class PathEntry : Box, AdaptativeWidget
         return search_entry.handle_event (event);
     }
 
-    private bool has_error_class = false;
     internal void set_path (ViewType type, string _path)
     {
         string path = _path.strip ();
 
-        if (!has_error_class && DConfWindow.is_path_invalid (path))
-        {
-            has_error_class = true;
-            search_entry.get_style_context ().add_class ("error");
-        }
-        else if (has_error_class && !DConfWindow.is_path_invalid (path))
-        {
-            has_error_class = false;
-            search_entry.get_style_context ().remove_class ("error");
-        }
+        search_entry.check_error (ref path);
 
         current_path = path;
 //        if (type == ViewType.SEARCH)
@@ -156,10 +176,10 @@ private class PathEntry : Box, AdaptativeWidget
         SignalHandler.unblock (search_entry, search_changed_handler);
     }
 
-    private static inline void _prepare (SearchMode  mode,
-                                         string?     nullable_search,
-                                     ref string      current_path,
-                                     ref SearchEntry search_entry)
+    private static inline void _prepare (SearchMode   mode,
+                                         string?      nullable_search,
+                                     ref string       current_path,
+                                     ref BrowserEntry search_entry)
     {
         string search;
         switch (mode)
@@ -190,19 +210,19 @@ private class PathEntry : Box, AdaptativeWidget
         }
     }
 
-    private static inline void _prepare_move_end (ref string text, ref SearchEntry search_entry)
+    private static inline void _prepare_move_end (ref string text, ref BrowserEntry search_entry)
     {
         search_entry.text = text;
         _entry_grab_focus_without_selecting (ref search_entry);
     }
 
-    private static inline void _prepare_search (ref string text, ref SearchEntry search_entry)
+    private static inline void _prepare_search (ref string text, ref BrowserEntry search_entry)
     {
         search_entry.text = text;
         search_entry.grab_focus ();
     }
 
-    private static inline void _prepare_select_last_word (ref string current_path, ref SearchEntry 
search_entry)
+    private static inline void _prepare_select_last_word (ref string current_path, ref BrowserEntry 
search_entry)
     {
         search_entry.move_cursor (MovementStep.DISPLAY_LINE_ENDS, -1, false);
         search_entry.text = current_path;
diff --git a/editor/pathwidget.vala b/editor/pathwidget.vala
index d1a9198..4b02735 100644
--- a/editor/pathwidget.vala
+++ b/editor/pathwidget.vala
@@ -161,7 +161,6 @@ private class PathWidget : Box, AdaptativeWidget
     }
 
     /* path entry */
-    [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 
(); }
 
diff --git a/editor/registry-search.vala b/editor/registry-search.vala
index fb85ffd..220583f 100644
--- a/editor/registry-search.vala
+++ b/editor/registry-search.vala
@@ -187,7 +187,7 @@ private class RegistrySearch : RegistryList
     {
         string term = _term.strip ();
 
-        if (DConfWindow.is_path_invalid (term))
+        if (BrowserWindow.is_path_invalid (term))
         {
             if (old_term != null)
                 ensure_selection (key_list_box, (!) old_term);


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