[dconf-editor] Introduce RegistryList.



commit 1c671e2174fcb73623e2e7e373ce42b0692aea88
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Fri Feb 9 00:10:05 2018 +0100

    Introduce RegistryList.

 editor/dconf-editor.gresource.xml |    1 -
 editor/meson.build                |    1 -
 editor/registry-placeholder.vala  |    3 +-
 editor/registry-search.ui         |   31 ------
 editor/registry-search.vala       |  136 +-------------------------
 editor/registry-view.ui           |    5 +-
 editor/registry-view.vala         |  194 +++++++++++++++++++------------------
 po/POTFILES.in                    |    2 -
 8 files changed, 105 insertions(+), 268 deletions(-)
---
diff --git a/editor/dconf-editor.gresource.xml b/editor/dconf-editor.gresource.xml
index 231c671..3eed610 100644
--- a/editor/dconf-editor.gresource.xml
+++ b/editor/dconf-editor.gresource.xml
@@ -16,7 +16,6 @@
     <file preprocess="xml-stripblanks">property-row.ui</file>
     <file preprocess="xml-stripblanks">registry-info.ui</file>
     <file preprocess="xml-stripblanks">registry-placeholder.ui</file>
-    <file preprocess="xml-stripblanks">registry-search.ui</file>
     <file preprocess="xml-stripblanks">registry-view.ui</file>
   </gresource>
   <gresource prefix="/ca/desrt/dconf-editor/gtk">
diff --git a/editor/meson.build b/editor/meson.build
index 59f9aaa..838dcfe 100644
--- a/editor/meson.build
+++ b/editor/meson.build
@@ -105,7 +105,6 @@ resource_data = files(
   'property-row.ui',
   'registry-info.ui',
   'registry-placeholder.ui',
-  'registry-search.ui',
   'registry-view.ui'
 )
 
diff --git a/editor/registry-placeholder.vala b/editor/registry-placeholder.vala
index b6a9f29..4139a83 100644
--- a/editor/registry-placeholder.vala
+++ b/editor/registry-placeholder.vala
@@ -23,7 +23,7 @@ class RegistryPlaceholder : Grid
     [GtkChild] private Label placeholder_label;
     [GtkChild] private Image placeholder_image;
 
-    public string label { private get; construct; }
+    public string label { construct set { placeholder_label.label = value; }}
     public string icon_name { private get; construct; }
     public bool big { private get; construct; default = false; }
 
@@ -37,7 +37,6 @@ class RegistryPlaceholder : Grid
         else
             placeholder_image.pixel_size = 36;
 
-        placeholder_label.label = label;
         placeholder_image.icon_name = icon_name;
     }
 }
diff --git a/editor/registry-search.vala b/editor/registry-search.vala
index cfa836c..1b7d03e 100644
--- a/editor/registry-search.vala
+++ b/editor/registry-search.vala
@@ -17,82 +17,23 @@
 
 using Gtk;
 
-[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/registry-search.ui")]
-class RegistrySearch : Grid, BrowsableView
+class RegistrySearch : RegistryList
 {
     private string current_path;
 
-    [GtkChild] private ScrolledWindow scrolled;
-
-    [GtkChild] private ListBox key_list_box;
-
-    private GLib.ListStore rows_possibly_with_popover = new GLib.ListStore (typeof (ClickableListBoxRow));
-
-    private bool _small_keys_list_rows;
-    public bool small_keys_list_rows
-    {
-        set
-        {
-            _small_keys_list_rows = value;
-            key_list_box.foreach ((row) => {
-                    Widget? row_child = ((ListBoxRow) row).get_child ();
-                    if (row_child != null && (!) row_child is KeyListBoxRow)
-                        ((KeyListBoxRow) (!) row_child).small_keys_list_rows = value;
-                });
-        }
-    }
-
     public ModificationsHandler modifications_handler { private get; set; }
 
     private GLib.ListStore search_results_model = new GLib.ListStore (typeof (SettingObject));
 
     construct
     {
+        placeholder.label = _("No matches");
         key_list_box.set_header_func (update_search_results_header);
     }
 
     /*\
     * * Updating
     \*/
-/*
-    public void select_row_named (string selected, bool grab_focus)
-    {
-        check_resize ();
-        ListBoxRow? row = key_list_box.get_row_at_index (get_row_position (selected));
-        if (row == null)
-            assert_not_reached ();
-        scroll_to_row ((!) row, grab_focus);
-    }
-    public void select_first_row (bool grab_focus)
-    {
-        ListBoxRow? row = key_list_box.get_row_at_index (0);
-        if (row != null)
-            scroll_to_row ((!) row, grab_focus);
-    }
-    private int get_row_position (string selected)
-        requires (key_model != null)
-    {
-        uint position = 0;
-        while (position < ((!) key_model).get_n_items ())
-        {
-            SettingObject object = (SettingObject) ((!) key_model).get_object (position);
-            if (object.full_name == selected)
-                return (int) position;
-            position++;
-        }
-        assert_not_reached ();
-    } */
-    private void scroll_to_row (ListBoxRow row, bool grab_focus)
-    {
-        key_list_box.select_row (row);
-        if (grab_focus)
-            row.grab_focus ();
-
-        Allocation list_allocation, row_allocation;
-        scrolled.get_allocation (out list_allocation);
-        row.get_allocation (out row_allocation);
-        key_list_box.get_adjustment ().set_value (row_allocation.y + (int) ((row_allocation.height - 
list_allocation.height) / 2.0));
-    }
 
     private void ensure_selection ()
     {
@@ -240,19 +181,6 @@ class RegistrySearch : Grid, BrowsableView
         return false;
     }
 
-    public void invalidate_popovers ()
-    {
-        uint position = 0;
-        ClickableListBoxRow? row = (ClickableListBoxRow?) rows_possibly_with_popover.get_item (0);
-        while (row != null)
-        {
-            ((!) row).destroy_popover ();
-            position++;
-            row = (ClickableListBoxRow?) rows_possibly_with_popover.get_item (position);
-        }
-        rows_possibly_with_popover.remove_all ();
-    }
-
     public string get_selected_row_name ()
     {
         ListBoxRow? selected_row = key_list_box.get_selected_row ();
@@ -269,33 +197,6 @@ class RegistrySearch : Grid, BrowsableView
     * * Keyboard calls
     \*/
 
-    public bool show_row_popover ()
-    {
-        ListBoxRow? selected_row = (ListBoxRow?) key_list_box.get_selected_row ();
-        if (selected_row == null)
-            return false;
-
-        ClickableListBoxRow row = (ClickableListBoxRow) ((!) selected_row).get_child ();
-
-        if (row.right_click_popover_visible ())
-            row.hide_right_click_popover ();
-        else
-        {
-            row.show_right_click_popover ();
-            rows_possibly_with_popover.append (row);
-        }
-        return true;
-    }
-
-    public string? get_copy_text ()
-    {
-        ListBoxRow? selected_row = key_list_box.get_selected_row ();
-        if (selected_row == null)
-            return null;
-        else
-            return ((ClickableListBoxRow) ((!) selected_row).get_child ()).get_text ();
-    }
-
     public string? get_copy_path_text ()
     {
         ListBoxRow? selected_row = key_list_box.get_selected_row ();
@@ -305,39 +206,6 @@ class RegistrySearch : Grid, BrowsableView
             return ((!) selected_row).get_action_target_value ().get_string ();
     }
 
-    public void toggle_boolean_key ()
-    {
-        ListBoxRow? selected_row = (ListBoxRow?) key_list_box.get_selected_row ();
-        if (selected_row == null)
-            return;
-
-        if (!(((!) selected_row).get_child () is KeyListBoxRow))
-            return;
-
-        ((KeyListBoxRow) ((!) selected_row).get_child ()).toggle_boolean_key ();
-    }
-
-    public void set_selected_to_default ()
-    {
-        ListBoxRow? selected_row = (ListBoxRow?) key_list_box.get_selected_row ();
-        if (selected_row == null)
-            return;
-
-        if (!(((!) selected_row).get_child () is KeyListBoxRow))
-            assert_not_reached ();
-
-        ((KeyListBoxRow) ((!) selected_row).get_child ()).on_delete_call ();
-    }
-
-    public void discard_row_popover ()
-    {
-        ListBoxRow? selected_row = (ListBoxRow?) key_list_box.get_selected_row ();
-        if (selected_row == null)
-            return;
-
-        ((ClickableListBoxRow) ((!) selected_row).get_child ()).destroy_popover ();
-    }
-
     /*\
     * * Search
     \*/
diff --git a/editor/registry-view.ui b/editor/registry-view.ui
index 5bb2f70..c320036 100644
--- a/editor/registry-view.ui
+++ b/editor/registry-view.ui
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface domain="dconf-editor">
   <!-- interface-requires gtk+ 3.0 -->
-  <template class="RegistryView" parent="GtkGrid">
+  <template class="RegistryList" parent="GtkGrid">
     <property name="orientation">vertical</property>
     <child>
       <object class="GtkScrolledWindow" id="scrolled">
@@ -16,8 +16,7 @@
               <class name="keys-list"/>
             </style>
             <child type="placeholder">
-              <object class="RegistryPlaceholder">
-                <property name="label" translatable="yes">No keys in this path</property>
+              <object class="RegistryPlaceholder" id="placeholder">
                 <property name="icon-name">ca.desrt.dconf-editor-symbolic</property>
                 <property name="big">True</property>
               </object>
diff --git a/editor/registry-view.vala b/editor/registry-view.vala
index c2edb72..832e752 100644
--- a/editor/registry-view.vala
+++ b/editor/registry-view.vala
@@ -18,16 +18,15 @@
 using Gtk;
 
 [GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/registry-view.ui")]
-class RegistryView : Grid, BrowsableView
+class RegistryList : Grid, BrowsableView
 {
+    [GtkChild] protected ListBox key_list_box;
+    [GtkChild] protected RegistryPlaceholder placeholder;
     [GtkChild] private ScrolledWindow scrolled;
 
-    [GtkChild] private ListBox key_list_box;
-    private GLib.ListStore? key_model = null;
-
-    private GLib.ListStore rows_possibly_with_popover = new GLib.ListStore (typeof (ClickableListBoxRow));
+    protected GLib.ListStore rows_possibly_with_popover = new GLib.ListStore (typeof (ClickableListBoxRow));
 
-    private bool _small_keys_list_rows;
+    protected bool _small_keys_list_rows;
     public bool small_keys_list_rows
     {
         set
@@ -41,10 +40,105 @@ class RegistryView : Grid, BrowsableView
         }
     }
 
+    protected void scroll_to_row (ListBoxRow row, bool grab_focus)
+    {
+        key_list_box.select_row (row);
+        if (grab_focus)
+            row.grab_focus ();
+
+        Allocation list_allocation, row_allocation;
+        scrolled.get_allocation (out list_allocation);
+        row.get_allocation (out row_allocation);
+        key_list_box.get_adjustment ().set_value (row_allocation.y + (int) ((row_allocation.height - 
list_allocation.height) / 2.0));
+    }
+
+    public void invalidate_popovers ()
+    {
+        uint position = 0;
+        ClickableListBoxRow? row = (ClickableListBoxRow?) rows_possibly_with_popover.get_item (0);
+        while (row != null)
+        {
+            ((!) row).destroy_popover ();
+            position++;
+            row = (ClickableListBoxRow?) rows_possibly_with_popover.get_item (position);
+        }
+        rows_possibly_with_popover.remove_all ();
+    }
+
+    /*\
+    * * Keyboard calls
+    \*/
+
+    public bool show_row_popover ()
+    {
+        ListBoxRow? selected_row = (ListBoxRow?) key_list_box.get_selected_row ();
+        if (selected_row == null)
+            return false;
+
+        ClickableListBoxRow row = (ClickableListBoxRow) ((!) selected_row).get_child ();
+
+        if (row.right_click_popover_visible ())
+            row.hide_right_click_popover ();
+        else
+        {
+            row.show_right_click_popover ();
+            rows_possibly_with_popover.append (row);
+        }
+        return true;
+    }
+
+    public string? get_copy_text ()
+    {
+        ListBoxRow? selected_row = key_list_box.get_selected_row ();
+        if (selected_row == null)
+            return null;
+        else
+            return ((ClickableListBoxRow) ((!) selected_row).get_child ()).get_text ();
+    }
+
+    public void toggle_boolean_key ()
+    {
+        ListBoxRow? selected_row = (ListBoxRow?) key_list_box.get_selected_row ();
+        if (selected_row == null)
+            return;
+
+        if (!(((!) selected_row).get_child () is KeyListBoxRow))
+            return;
+
+        ((KeyListBoxRow) ((!) selected_row).get_child ()).toggle_boolean_key ();
+    }
+
+    public void set_selected_to_default ()
+    {
+        ListBoxRow? selected_row = (ListBoxRow?) key_list_box.get_selected_row ();
+        if (selected_row == null)
+            return;
+
+        if (!(((!) selected_row).get_child () is KeyListBoxRow))
+            assert_not_reached ();
+
+        ((KeyListBoxRow) ((!) selected_row).get_child ()).on_delete_call ();
+    }
+
+    public void discard_row_popover ()
+    {
+        ListBoxRow? selected_row = (ListBoxRow?) key_list_box.get_selected_row ();
+        if (selected_row == null)
+            return;
+
+        ((ClickableListBoxRow) ((!) selected_row).get_child ()).destroy_popover ();
+    }
+}
+
+class RegistryView : RegistryList
+{
+    private GLib.ListStore? key_model = null;
+
     public ModificationsHandler modifications_handler { private get; set; }
 
     construct
     {
+        placeholder.label = _("No keys in this path");
         key_list_box.set_header_func (update_row_header);
     }
 
@@ -126,17 +220,6 @@ class RegistryView : Grid, BrowsableView
         }
         return 0; // selected row may have been removed
     }
-    private void scroll_to_row (ListBoxRow row, bool grab_focus)
-    {
-        key_list_box.select_row (row);
-        if (grab_focus)
-            row.grab_focus ();
-
-        Allocation list_allocation, row_allocation;
-        scrolled.get_allocation (out list_allocation);
-        row.get_allocation (out row_allocation);
-        key_list_box.get_adjustment ().set_value (row_allocation.y + (int) ((row_allocation.height - 
list_allocation.height) / 2.0));
-    }
 
     /*\
     * * Key ListBox
@@ -271,19 +354,6 @@ class RegistryView : Grid, BrowsableView
         return false;
     }
 
-    public void invalidate_popovers ()
-    {
-        uint position = 0;
-        ClickableListBoxRow? row = (ClickableListBoxRow?) rows_possibly_with_popover.get_item (0);
-        while (row != null)
-        {
-            ((!) row).destroy_popover ();
-            position++;
-            row = (ClickableListBoxRow?) rows_possibly_with_popover.get_item (position);
-        }
-        rows_possibly_with_popover.remove_all ();
-    }
-
     public string get_selected_row_name ()
     {
         ListBoxRow? selected_row = key_list_box.get_selected_row ();
@@ -295,68 +365,4 @@ class RegistryView : Grid, BrowsableView
         else
             return "";
     }
-
-    /*\
-    * * Keyboard calls
-    \*/
-
-    public bool show_row_popover ()
-    {
-        ListBoxRow? selected_row = (ListBoxRow?) key_list_box.get_selected_row ();
-        if (selected_row == null)
-            return false;
-
-        ClickableListBoxRow row = (ClickableListBoxRow) ((!) selected_row).get_child ();
-
-        if (row.right_click_popover_visible ())
-            row.hide_right_click_popover ();
-        else
-        {
-            row.show_right_click_popover ();
-            rows_possibly_with_popover.append (row);
-        }
-        return true;
-    }
-
-    public string? get_copy_text ()
-    {
-        ListBoxRow? selected_row = key_list_box.get_selected_row ();
-        if (selected_row == null)
-            return null;
-        else
-            return ((ClickableListBoxRow) ((!) selected_row).get_child ()).get_text ();
-    }
-
-    public void toggle_boolean_key ()
-    {
-        ListBoxRow? selected_row = (ListBoxRow?) key_list_box.get_selected_row ();
-        if (selected_row == null)
-            return;
-
-        if (!(((!) selected_row).get_child () is KeyListBoxRow))
-            return;
-
-        ((KeyListBoxRow) ((!) selected_row).get_child ()).toggle_boolean_key ();
-    }
-
-    public void set_selected_to_default ()
-    {
-        ListBoxRow? selected_row = (ListBoxRow?) key_list_box.get_selected_row ();
-        if (selected_row == null)
-            return;
-
-        if (!(((!) selected_row).get_child () is KeyListBoxRow))
-            assert_not_reached ();
-
-        ((KeyListBoxRow) ((!) selected_row).get_child ()).on_delete_call ();
-    }
-
-    public void discard_row_popover ()
-    {
-        ListBoxRow? selected_row = (ListBoxRow?) key_list_box.get_selected_row ();
-        if (selected_row == null)
-            return;
-
-        ((ClickableListBoxRow) ((!) selected_row).get_child ()).destroy_popover ();
-    }
 }
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 36a8c77..ee3a958 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -22,8 +22,6 @@ editor/modifications-revealer.vala
 editor/pathbar.vala
 editor/registry-info.ui
 editor/registry-info.vala
-editor/registry-search.ui
 editor/registry-search.vala
-editor/registry-view.ui
 editor/registry-view.vala
 editor/setting-object.vala


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