[dconf-editor] Make some methods static.



commit 69c2740668e8ecc0e9d438614412e7c20ce67748
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu Jan 10 20:28:51 2019 +0100

    Make some methods static.
    
    Rework the _prepare method that is used to configure
    the text of the search entry before it is displayed.

 editor/pathentry.vala | 79 +++++++++++++++++++++++++++++++++++----------------
 1 file changed, 55 insertions(+), 24 deletions(-)
---
diff --git a/editor/pathentry.vala b/editor/pathentry.vala
index ef8d0c2..1e6821e 100644
--- a/editor/pathentry.vala
+++ b/editor/pathentry.vala
@@ -102,6 +102,10 @@ private class PathEntry : Box, AdaptativeWidget
     }
 
     internal void entry_grab_focus_without_selecting ()
+    {
+        _entry_grab_focus_without_selecting (ref search_entry);
+    }
+    private static void _entry_grab_focus_without_selecting (ref SearchEntry search_entry)
     {
         if (search_entry.text_length != 0)
         {
@@ -140,48 +144,44 @@ private class PathEntry : Box, AdaptativeWidget
 //        if (type == ViewType.SEARCH)
     }
 
-    internal void prepare (SearchMode mode, string? search = null)
+    /*\
+    * * prepare call
+    \*/
+
+    internal void prepare (SearchMode mode, string? nullable_search = null)
         requires (search_changed_handler != 0)
     {
         SignalHandler.block (search_entry, search_changed_handler);
-        _prepare (mode, search);
+        _prepare (mode, nullable_search, ref current_path, ref search_entry);
         SignalHandler.unblock (search_entry, search_changed_handler);
     }
-    private inline void _prepare (SearchMode mode, string? search)
+
+    private static inline void _prepare (SearchMode  mode,
+                                         string?     nullable_search,
+                                     ref string      current_path,
+                                     ref SearchEntry search_entry)
     {
+        string search;
         switch (mode)
         {
             case SearchMode.EDIT_PATH_MOVE_END:
-                search_entry.text = search == null ? current_path : (!) search;
-                entry_grab_focus_without_selecting ();
+                search = nullable_search == null ? current_path : (!) nullable_search;
+                _prepare_move_end (ref search, ref search_entry);
                 return;
 
             case SearchMode.EDIT_PATH_SELECT_ALL:
-                search_entry.text = search == null ? current_path : (!) search;
-                search_entry.grab_focus ();
+                search = nullable_search == null ? current_path : (!) nullable_search;
+                _prepare_search (ref search, ref search_entry);
                 return;
 
             case SearchMode.EDIT_PATH_SELECT_LAST_WORD:
-                search_entry.move_cursor (MovementStep.DISPLAY_LINE_ENDS, -1, false);
-                search_entry.text = current_path;
-                if (search_entry.text_length == 1)  // root
-                {
-                    search_entry.grab_focus ();
-                    return;
-                }
-                if (search_entry.text_length != 0)
-                {
-                    if (search_entry.cursor_position == search_entry.text_length)
-                        search_entry.move_cursor (MovementStep.DISPLAY_LINE_ENDS, -1, false);
-                    search_entry.move_cursor (MovementStep.VISUAL_POSITIONS, ModelUtils.get_parent_path 
(current_path).length, false);
-                    search_entry.move_cursor (MovementStep.DISPLAY_LINE_ENDS, 1, true);
-                }
-                search_entry.grab_focus_without_selecting ();
+                search = current_path;
+                _prepare_select_last_word (ref search, ref search_entry);
                 return;
 
             case SearchMode.SEARCH:
-                search_entry.text = "";
-                search_entry.grab_focus ();
+                search = "";
+                _prepare_search (ref search, ref search_entry);
                 return;
 
             case SearchMode.UNCLEAR:
@@ -189,4 +189,35 @@ private class PathEntry : Box, AdaptativeWidget
                 assert_not_reached ();
         }
     }
+
+    private static inline void _prepare_move_end (ref string text, ref SearchEntry 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)
+    {
+        search_entry.text = text;
+        search_entry.grab_focus ();
+    }
+
+    private static inline void _prepare_select_last_word (ref string current_path, ref SearchEntry 
search_entry)
+    {
+        search_entry.move_cursor (MovementStep.DISPLAY_LINE_ENDS, -1, false);
+        search_entry.text = current_path;
+        if (search_entry.text_length == 1)  // root
+        {
+            search_entry.grab_focus ();
+            return;
+        }
+        if (search_entry.text_length != 0)
+        {
+            if (search_entry.cursor_position == search_entry.text_length)
+                search_entry.move_cursor (MovementStep.DISPLAY_LINE_ENDS, -1, false);
+            search_entry.move_cursor (MovementStep.VISUAL_POSITIONS, ModelUtils.get_parent_path 
(current_path).length, false);
+            search_entry.move_cursor (MovementStep.DISPLAY_LINE_ENDS, 1, true);
+        }
+        search_entry.grab_focus_without_selecting ();
+    }
 }


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