[dconf-editor] Introduce BrowserStack.



commit fd9650928a8db58cb62004726c52022448b688ed
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sun Feb 11 11:49:49 2018 +0100

    Introduce BrowserStack.

 editor/browser-stack.ui           |   44 +++++++
 editor/browser-stack.vala         |  240 +++++++++++++++++++++++++++++++++++++
 editor/browser-view.ui            |   29 +-----
 editor/browser-view.vala          |  194 +++++-------------------------
 editor/dconf-editor.gresource.xml |    1 +
 editor/meson.build                |    2 +
 6 files changed, 320 insertions(+), 190 deletions(-)
---
diff --git a/editor/browser-stack.ui b/editor/browser-stack.ui
new file mode 100644
index 0000000..5c829d4
--- /dev/null
+++ b/editor/browser-stack.ui
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="dconf-editor">
+  <!-- interface-requires gtk+ 3.0 -->
+  <template class="BrowserStack" parent="GtkGrid">
+    <property name="orientation">vertical</property>
+    <child>
+      <object class="BrowserInfoBar" id="info_bar">
+        <property name="visible">True</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkStack" id="stack">
+        <property name="visible">True</property>
+        <property name="visible-child">browse_view</property> <!-- uses the "id" attribute -->
+        <property name="transition-type">crossfade</property>
+        <property name="expand">True</property>
+        <child>
+          <object class="RegistryView"  id="browse_view">
+            <property name="visible">True</property>
+          </object>
+          <packing>
+            <property name="name">browse-view</property>
+          </packing>
+        </child>
+        <child>
+          <object class="RegistryInfo" id="properties_view">
+            <property name="visible">True</property>
+          </object>
+          <packing>
+            <property name="name">properties-view</property>
+          </packing>
+        </child>
+        <child>
+          <object class="RegistrySearch"  id="search_results_view">
+            <property name="visible">True</property>
+          </object>
+          <packing>
+            <property name="name">search-results-view</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/editor/browser-stack.vala b/editor/browser-stack.vala
new file mode 100644
index 0000000..688d60a
--- /dev/null
+++ b/editor/browser-stack.vala
@@ -0,0 +1,240 @@
+/*
+  This file is part of Dconf Editor
+
+  Dconf Editor is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  Dconf Editor is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with Dconf Editor.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+using Gtk;
+
+[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/browser-stack.ui")]
+class BrowserStack : Grid
+{
+    [GtkChild] private Stack stack;
+    [GtkChild] private RegistryView browse_view;
+    [GtkChild] private RegistryInfo properties_view;
+    [GtkChild] private RegistrySearch search_results_view;
+    private Widget? pre_search_view = null;
+
+    public bool small_keys_list_rows
+    {
+        set
+        {
+            browse_view.small_keys_list_rows = value;
+            search_results_view.small_keys_list_rows = value;
+        }
+    }
+
+    public ModificationsHandler modifications_handler
+    {
+        set {
+            browse_view.modifications_handler = value;
+            properties_view.modifications_handler = value;
+            search_results_view.modifications_handler = value;
+        }
+    }
+
+    /*\
+    * * Views
+    \*/
+
+    public string get_selected_row_name ()
+    {
+        if (current_view_is_browse_view ())
+            return browse_view.get_selected_row_name ();
+        if (current_view_is_search_results_view ())
+            return search_results_view.get_selected_row_name ();
+        return "";
+    }
+
+    public void prepare_browse_view (GLib.ListStore key_model, bool is_ancestor)
+    {
+        browse_view.set_key_model (key_model);
+
+        stack.set_transition_type (is_ancestor && pre_search_view == null ? StackTransitionType.CROSSFADE : 
StackTransitionType.NONE);
+        pre_search_view = null;
+    }
+
+    public void select_row (string selected, string last_context)
+    {
+        bool grab_focus = true;     // unused, for now
+        if (selected != "")
+            browse_view.select_row_named (selected, last_context, grab_focus);
+        else
+            browse_view.select_first_row (grab_focus);
+        properties_view.clean ();
+    }
+
+    public void prepare_properties_view (Key key, bool is_parent)
+    {
+        properties_view.populate_properties_list_box (key);
+
+        stack.set_transition_type (is_parent && pre_search_view == null ? StackTransitionType.CROSSFADE : 
StackTransitionType.NONE);
+        pre_search_view = null;
+    }
+
+    public void show_search_view (string term, string current_path, string [] bookmarks, SortingOptions 
sorting_options)
+    {
+        search_results_view.start_search (term, current_path, bookmarks, sorting_options);
+        if (pre_search_view == null)
+        {
+            pre_search_view = stack.visible_child;
+            stack.set_transition_type (StackTransitionType.NONE);
+            stack.visible_child = search_results_view;
+        }
+    }
+
+    public void hide_search_view ()
+    {
+        if (pre_search_view != null)
+        {
+            stack.set_transition_type (StackTransitionType.NONE);
+            stack.visible_child = (!) pre_search_view;
+            pre_search_view = null;
+
+            if (stack.get_visible_child () == browse_view)
+                browse_view.focus_selected_row ();
+        }
+        search_results_view.stop_search ();
+    }
+
+    public void set_path (string path)
+    {
+        if (path.has_suffix ("/"))
+            stack.set_visible_child (browse_view);
+        else
+            stack.set_visible_child (properties_view);
+    }
+
+    public string? get_copy_text ()
+    {
+        return ((BrowsableView) stack.get_visible_child ()).get_copy_text ();
+    }
+
+    public string? get_copy_path_text ()
+    {
+        if (current_view_is_search_results_view ())
+            return search_results_view.get_copy_path_text ();
+
+        warning ("BrowserView get_copy_path_text() called but current view is not search results view.");
+        return null;
+    }
+
+    public bool show_row_popover ()
+    {
+        if (current_view_is_browse_view ())
+            return browse_view.show_row_popover ();
+        if (current_view_is_search_results_view ())
+            return search_results_view.show_row_popover ();
+        return false;
+    }
+
+    public void toggle_boolean_key ()
+    {
+        if (current_view_is_browse_view ())
+            browse_view.toggle_boolean_key ();
+        else if (current_view_is_search_results_view ())
+            search_results_view.toggle_boolean_key ();
+    }
+
+    public void set_selected_to_default ()
+    {
+        if (current_view_is_browse_view ())
+            browse_view.set_selected_to_default ();
+        else if (current_view_is_search_results_view ())
+            search_results_view.set_selected_to_default ();
+    }
+
+    public void discard_row_popover ()
+    {
+        if (current_view_is_browse_view ())
+            browse_view.discard_row_popover ();
+        else if (current_view_is_search_results_view ())
+            search_results_view.discard_row_popover ();
+    }
+
+    public void invalidate_popovers ()
+    {
+        browse_view.invalidate_popovers ();
+        search_results_view.invalidate_popovers ();
+    }
+
+    public bool current_view_is_browse_view ()
+    {
+        return stack.get_visible_child () == browse_view;
+    }
+
+    public bool current_view_is_properties_view ()
+    {
+        return stack.get_visible_child () == properties_view;
+    }
+
+    public bool current_view_is_search_results_view ()
+    {
+        return stack.get_visible_child () == search_results_view;
+    }
+
+    /*\
+    * * Reload
+    \*/
+
+    public void reload_search (string current_path, string [] bookmarks, SortingOptions sorting_options)
+    {
+        search_results_view.reload_search (current_path, bookmarks, sorting_options);
+    }
+
+    public bool check_reload_folder (GLib.ListStore fresh_key_model)
+    {
+        return browse_view.check_reload (fresh_key_model);
+    }
+
+    public bool check_reload_object (Variant properties)
+    {
+        return properties_view.check_reload (properties);
+    }
+
+    /*\
+    * * Keyboard calls
+    \*/
+
+    public bool return_pressed ()
+    {
+        if (!current_view_is_search_results_view ())
+            assert_not_reached ();
+
+        return search_results_view.return_pressed ();
+    }
+
+    public bool up_pressed ()
+    {
+        if (current_view_is_browse_view ())
+            return browse_view.up_or_down_pressed (false);
+        else if (current_view_is_search_results_view ())
+            return search_results_view.up_or_down_pressed (false);
+        return false;
+    }
+
+    public bool down_pressed ()
+    {
+        if (current_view_is_browse_view ())
+            return browse_view.up_or_down_pressed (true);
+        else if (current_view_is_search_results_view ())
+            return search_results_view.up_or_down_pressed (true);
+        return false;
+    }
+}
+
+public interface BrowsableView
+{
+    public abstract string? get_copy_text ();
+}
diff --git a/editor/browser-view.ui b/editor/browser-view.ui
index 599d0d2..4f0de26 100644
--- a/editor/browser-view.ui
+++ b/editor/browser-view.ui
@@ -9,35 +9,8 @@
       </object>
     </child>
     <child>
-      <object class="GtkStack" id="stack">
+      <object class="BrowserStack" id="current_child">
         <property name="visible">True</property>
-        <property name="visible-child">browse_view</property> <!-- uses the "id" attribute -->
-        <property name="transition-type">crossfade</property>
-        <property name="expand">True</property>
-        <child>
-          <object class="RegistryView"  id="browse_view">
-            <property name="visible">True</property>
-          </object>
-          <packing>
-            <property name="name">browse-view</property>
-          </packing>
-        </child>
-        <child>
-          <object class="RegistryInfo" id="properties_view">
-            <property name="visible">True</property>
-          </object>
-          <packing>
-            <property name="name">properties-view</property>
-          </packing>
-        </child>
-        <child>
-          <object class="RegistrySearch"  id="search_results_view">
-            <property name="visible">True</property>
-          </object>
-          <packing>
-            <property name="name">search-results-view</property>
-          </packing>
-        </child>
       </object>
     </child>
   </template>
diff --git a/editor/browser-view.vala b/editor/browser-view.vala
index 13ea1a1..2b216ed 100644
--- a/editor/browser-view.vala
+++ b/editor/browser-view.vala
@@ -23,24 +23,12 @@ class BrowserView : Grid
     public string last_context { get; private set; default = ""; }
 
     [GtkChild] private BrowserInfoBar info_bar;
-
-    [GtkChild] private Stack stack;
-    [GtkChild] private RegistryView browse_view;
-    [GtkChild] private RegistryInfo properties_view;
-    [GtkChild] private RegistrySearch search_results_view;
-    private Widget? pre_search_view = null;
+    [GtkChild] private BrowserStack current_child;
 
     private SortingOptions sorting_options = new SortingOptions ();
     private GLib.ListStore? key_model = null;
 
-    public bool small_keys_list_rows
-    {
-        set
-        {
-            browse_view.small_keys_list_rows = value;
-            search_results_view.small_keys_list_rows = value;
-        }
-    }
+    public bool small_keys_list_rows { set { current_child.small_keys_list_rows = value; }}
 
     private ModificationsHandler _modifications_handler;
     public ModificationsHandler modifications_handler
@@ -48,9 +36,7 @@ class BrowserView : Grid
         private get { return _modifications_handler; }
         set {
             _modifications_handler = value;
-            browse_view.modifications_handler = value;
-            properties_view.modifications_handler = value;
-            search_results_view.modifications_handler = value;
+            current_child.modifications_handler = value;
         }
     }
 
@@ -169,151 +155,42 @@ class BrowserView : Grid
     * * Views
     \*/
 
-    public string get_selected_row_name ()
-    {
-        if (current_view_is_browse_view ())
-            return browse_view.get_selected_row_name ();
-        if (current_view_is_search_results_view ())
-            return search_results_view.get_selected_row_name ();
-        return "";
-    }
-
     public void prepare_browse_view (GLib.ListStore key_model, bool is_ancestor)
     {
         this.key_model = key_model;
         sorting_options.sort_key_model (key_model);
-        browse_view.set_key_model (key_model);
-
-        stack.set_transition_type (is_ancestor && pre_search_view == null ? StackTransitionType.CROSSFADE : 
StackTransitionType.NONE);
-        pre_search_view = null;
+        current_child.prepare_browse_view (key_model, is_ancestor);
         hide_reload_warning ();
     }
 
     public void select_row (string selected)
     {
-        bool grab_focus = true;     // unused, for now
-        if (selected != "")
-            browse_view.select_row_named (selected, last_context, grab_focus);
-        else
-            browse_view.select_first_row (grab_focus);
-        properties_view.clean ();
+        current_child.select_row (selected, last_context);
     }
 
     public void prepare_properties_view (Key key, bool is_parent)
     {
-        properties_view.populate_properties_list_box (key);
-
+        current_child.prepare_properties_view (key, is_parent);
         hide_reload_warning ();
-
-        stack.set_transition_type (is_parent && pre_search_view == null ? StackTransitionType.CROSSFADE : 
StackTransitionType.NONE);
-        pre_search_view = null;
-
         last_context = (key is GSettingsKey) ? ((GSettingsKey) key).schema_id : ".dconf";
     }
 
     public void show_search_view (string term, string current_path, string [] bookmarks)
     {
-        search_results_view.start_search (term, current_path, bookmarks, sorting_options);
-        if (pre_search_view == null)
-        {
-            pre_search_view = stack.visible_child;
-            stack.set_transition_type (StackTransitionType.NONE);
-            stack.visible_child = search_results_view;
-        }
+        current_child.show_search_view (term, current_path, bookmarks, sorting_options);
     }
 
     public void hide_search_view ()
     {
-        if (pre_search_view != null)
-        {
-            stack.set_transition_type (StackTransitionType.NONE);
-            stack.visible_child = (!) pre_search_view;
-            pre_search_view = null;
-
-            if (stack.get_visible_child () == browse_view)
-                browse_view.focus_selected_row ();
-        }
-        search_results_view.stop_search ();
+        current_child.hide_search_view ();
     }
 
     public void set_path (string path)
     {
-        if (path.has_suffix ("/"))
-            stack.set_visible_child (browse_view);
-        else
-            stack.set_visible_child (properties_view);
-
+        current_child.set_path (path);
         modifications_handler.path_changed ();
     }
 
-    public string? get_copy_text ()
-    {
-        return ((BrowsableView) stack.get_visible_child ()).get_copy_text ();
-    }
-
-    public string? get_copy_path_text ()
-    {
-        if (current_view_is_search_results_view ())
-            return search_results_view.get_copy_path_text ();
-
-        warning ("BrowserView get_copy_path_text() called but current view is not search results view.");
-        return null;
-    }
-
-    public bool show_row_popover ()
-    {
-        if (current_view_is_browse_view ())
-            return browse_view.show_row_popover ();
-        if (current_view_is_search_results_view ())
-            return search_results_view.show_row_popover ();
-        return false;
-    }
-
-    public void toggle_boolean_key ()
-    {
-        if (current_view_is_browse_view ())
-            browse_view.toggle_boolean_key ();
-        else if (current_view_is_search_results_view ())
-            search_results_view.toggle_boolean_key ();
-    }
-
-    public void set_selected_to_default ()
-    {
-        if (current_view_is_browse_view ())
-            browse_view.set_selected_to_default ();
-        else if (current_view_is_search_results_view ())
-            search_results_view.set_selected_to_default ();
-    }
-
-    public void discard_row_popover ()
-    {
-        if (current_view_is_browse_view ())
-            browse_view.discard_row_popover ();
-        else if (current_view_is_search_results_view ())
-            search_results_view.discard_row_popover ();
-    }
-
-    public void invalidate_popovers ()
-    {
-        browse_view.invalidate_popovers ();
-        search_results_view.invalidate_popovers ();
-    }
-
-    public bool current_view_is_browse_view ()
-    {
-        return stack.get_visible_child () == browse_view;
-    }
-
-    public bool current_view_is_properties_view ()
-    {
-        return stack.get_visible_child () == properties_view;
-    }
-
-    public bool current_view_is_search_results_view ()
-    {
-        return stack.get_visible_child () == search_results_view;
-    }
-
     /*\
     * * Reload
     \*/
@@ -337,7 +214,7 @@ class BrowserView : Grid
     public void reload_search (string current_path, string [] bookmarks)
     {
         hide_reload_warning ();
-        search_results_view.reload_search (current_path, bookmarks, sorting_options);
+        current_child.reload_search (current_path, bookmarks, sorting_options);
     }
 
     public bool check_reload (string path, bool show_infobar)
@@ -347,13 +224,13 @@ class BrowserView : Grid
         if (current_view_is_browse_view ())
         {
             GLib.ListStore? fresh_key_model = model.get_children (path);
-            if (fresh_key_model != null && !browse_view.check_reload ((!) fresh_key_model))
+            if (fresh_key_model != null && !current_child.check_reload_folder ((!) fresh_key_model))
                 return false;
         }
         else if (current_view_is_properties_view ())
         {
             Variant? properties = model.get_key_properties (path, last_context);
-            if (properties != null && !properties_view.check_reload ((!) properties))
+            if (properties != null && !current_child.check_reload_object ((!) properties))
                 return false;
         }
 
@@ -366,39 +243,32 @@ class BrowserView : Grid
     }
 
     /*\
-    * * Keyboard calls
+    * * Proxy calls
     \*/
 
-    public bool return_pressed ()
-    {
-        if (!current_view_is_search_results_view ())
-            assert_not_reached ();
+    // popovers invalidation
+    public void discard_row_popover () { current_child.discard_row_popover (); }
+    public void invalidate_popovers () { current_child.invalidate_popovers (); }
 
-        return search_results_view.return_pressed ();
-    }
+    // questionning view
+    public bool current_view_is_browse_view ()         { return current_child.current_view_is_browse_view 
();         }
+    public bool current_view_is_properties_view ()     { return 
current_child.current_view_is_properties_view ();     }
+    public bool current_view_is_search_results_view () { return 
current_child.current_view_is_search_results_view (); }
 
-    public bool up_pressed ()
-    {
-        if (current_view_is_browse_view ())
-            return browse_view.up_or_down_pressed (false);
-        else if (current_view_is_search_results_view ())
-            return search_results_view.up_or_down_pressed (false);
-        return false;
-    }
+    // keyboard
+    public bool return_pressed ()   { return current_child.return_pressed ();   }
+    public bool up_pressed ()       { return current_child.up_pressed ();       }
+    public bool down_pressed ()     { return current_child.down_pressed ();     }
 
-    public bool down_pressed ()
-    {
-        if (current_view_is_browse_view ())
-            return browse_view.up_or_down_pressed (true);
-        else if (current_view_is_search_results_view ())
-            return search_results_view.up_or_down_pressed (true);
-        return false;
-    }
-}
+    public bool show_row_popover () { return current_child.show_row_popover (); }   // Menu
 
-public interface BrowsableView
-{
-    public abstract string? get_copy_text ();
+    public void toggle_boolean_key ()      { current_child.toggle_boolean_key ();      }
+    public void set_selected_to_default () { current_child.set_selected_to_default (); }
+
+    // current row property
+    public string get_selected_row_name () { return current_child.get_selected_row_name (); }
+    public string? get_copy_text ()        { return current_child.get_copy_text ();         }
+    public string? get_copy_path_text ()   { return current_child.get_copy_path_text ();    }
 }
 
 /*\
diff --git a/editor/dconf-editor.gresource.xml b/editor/dconf-editor.gresource.xml
index 3eed610..ba52b3e 100644
--- a/editor/dconf-editor.gresource.xml
+++ b/editor/dconf-editor.gresource.xml
@@ -4,6 +4,7 @@
     <file preprocess="xml-stripblanks">bookmark.ui</file>
     <file preprocess="xml-stripblanks">bookmarks.ui</file>
     <file preprocess="xml-stripblanks">browser-infobar.ui</file>
+    <file preprocess="xml-stripblanks">browser-stack.ui</file>
     <file preprocess="xml-stripblanks">browser-view.ui</file>
     <file>dconf-editor.css</file>
     <file preprocess="xml-stripblanks">dconf-editor.ui</file>
diff --git a/editor/meson.build b/editor/meson.build
index 838dcfe..3f44647 100644
--- a/editor/meson.build
+++ b/editor/meson.build
@@ -68,6 +68,7 @@ install_data(
 sources = files(
   'bookmarks.vala',
   'browser-infobar.vala',
+  'browser-stack.vala',
   'browser-view.vala',
   'dconf-editor.vala',
   'dconf-model.vala',
@@ -91,6 +92,7 @@ resource_data = files(
   'bookmarks.ui',
   'bookmark.ui',
   'browser-infobar.ui',
+  'browser-stack.ui',
   'browser-view.ui',
   'dconf-editor.css',
   'dconf-editor-menu.ui',


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