[dconf-editor] Use both RegistryView and BrowserView.



commit 734a6ce8b44bf282f8430c86f88e0b421fb1dffc
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Nov 8 15:02:38 2017 +0100

    Use both RegistryView and BrowserView.

 editor/browser-view.ui             |   51 +----
 editor/browser-view.vala           |  401 ++++++++----------------------------
 editor/dconf-window.vala           |   13 --
 editor/key-list-box-row.vala       |    2 +-
 editor/modifications-revealer.vala |    2 +-
 editor/registry-info.vala          |    2 +-
 editor/registry-view.ui            |   82 ++------
 editor/registry-view.vala          |  212 ++++----------------
 8 files changed, 147 insertions(+), 618 deletions(-)
---
diff --git a/editor/browser-view.ui b/editor/browser-view.ui
index 8072297..83bea2b 100644
--- a/editor/browser-view.ui
+++ b/editor/browser-view.ui
@@ -4,31 +4,6 @@
   <template class="BrowserView" parent="GtkGrid">
     <property name="orientation">vertical</property>
     <child>
-      <object class="GtkRevealer" id="multiple_schemas_warning_revealer">
-        <property name="visible">True</property>
-        <property name="reveal-child">False</property>
-        <child>
-          <object class="GtkInfoBar">
-            <property name="visible">True</property>
-            <property name="message-type">warning</property>
-            <child internal-child="content_area">
-              <object class="GtkBox">
-                <child>
-                  <object class="GtkLabel">
-                    <property name="visible">True</property>
-                    <property name="hexpand">True</property>
-                    <property name="max-width-chars">40</property>
-                    <property name="wrap">True</property>
-                    <property name="label" translatable="yes">Multiple schemas are installed at this path. 
This could lead to problems if it hasn’t been done carefully. Only one schema is displayed here. Edit values 
at your own risk.</property>
-                  </object>
-                </child>
-              </object>
-            </child>
-          </object>
-        </child>
-      </object>
-    </child>
-    <child>
       <object class="GtkRevealer" id="need_reload_warning_revealer">
         <property name="visible">True</property>
         <property name="reveal-child">False</property>
@@ -66,29 +41,14 @@
     <child>
       <object class="GtkStack" id="stack">
         <property name="visible">True</property>
-        <property name="visible-child">browse-view</property> <!-- uses the "id" attribute -->
+        <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="GtkScrolledWindow" id="browse-view">
+          <object class="RegistryView"  id="browse_view">
             <property name="visible">True</property>
-            <child>
-              <object class="GtkListBox" id="key_list_box">
-                <property name="visible">True</property>
-                <property name="activate-on-single-click">True</property>
-                <property name="selection-mode">browse</property><!-- permits to not have an item selected 
-->
-                <style>
-                  <class name="keys-list"/>
-                </style>
-                <signal name="row-activated" handler="row_activated_cb"/>
-                <child type="placeholder">
-                  <object class="RegistryPlaceholder">
-                    <property name="visible">True</property>
-                    <property name="label" translatable="yes">No keys in this path</property>
-                  </object>
-                </child>
-              </object>
-            </child>
+            <property name="revealer">revealer</property>
+            <signal name="request_path" handler="request_path_test"/>
           </object>
           <packing>
             <property name="name">browse-view</property>
@@ -99,6 +59,9 @@
             <property name="visible">True</property>
             <property name="revealer">revealer</property>
           </object>
+          <packing>
+            <property name="name">properties-view</property>
+          </packing>
         </child>
       </object>
     </child>
diff --git a/editor/browser-view.vala b/editor/browser-view.vala
index c7888c3..fbddf58 100644
--- a/editor/browser-view.vala
+++ b/editor/browser-view.vala
@@ -17,39 +17,35 @@
 
 using Gtk;
 
+public enum Behaviour {
+    UNSAFE,
+    SAFE,
+    ALWAYS_CONFIRM_IMPLICIT,
+    ALWAYS_CONFIRM_EXPLICIT,
+    ALWAYS_DELAY
+}
+
 [GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/browser-view.ui")]
 class BrowserView : Grid, PathElement
 {
     public string current_path { get; private set; }
-    public Behaviour behaviour { get; set; }
-
-    private GLib.Settings application_settings = new GLib.Settings ("ca.desrt.dconf-editor.Settings");
-    [GtkChild] private Revealer need_reload_warning_revealer;
-    [GtkChild] private Revealer multiple_schemas_warning_revealer;
-    private bool multiple_schemas_warning_needed;
 
+    private GLib.Settings settings = new GLib.Settings ("ca.desrt.dconf-editor.Settings");
     private Directory current_directory;
 
+    [GtkChild] private Revealer need_reload_warning_revealer;
+
     [GtkChild] private Stack stack;
+    [GtkChild] private RegistryView browse_view;
     [GtkChild] private RegistryInfo properties_view;
 
-    [GtkChild] private ListBox key_list_box;
-    private GLib.ListStore? key_model = null;
     private SortingOptions sorting_options;
 
-    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 is KeyListBoxRow)
-                        ((KeyListBoxRow) row_child).small_keys_list_rows = value;
-                });
+            browse_view.small_keys_list_rows = value;
         }
     }
 
@@ -68,15 +64,21 @@ class BrowserView : Grid, PathElement
     {
         ulong revealer_reload_handler = revealer.reload.connect (invalidate_popovers);
 
-        bind_property ("behaviour", revealer, "behaviour", 
BindingFlags.BIDIRECTIONAL|BindingFlags.SYNC_CREATE);
+        ulong behaviour_changed_handler = settings.changed ["behaviour"].connect (invalidate_popovers);
+        settings.bind ("behaviour", revealer, "behaviour", 
SettingsBindFlags.GET|SettingsBindFlags.NO_SENSITIVITY);
+        settings.bind ("behaviour", browse_view, "behaviour", 
SettingsBindFlags.GET|SettingsBindFlags.NO_SENSITIVITY);
 
         sorting_options = new SortingOptions ();
-        application_settings.bind ("sort-case-sensitive", sorting_options, "case-sensitive", 
GLib.SettingsBindFlags.GET);
-        application_settings.bind ("sort-folders", sorting_options, "sort-folders", 
GLib.SettingsBindFlags.GET);
+        settings.bind ("sort-case-sensitive", sorting_options, "case-sensitive", GLib.SettingsBindFlags.GET);
+        settings.bind ("sort-folders", sorting_options, "sort-folders", GLib.SettingsBindFlags.GET);
 
-        key_list_box.set_header_func (update_row_header);
+        sorting_options.notify.connect (() => {
+                if (!is_not_browsing_view () && current_directory.need_sorting (sorting_options))
+                    need_reload_warning_revealer.set_reveal_child (true);
+            });
 
         destroy.connect (() => {
+                settings.disconnect (behaviour_changed_handler);
                 revealer.disconnect (revealer_reload_handler);
                 base.destroy ();
             });
@@ -85,78 +87,46 @@ class BrowserView : Grid, PathElement
     public void init (string path, bool restore_view)   // TODO check path format
     {
         current_path = (restore_view && path != "" && path [0] == '/') ? path : "/";
-
-        sorting_options.notify.connect (() => {
-                if (!is_not_browsing_view () && current_directory.need_sorting (sorting_options))
-                    need_reload_warning_revealer.set_reveal_child (true);
-            });
     }
 
-    /*\
-    * * Stack switching
-    \*/
+    [GtkCallback]
+    private void request_path_test (string test)
+    {
+        request_path (test);
+    }
 
     public void set_directory (Directory directory, string? selected)
     {
         current_directory = directory;
-
         current_directory.sort_key_model (sorting_options);
-        key_model = current_directory.key_model;
 
-        multiple_schemas_warning_needed = current_directory.warning_multiple_schemas;
-
-        key_list_box.bind_model (key_model, new_list_box_row);
+        browse_view.set_key_model (directory.key_model);
 
         show_browse_view (directory.full_name, selected);
+        properties_view.clean ();
     }
 
-    private void show_browse_view (string path, string? selected, bool grab_focus = true)
+    private void show_browse_view (string path, string? selected)
+    {
+        _show_browse_view (path);
+        select_row (selected);
+    }
+    private void _show_browse_view (string path)
     {
         stack.set_transition_type (current_path.has_prefix (path) ? StackTransitionType.CROSSFADE : 
StackTransitionType.NONE);
         need_reload_warning_revealer.set_reveal_child (false);
-        multiple_schemas_warning_revealer.set_reveal_child (multiple_schemas_warning_needed);
+        browse_view.show_multiple_schemas_warning (current_directory.warning_multiple_schemas);
+
         update_current_path (path);
-        current_directory.sort_key_model (sorting_options);
         stack.set_visible_child_name ("browse-view");
-        if (selected != null)
-        {
-            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);
-        }
-        else
-        {
-            ListBoxRow? row = key_list_box.get_row_at_index (0);
-            if (row != null)
-                scroll_to_row ((!) row, grab_focus);
-        }
-        properties_view.clean ();
-    }
-    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)
+    private void select_row (string? selected)
     {
-        key_list_box.select_row (row);
-        if (grab_focus)
-            row.grab_focus ();
-
-        Allocation list_allocation, row_allocation;
-        stack.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));
+        bool grab_focus = true;     // unused, for now
+        if (selected != null)
+            browse_view.select_row_named ((!) selected, grab_focus);
+        else
+            browse_view.select_first_row (grab_focus);
     }
 
     public void show_properties_view (Key key, string path, bool warning_multiple_schemas)
@@ -164,7 +134,7 @@ class BrowserView : Grid, PathElement
         properties_view.populate_properties_list_box (key, warning_multiple_schemas);
 
         need_reload_warning_revealer.set_reveal_child (false);
-        multiple_schemas_warning_revealer.set_reveal_child (false);
+        browse_view.show_multiple_schemas_warning (false);
 
         stack.set_transition_type (path.has_prefix (current_path) && current_path.length == 
path.last_index_of_char ('/') + 1 ? StackTransitionType.CROSSFADE : StackTransitionType.NONE);
         update_current_path (path);
@@ -179,187 +149,54 @@ class BrowserView : Grid, PathElement
         invalidate_popovers ();
     }
 
-    /*\
-    * * Key ListBox
-    \*/
-
-    private void update_row_header (ListBoxRow row, ListBoxRow? before)
-    {
-        if (before != null)
-        {
-            ListBoxRowHeader header = new ListBoxRowHeader ();
-            header.set_halign (Align.CENTER);
-            header.show ();
-            row.set_header (header);
-        }
-    }
-
-    private Widget new_list_box_row (Object item)
-    {
-        ClickableListBoxRow row;
-        SettingObject setting_object = (SettingObject) item;
-        ulong on_delete_call_handler;
-
-        if (setting_object is Directory)
-        {
-            row = new FolderListBoxRow (setting_object.name, setting_object.full_name);
-            on_delete_call_handler = row.on_delete_call.connect (() => reset_objects (((Directory) 
setting_object).key_model, true));
-        }
-        else
-        {
-            if (setting_object is GSettingsKey)
-                row = new KeyListBoxRowEditable ((GSettingsKey) setting_object);
-            else
-                row = new KeyListBoxRowEditableNoSchema ((DConfKey) setting_object);
-
-            Key key = (Key) setting_object;
-            KeyListBoxRow key_row = (KeyListBoxRow) row;
-            key_row.small_keys_list_rows = _small_keys_list_rows;
-
-            on_delete_call_handler = row.on_delete_call.connect (() => set_key_value (key, null));
-            ulong set_key_value_handler = key_row.set_key_value.connect ((variant) => { set_key_value (key, 
variant); set_delayed_icon (row, key); });
-            ulong change_dismissed_handler = key_row.change_dismissed.connect (() => revealer.dismiss_change 
(key));
-
-            ulong key_planned_change_handler = key.notify ["planned-change"].connect (() => set_delayed_icon 
(row, key));
-            ulong key_planned_value_handler = key.notify ["planned-value"].connect (() => set_delayed_icon 
(row, key));
-            set_delayed_icon (row, key);
-
-            row.destroy.connect (() => {
-                    key_row.disconnect (set_key_value_handler);
-                    key_row.disconnect (change_dismissed_handler);
-                    key.disconnect (key_planned_change_handler);
-                    key.disconnect (key_planned_value_handler);
-                });
-        }
-
-        ulong on_row_clicked_handler = row.on_row_clicked.connect (() => request_path 
(setting_object.full_name));
-        ulong button_press_event_handler = row.button_press_event.connect (on_button_pressed);
-
-        row.destroy.connect (() => {
-                row.disconnect (on_delete_call_handler);
-                row.disconnect (on_row_clicked_handler);
-                row.disconnect (button_press_event_handler);
-            });
-
-        /* Wrapper ensures max width for rows */
-        ListBoxRowWrapper wrapper = new ListBoxRowWrapper ();
-        wrapper.set_halign (Align.CENTER);
-        wrapper.add (row);
-        if (row is FolderListBoxRow)
-            wrapper.get_style_context ().add_class ("folder-row");
-        else
-            wrapper.get_style_context ().add_class ("key-row");
-        return wrapper;
-    }
-
-    private void set_delayed_icon (ClickableListBoxRow row, Key key)
+    public bool get_current_delay_mode ()
     {
-        if (key.planned_change)
-        {
-            StyleContext context = row.get_style_context ();
-            context.add_class ("delayed");
-            if (key is DConfKey)
-            {
-                if (key.planned_value == null)
-                    context.add_class ("erase");
-                else
-                    context.remove_class ("erase");
-            }
-        }
-        else
-            row.get_style_context ().remove_class ("delayed");
+        return revealer.get_current_delay_mode ();
     }
 
-    private bool on_button_pressed (Widget widget, Gdk.EventButton event)
+    public string? get_copy_text ()
     {
-        ListBoxRow list_box_row = (ListBoxRow) widget.get_parent ();
-        key_list_box.select_row (list_box_row);
-        list_box_row.grab_focus ();
-
-        if (event.button == Gdk.BUTTON_SECONDARY)
-        {
-            ClickableListBoxRow row = (ClickableListBoxRow) widget;
-
-            int event_x = (int) event.x;
-            if (event.window != widget.get_window ())   // boolean value switch
-            {
-                int widget_x, unused;
-                event.window.get_position (out widget_x, out unused);
-                event_x += widget_x;
-            }
-
-            row.show_right_click_popover (get_current_delay_mode (), event_x);
-            rows_possibly_with_popover.append (row);
-        }
-
-        return false;
+        return ((BrowsableView) stack.get_visible_child ()).get_copy_text ();
     }
 
-    [GtkCallback]
-    private void row_activated_cb (ListBoxRow list_box_row)
+    public bool show_row_popover ()
     {
-        ((ClickableListBoxRow) list_box_row.get_child ()).on_row_clicked ();
+        if (is_not_browsing_view ())
+            return false;
+        return browse_view.show_row_popover ();
     }
 
-    public void invalidate_popovers ()
+    public void toggle_boolean_key ()
     {
-        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 ();
-        window.update_hamburger_menu ();
+        if (is_not_browsing_view ())
+            return;                         // TODO something, probably
+        browse_view.toggle_boolean_key ();
     }
 
-    [GtkCallback]
-    private void reload ()
-        requires (!is_not_browsing_view ())
+    public void set_to_default ()
     {
-        ListBoxRow? selected_row = key_list_box.get_selected_row ();
-        string? saved_selection = null;
-        if (selected_row != null)
-        {
-            int position = ((!) selected_row).get_index ();
-            saved_selection = ((SettingObject) ((!) key_model).get_object (position)).full_name;
-        }
-
-        show_browse_view (current_path, saved_selection);
+        if (is_not_browsing_view ())
+            return;
+        browse_view.set_to_default ();
     }
 
-    /*\
-    * * Revealer stuff
-    \*/
-
-    public bool get_current_delay_mode ()
+    public void discard_row_popover ()
     {
-        return revealer.get_current_delay_mode ();
+        if (is_not_browsing_view ())
+            return;
+        browse_view.discard_row_popover ();
     }
 
-    public void enter_delay_mode ()
+    private void invalidate_popovers ()
     {
-        revealer.enter_delay_mode ();
-        invalidate_popovers ();
+        browse_view.invalidate_popovers ();
+        window.update_hamburger_menu ();
     }
 
-    private void set_key_value (Key key, Variant? new_value)
+    private bool is_not_browsing_view ()
     {
-        if (get_current_delay_mode ())
-            revealer.add_delayed_setting (key, new_value);
-        else if (new_value != null)
-            key.value = (!) new_value;
-        else if (key is GSettingsKey)
-            ((GSettingsKey) key).set_to_default ();
-        else if (behaviour != Behaviour.UNSAFE)
-        {
-            enter_delay_mode ();
-            revealer.add_delayed_setting (key, null);
-        }
-        else
-            ((DConfKey) key).erase ();
+        string? visible_child_name = stack.get_visible_child_name ();
+        return (visible_child_name == null || ((!) visible_child_name) != "browse-view");
     }
 
     /*\
@@ -368,10 +205,10 @@ class BrowserView : Grid, PathElement
 
     public void reset (bool recursively)
     {
-        reset_objects (key_model, recursively);
+        reset_objects (current_directory.key_model, recursively);
     }
 
-    private void reset_objects (GLib.ListStore? objects, bool recursively)
+    public void reset_objects (GLib.ListStore? objects, bool recursively)
     {
         enter_delay_mode ();
         reset_generic (objects, recursively);
@@ -406,90 +243,22 @@ class BrowserView : Grid, PathElement
         }
     }
 
-    /*\
-    * * Keyboard calls
-    \*/
-
-/*    public void set_search_mode (bool? mode)    // mode is never 'true'...
-    {
-        if (mode == null)
-            search_bar.set_search_mode (!search_bar.get_search_mode ());
-        else
-            search_bar.set_search_mode ((!) mode);
-    }
-
-    public bool handle_search_event (Gdk.EventKey event)
-    {
-        if (is_not_browsing_view ())
-            return false;
-
-        return search_bar.handle_event (event);
-    } */
-
-    public bool show_row_popover ()
-    {
-        ListBoxRow? selected_row = get_key_row ();
-        if (selected_row == null)
-            return false;
-
-        ClickableListBoxRow row = (ClickableListBoxRow) ((!) selected_row).get_child ();
-        row.show_right_click_popover (get_current_delay_mode ());
-        rows_possibly_with_popover.append (row);
-        return true;
-    }
-
-    public string? get_copy_text ()
-    {
-        if (is_not_browsing_view ())
-            return properties_view.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 = get_key_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_to_default ()
-    {
-        ListBoxRow? selected_row = get_key_row ();
-        if (selected_row == null)
-            return;
-
-        ((ClickableListBoxRow) ((!) selected_row).get_child ()).on_delete_call ();
-    }
-
-    public void discard_row_popover ()
+    public void enter_delay_mode ()
     {
-        ListBoxRow? selected_row = get_key_row ();
-        if (selected_row == null)
-            return;
-
-        ((ClickableListBoxRow) ((!) selected_row).get_child ()).hide_right_click_popover ();
+        revealer.enter_delay_mode ();
+        invalidate_popovers ();
     }
 
-    private bool is_not_browsing_view ()
+    [GtkCallback]
+    private void reload ()
     {
-        string? visible_child_name = stack.get_visible_child_name ();
-        return (visible_child_name == null || ((!) visible_child_name) != "browse-view");
+        string? saved_selection = browse_view.get_selected_row_name ();
+        current_directory.sort_key_model (sorting_options);    // TODO duplicate in set_directory
+        show_browse_view (current_path, saved_selection);
     }
+}
 
-    private ListBoxRow? get_key_row ()
-    {
-        if (is_not_browsing_view ())
-            return null;
-        return (ListBoxRow?) key_list_box.get_selected_row ();
-    }
+public interface BrowsableView
+{
+    public abstract string? get_copy_text ();
 }
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index b7b9309..12295fe 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -17,14 +17,6 @@
 
 using Gtk;
 
-public enum Behaviour {
-    UNSAFE,
-    SAFE,
-    ALWAYS_CONFIRM_IMPLICIT,
-    ALWAYS_CONFIRM_EXPLICIT,
-    ALWAYS_DELAY
-}
-
 [GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/dconf-editor.ui")]
 class DConfWindow : ApplicationWindow
 {
@@ -73,7 +65,6 @@ class DConfWindow : ApplicationWindow
         }
     }
 
-    private ulong behaviour_changed_handler = 0;
 /*    private ulong theme_changed_handler = 0; */
     private ulong small_keys_list_rows_handler = 0;
     private ulong small_bookmarks_rows_handler = 0;
@@ -82,8 +73,6 @@ class DConfWindow : ApplicationWindow
     {
         add_action_entries (action_entries, this);
 
-        behaviour_changed_handler = settings.changed ["behaviour"].connect 
(browser_view.invalidate_popovers);
-
         set_default_size (settings.get_int ("window-width"), settings.get_int ("window-height"));
         if (settings.get_boolean ("window-is-maximized"))
             maximize ();
@@ -123,7 +112,6 @@ class DConfWindow : ApplicationWindow
             context.add_class ("small-bookmarks-rows");
 
         browser_view.bind_property ("current-path", this, "current-path");    // TODO in UI file?
-        settings.bind ("behaviour", browser_view, "behaviour", 
SettingsBindFlags.GET|SettingsBindFlags.NO_SENSITIVITY);
 
         settings.bind ("mouse-use-extra-buttons", this, "mouse-extra-buttons", 
SettingsBindFlags.GET|SettingsBindFlags.NO_SENSITIVITY);
         settings.bind ("mouse-back-button", this, "mouse-back-button", 
SettingsBindFlags.GET|SettingsBindFlags.NO_SENSITIVITY);
@@ -249,7 +237,6 @@ class DConfWindow : ApplicationWindow
     {
         ((ConfigurationEditor) get_application ()).clean_copy_notification ();
 
-        settings.disconnect (behaviour_changed_handler);
 /*        settings.disconnect (theme_changed_handler); */
         settings.disconnect (small_keys_list_rows_handler);
         settings.disconnect (small_bookmarks_rows_handler);
diff --git a/editor/key-list-box-row.vala b/editor/key-list-box-row.vala
index 20388a2..1130681 100644
--- a/editor/key-list-box-row.vala
+++ b/editor/key-list-box-row.vala
@@ -179,7 +179,7 @@ private abstract class KeyListBoxRow : ClickableListBoxRow
         name_context = key_name_label.get_style_context ();
         value_context = key_value_label.get_style_context ();
 
-        if (abstract_key.type_string == "b")
+        if (abstract_key.type_string == "b")    // TODO not with “always delay” behaviour, nor in “delay 
mode”
         {
             boolean_switch = new Switch ();
             ((!) boolean_switch).can_focus = false;
diff --git a/editor/modifications-revealer.vala b/editor/modifications-revealer.vala
index a07cb77..a464d1e 100644
--- a/editor/modifications-revealer.vala
+++ b/editor/modifications-revealer.vala
@@ -39,7 +39,7 @@ class ModificationsRevealer : Revealer
 
     public signal void reload ();
 
-    public Behaviour behaviour { get; set; }
+    public Behaviour behaviour { private get; set; }
 
     /*\
     * * Window management callbacks
diff --git a/editor/registry-info.vala b/editor/registry-info.vala
index 1a30141..8f1a868 100644
--- a/editor/registry-info.vala
+++ b/editor/registry-info.vala
@@ -18,7 +18,7 @@
 using Gtk;
 
 [GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/registry-info.ui")]
-class RegistryInfo : Grid
+class RegistryInfo : Grid, BrowsableView
 {
     [GtkChild] private Revealer multiple_schemas_warning_revealer;
     [GtkChild] private Revealer no_schema_warning;
diff --git a/editor/registry-view.ui b/editor/registry-view.ui
index cbfd84f..ee9aba9 100644
--- a/editor/registry-view.ui
+++ b/editor/registry-view.ui
@@ -29,84 +29,28 @@
       </object>
     </child>
     <child>
-      <object class="GtkRevealer" id="need_reload_warning_revealer">
+      <object class="GtkScrolledWindow" id="scrolled">
         <property name="visible">True</property>
-        <property name="reveal-child">False</property>
-        <child>
-          <object class="GtkInfoBar">
-            <property name="visible">True</property>
-            <property name="message-type">info</property>
-            <child internal-child="content_area">
-              <object class="GtkBox">
-                <child>
-                  <object class="GtkLabel">
-                    <property name="visible">True</property>
-                    <property name="hexpand">True</property>
-                    <property name="max-width-chars">40</property>
-                    <property name="wrap">True</property>
-                    <property name="label" translatable="yes">Sort preferences have changed. Do you want to 
reload the view?</property>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkButton">
-                    <property name="visible">True</property>
-                    <property name="label" translatable="yes">Reload</property>
-                    <signal name="clicked" handler="reload"/>
-                  </object>
-                  <packing>
-                    <property name="pack-type">end</property>
-                  </packing>
-                </child>
-              </object>
-            </child>
-          </object>
-        </child>
-      </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="GtkScrolledWindow" id="browse-view">
+          <object class="GtkListBox" id="key_list_box">
             <property name="visible">True</property>
-            <child>
-              <object class="GtkListBox" id="key_list_box">
-                <property name="visible">True</property>
-                <property name="activate-on-single-click">True</property>
-                <property name="selection-mode">browse</property><!-- permits to not have an item selected 
-->
-                <style>
-                  <class name="keys-list"/>
-                </style>
-                <signal name="row-activated" handler="row_activated_cb"/>
-                <child type="placeholder">
-                  <object class="RegistryPlaceholder">
-                    <property name="label" translatable="yes">No keys in this path</property>
-                    <property name="icon-name">ca.desrt.dconf-editor-symbolic</property>
-                    <property name="big">True</property>
-                  </object>
-                </child>
+            <property name="activate-on-single-click">True</property>
+            <property name="selection-mode">browse</property><!-- permits to not have an item selected -->
+            <style>
+              <class name="keys-list"/>
+            </style>
+            <signal name="row-activated" handler="row_activated_cb"/>
+            <child type="placeholder">
+              <object class="RegistryPlaceholder">
+                <property name="label" translatable="yes">No keys in this path</property>
+                <property name="icon-name">ca.desrt.dconf-editor-symbolic</property>
+                <property name="big">True</property>
               </object>
             </child>
           </object>
-          <packing>
-            <property name="name">browse-view</property>
-          </packing>
-        </child>
-        <child>
-          <object class="RegistryInfo" id="properties_view">
-            <property name="visible">True</property>
-            <property name="revealer">revealer</property>
-          </object>
         </child>
       </object>
     </child>
-    <child>
-      <object class="ModificationsRevealer" id="revealer">
-        <property name="visible">True</property>
-      </object>
-    </child>
   </template>
 </interface>
diff --git a/editor/registry-view.vala b/editor/registry-view.vala
index e99c849..640cdd7 100644
--- a/editor/registry-view.vala
+++ b/editor/registry-view.vala
@@ -18,24 +18,16 @@
 using Gtk;
 
 [GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/registry-view.ui")]
-class RegistryView : Grid, PathElement
+class RegistryView : Grid, PathElement, BrowsableView
 {
-    public string current_path { get; private set; }
-    public Behaviour behaviour { get; set; }
+    public Behaviour behaviour { private get; set; }
 
-    private GLib.Settings application_settings = new GLib.Settings ("ca.desrt.dconf-editor.Settings");
-    [GtkChild] private Revealer need_reload_warning_revealer;
     [GtkChild] private Revealer multiple_schemas_warning_revealer;
-    private bool multiple_schemas_warning_needed;
 
-    private Directory current_directory;
-
-    [GtkChild] private Stack stack;
-    [GtkChild] private RegistryInfo properties_view;
+    [GtkChild] private ScrolledWindow scrolled;
 
     [GtkChild] private ListBox key_list_box;
     private GLib.ListStore? key_model = null;
-    private SortingOptions sorting_options;
 
     private GLib.ListStore rows_possibly_with_popover = new GLib.ListStore (typeof (ClickableListBoxRow));
 
@@ -53,86 +45,50 @@ class RegistryView : Grid, PathElement
         }
     }
 
-    [GtkChild] private ModificationsRevealer revealer;
+    public ModificationsRevealer revealer { private get; set; }
 
-    private DConfWindow? _window = null;
-    private DConfWindow window {
+    private BrowserView? _browser_view = null;
+    private BrowserView browser_view {
         get {
-            if (_window == null)
-                _window = (DConfWindow) DConfWindow._get_parent (DConfWindow._get_parent (this));
-            return (!) _window;
+            if (_browser_view == null)
+                _browser_view = (BrowserView) DConfWindow._get_parent (DConfWindow._get_parent (this));
+            return (!) _browser_view;
         }
     }
 
     construct
     {
-        ulong revealer_reload_handler = revealer.reload.connect (invalidate_popovers);
-
-        bind_property ("behaviour", revealer, "behaviour", 
BindingFlags.BIDIRECTIONAL|BindingFlags.SYNC_CREATE);
-
-        sorting_options = new SortingOptions ();
-        application_settings.bind ("sort-case-sensitive", sorting_options, "case-sensitive", 
GLib.SettingsBindFlags.GET);
-        application_settings.bind ("sort-folders", sorting_options, "sort-folders", 
GLib.SettingsBindFlags.GET);
-
         key_list_box.set_header_func (update_row_header);
-
-        destroy.connect (() => {
-                revealer.disconnect (revealer_reload_handler);
-                base.destroy ();
-            });
-    }
-
-    public void init (string path, bool restore_view)   // TODO check path format
-    {
-        current_path = (restore_view && path != "" && path [0] == '/') ? path : "/";
-
-        sorting_options.notify.connect (() => {
-                if (!is_not_browsing_view () && current_directory.need_sorting (sorting_options))
-                    need_reload_warning_revealer.set_reveal_child (true);
-            });
     }
 
     /*\
-    * * Stack switching
+    * * Updating
     \*/
 
-    public void set_directory (Directory directory, string? selected)
+    public void set_key_model (GLib.ListStore _key_model)
     {
-        current_directory = directory;
-
-        current_directory.sort_key_model (sorting_options);
-        key_model = current_directory.key_model;
-
-        multiple_schemas_warning_needed = current_directory.warning_multiple_schemas;
-
+        key_model = _key_model;
         key_list_box.bind_model (key_model, new_list_box_row);
-
-        show_browse_view (directory.full_name, selected);
     }
 
-    private void show_browse_view (string path, string? selected, bool grab_focus = true)
+    public void show_multiple_schemas_warning (bool multiple_schemas_warning_needed)
     {
-        stack.set_transition_type (current_path.has_prefix (path) ? StackTransitionType.CROSSFADE : 
StackTransitionType.NONE);
-        need_reload_warning_revealer.set_reveal_child (false);
         multiple_schemas_warning_revealer.set_reveal_child (multiple_schemas_warning_needed);
-        update_current_path (path);
-        current_directory.sort_key_model (sorting_options);
-        stack.set_visible_child_name ("browse-view");
-        if (selected != null)
-        {
-            check_resize ();
-            ListBoxRow? row = key_list_box.get_row_at_index (get_row_position ((!) selected));
-            if (row == null)
-                assert_not_reached ();
+    }
+
+    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);
-        }
-        else
-        {
-            ListBoxRow? row = key_list_box.get_row_at_index (0);
-            if (row != null)
-                scroll_to_row ((!) row, grab_focus);
-        }
-        properties_view.clean ();
     }
     private int get_row_position (string selected)
         requires (key_model != null)
@@ -154,31 +110,11 @@ class RegistryView : Grid, PathElement
             row.grab_focus ();
 
         Allocation list_allocation, row_allocation;
-        stack.get_allocation (out list_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 show_properties_view (Key key, string path, bool warning_multiple_schemas)
-    {
-        properties_view.populate_properties_list_box (key, warning_multiple_schemas);
-
-        need_reload_warning_revealer.set_reveal_child (false);
-        multiple_schemas_warning_revealer.set_reveal_child (false);
-
-        stack.set_transition_type (path.has_prefix (current_path) && current_path.length == 
path.last_index_of_char ('/') + 1 ? StackTransitionType.CROSSFADE : StackTransitionType.NONE);
-        update_current_path (path);
-        stack.set_visible_child (properties_view);
-    }
-
-    private void update_current_path (string path)
-    {
-        revealer.path_changed ();
-        current_path = path;
-        window.update_path_elements ();
-        invalidate_popovers ();
-    }
-
     /*\
     * * Key ListBox
     \*/
@@ -203,7 +139,7 @@ class RegistryView : Grid, PathElement
         if (setting_object is Directory)
         {
             row = new FolderListBoxRow (setting_object.name, setting_object.full_name);
-            on_delete_call_handler = row.on_delete_call.connect (() => reset_objects (((Directory) 
setting_object).key_model, true));
+            on_delete_call_handler = row.on_delete_call.connect (() => browser_view.reset_objects 
(((Directory) setting_object).key_model, true));
         }
         else
         {
@@ -312,22 +248,18 @@ class RegistryView : Grid, PathElement
             row = (ClickableListBoxRow?) rows_possibly_with_popover.get_item (position);
         }
         rows_possibly_with_popover.remove_all ();
-        window.update_hamburger_menu ();
     }
 
-    [GtkCallback]
-    private void reload ()
-        requires (!is_not_browsing_view ())
+    public string? get_selected_row_name ()
     {
         ListBoxRow? selected_row = key_list_box.get_selected_row ();
-        string? saved_selection = null;
         if (selected_row != null)
         {
             int position = ((!) selected_row).get_index ();
-            saved_selection = ((SettingObject) ((!) key_model).get_object (position)).full_name;
+            return ((SettingObject) ((!) key_model).get_object (position)).full_name;
         }
-
-        show_browse_view (current_path, saved_selection);
+        else
+            return null;
     }
 
     /*\
@@ -336,13 +268,7 @@ class RegistryView : Grid, PathElement
 
     public bool get_current_delay_mode ()
     {
-        return revealer.get_current_delay_mode ();
-    }
-
-    public void enter_delay_mode ()
-    {
-        revealer.enter_delay_mode ();
-        invalidate_popovers ();
+        return browser_view.get_current_delay_mode ();
     }
 
     private void set_key_value (Key key, Variant? new_value)
@@ -355,7 +281,7 @@ class RegistryView : Grid, PathElement
             ((GSettingsKey) key).set_to_default ();
         else if (behaviour != Behaviour.UNSAFE)
         {
-            enter_delay_mode ();
+            browser_view.enter_delay_mode ();
             revealer.add_delayed_setting (key, null);
         }
         else
@@ -363,50 +289,6 @@ class RegistryView : Grid, PathElement
     }
 
     /*\
-    * * Action entries
-    \*/
-
-    public void reset (bool recursively)
-    {
-        reset_objects (key_model, recursively);
-    }
-
-    private void reset_objects (GLib.ListStore? objects, bool recursively)
-    {
-        enter_delay_mode ();
-        reset_generic (objects, recursively);
-        revealer.warn_if_no_planned_changes ();
-    }
-
-    private void reset_generic (GLib.ListStore? objects, bool recursively)
-    {
-        if (objects == null)
-            return;
-
-        for (uint position = 0;; position++)
-        {
-            Object? object = ((!) objects).get_object (position);
-            if (object == null)
-                return;
-
-            SettingObject setting_object = (SettingObject) ((!) object);
-            if (setting_object is Directory)
-            {
-                if (recursively)
-                    reset_generic (((Directory) setting_object).key_model, true);
-                continue;
-            }
-            if (setting_object is DConfKey)
-            {
-                if (!((DConfKey) setting_object).is_ghost)
-                    revealer.add_delayed_setting ((Key) setting_object, null);
-            }
-            else if (!((GSettingsKey) setting_object).is_default)
-                revealer.add_delayed_setting ((Key) setting_object, null);
-        }
-    }
-
-    /*\
     * * Keyboard calls
     \*/
 
@@ -428,7 +310,7 @@ class RegistryView : Grid, PathElement
 
     public bool show_row_popover ()
     {
-        ListBoxRow? selected_row = get_key_row ();
+        ListBoxRow? selected_row = (ListBoxRow?) key_list_box.get_selected_row ();
         if (selected_row == null)
             return false;
 
@@ -440,9 +322,6 @@ class RegistryView : Grid, PathElement
 
     public string? get_copy_text ()
     {
-        if (is_not_browsing_view ())
-            return properties_view.get_copy_text ();
-
         ListBoxRow? selected_row = key_list_box.get_selected_row ();
         if (selected_row == null)
             return null;
@@ -452,7 +331,7 @@ class RegistryView : Grid, PathElement
 
     public void toggle_boolean_key ()
     {
-        ListBoxRow? selected_row = get_key_row ();
+        ListBoxRow? selected_row = (ListBoxRow?) key_list_box.get_selected_row ();
         if (selected_row == null)
             return;
 
@@ -464,7 +343,7 @@ class RegistryView : Grid, PathElement
 
     public void set_to_default ()
     {
-        ListBoxRow? selected_row = get_key_row ();
+        ListBoxRow? selected_row = (ListBoxRow?) key_list_box.get_selected_row ();
         if (selected_row == null)
             return;
 
@@ -473,23 +352,10 @@ class RegistryView : Grid, PathElement
 
     public void discard_row_popover ()
     {
-        ListBoxRow? selected_row = get_key_row ();
+        ListBoxRow? selected_row = (ListBoxRow?) key_list_box.get_selected_row ();
         if (selected_row == null)
             return;
 
         ((ClickableListBoxRow) ((!) selected_row).get_child ()).hide_right_click_popover ();
     }
-
-    private bool is_not_browsing_view ()
-    {
-        string? visible_child_name = stack.get_visible_child_name ();
-        return (visible_child_name == null || ((!) visible_child_name) != "browse-view");
-    }
-
-    private ListBoxRow? get_key_row ()
-    {
-        if (is_not_browsing_view ())
-            return null;
-        return (ListBoxRow?) key_list_box.get_selected_row ();
-    }
 }



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