[dconf-editor] Some cleanings.



commit ee41c7ea81fdb5bdda08a208e29b25d90910cd7c
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Tue Aug 2 19:19:17 2016 +0200

    Some cleanings.

 editor/bookmarks.vala              |    4 +-
 editor/dconf-editor.ui             |    1 +
 editor/dconf-window.vala           |   18 ++++++--
 editor/modifications-revealer.vala |    2 +-
 editor/pathbar.vala                |    4 +-
 editor/registry-info.vala          |   15 ++-----
 editor/registry-view.vala          |   73 ++++++++++++++----------------------
 7 files changed, 49 insertions(+), 68 deletions(-)
---
diff --git a/editor/bookmarks.vala b/editor/bookmarks.vala
index 733f7e8..caedd6b 100644
--- a/editor/bookmarks.vala
+++ b/editor/bookmarks.vala
@@ -18,7 +18,7 @@
 using Gtk;
 
 [GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/bookmarks.ui")]
-public class Bookmarks : MenuButton
+public class Bookmarks : MenuButton, PathElement
 {
     [GtkChild] private ListBox bookmarks_list_box;
     [GtkChild] private Popover bookmarks_popover;
@@ -37,8 +37,6 @@ public class Bookmarks : MenuButton
     public string schema_id { get; construct; }
     private GLib.Settings settings;
 
-    public signal void request_path (string bookmark);
-
     private ulong switch_active_handler = 0;
 
     construct
diff --git a/editor/dconf-editor.ui b/editor/dconf-editor.ui
index 14e82fc..b0ba940 100644
--- a/editor/dconf-editor.ui
+++ b/editor/dconf-editor.ui
@@ -112,6 +112,7 @@
         <child>
           <object class="RegistryView" id="registry_view">
             <property name="visible">True</property>
+            <signal name="request_path" handler="request_path"/>
           </object>
         </child>
         <child type="overlay">
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index cb4f310..42f6d77 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -214,16 +214,19 @@ class DConfWindow : ApplicationWindow
     [GtkCallback]
     private void request_path (string full_name)
     {
-        registry_view.set_search_mode (false);  // TODO only useful when called from pathbar
-        registry_view.request_path (full_name);
+        registry_view.set_search_mode (false);  // TODO not useful when called from bookmark
+        registry_view.path_requested (full_name);
     }
 
-    public void update_hamburger_menu ()
+    public void update_path_elements ()
     {
-        GLib.Menu section;
-
         bookmarks_button.set_path (current_path);
         pathbar.set_path (current_path);
+    }
+
+    public void update_hamburger_menu ()
+    {
+        GLib.Menu section;
 
         GLib.Menu menu = new GLib.Menu ();
         menu.append (_("Copy current path"), "app.copy(\"" + current_path.escape ("") + "\")");
@@ -385,3 +388,8 @@ class DConfWindow : ApplicationWindow
         notification_revealer.set_reveal_child (false);
     }
 }
+
+public interface PathElement
+{
+    public signal void request_path (string path);
+}
diff --git a/editor/modifications-revealer.vala b/editor/modifications-revealer.vala
index 8379a1a..1b738b7 100644
--- a/editor/modifications-revealer.vala
+++ b/editor/modifications-revealer.vala
@@ -193,7 +193,7 @@ class ModificationsRevealer : Revealer
             warning (error.message);
         }
 
-        /* reload the hamburger menu */ /* FIXME should go back to keys list if the key is erased */
+        /* reload the hamburger menu */
 
         reload ();
     }
diff --git a/editor/pathbar.vala b/editor/pathbar.vala
index 74080ac..8c31e29 100644
--- a/editor/pathbar.vala
+++ b/editor/pathbar.vala
@@ -18,12 +18,10 @@
 using Gtk;
 
 [GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/pathbar.ui")]
-public class PathBar : Box
+public class PathBar : Box, PathElement
 {
     [GtkChild] private Button root_button;
 
-    public signal void request_path (string path);
-
     construct
     {
         add_slash_label ();
diff --git a/editor/registry-info.vala b/editor/registry-info.vala
index 2608451..df6ee42 100644
--- a/editor/registry-info.vala
+++ b/editor/registry-info.vala
@@ -54,22 +54,17 @@ class RegistryInfo : Grid
     * * Populating
     \*/
 
-    public bool populate_properties_list_box (Key key)
+    public void populate_properties_list_box (Key key)
     {
+        if (key is DConfKey && ((DConfKey) key).is_ghost)   // TODO place in "requires"
+            assert_not_reached ();
         clean ();   // for when switching between two keys, for example with a search (maybe also bookmarks)
 
         bool has_schema;
         unowned Variant [] dict_container;
         key.properties.get ("(ba{ss})", out has_schema, out dict_container);
 
-        if (!has_schema)
-        {
-            if (((DConfKey) key).is_ghost)
-                return false;
-            no_schema_warning.set_reveal_child (true);
-        }
-        else
-            no_schema_warning.set_reveal_child (false);
+        no_schema_warning.set_reveal_child (!has_schema);
 
         properties_list_box.@foreach ((widget) => widget.destroy ());
 
@@ -199,8 +194,6 @@ class RegistryInfo : Grid
                 key_editor_child.disconnect (value_has_changed_handler);
                 key_editor_child.disconnect (child_activated_handler);
             });
-
-        return true;
     }
 
     private static KeyEditorChild create_child (Key key)
diff --git a/editor/registry-view.vala b/editor/registry-view.vala
index 8183a97..b5f3152 100644
--- a/editor/registry-view.vala
+++ b/editor/registry-view.vala
@@ -18,7 +18,7 @@
 using Gtk;
 
 [GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/registry-view.ui")]
-class RegistryView : Grid
+class RegistryView : Grid, PathElement
 {
     public string current_path { get; private set; }
     public bool show_search_bar { get; set; }
@@ -65,13 +65,8 @@ class RegistryView : Grid
         dir_tree_view.set_model (model);
         dir_tree_view.expand_all ();
 
-        current_path = path;
-        if (!restore_view || current_path == "" || path [0] != '/' || !scroll_to_path (current_path))
-        {
-            current_path = "/";
-            if (!scroll_to_path ("/"))
-                assert_not_reached ();
-        }
+        current_path = (restore_view && path != "" && path [0] == '/') ? path : "/";
+        path_requested (current_path);
     }
 
     /*\
@@ -97,6 +92,7 @@ class RegistryView : Grid
     {
         revealer.path_changed ();
         current_path = path;
+        get_dconf_window ().update_path_elements ();
         invalidate_popovers ();
     }
 
@@ -121,13 +117,7 @@ class RegistryView : Grid
             return model.get_root_directory ();
     }
 
-    public void request_path (string path)
-    {
-        if (!scroll_to_path (path))
-            assert_not_reached ();
-    }
-
-    private bool scroll_to_path (string _full_name)     // TODO don't do all the selection work if the 
folder didn't change; clarify what "return true" means
+    public void path_requested (string _full_name)     // TODO don't do all the selection work if the folder 
didn't change
     {
         string full_name = _full_name.dup ();
         string folder_name;
@@ -139,13 +129,15 @@ class RegistryView : Grid
         if (!select_folder (folder_name))
         {
             get_dconf_window ().show_notification (_("Cannot find folder \"%s\".").printf (folder_name));
-            return false;
+            current_path = "/";
+            show_browse_view ("/");
+            return;
         }
 
         if (full_name == folder_name)
         {
             show_browse_view (full_name);
-            return true;
+            return;
         }
 
         string [] names = full_name.split ("/");
@@ -155,17 +147,18 @@ class RegistryView : Grid
         {
             show_browse_view (folder_name);
             get_dconf_window ().show_notification (_("Cannot find key \"%s\" here.").printf (key_name));
-            return true;
+            return;
         }
-        if (!properties_view.populate_properties_list_box ((!) key))
+        if (((!) key) is DConfKey && ((DConfKey) ((!) key)).is_ghost)
         {
             show_browse_view (folder_name);
             get_dconf_window ().show_notification (_("Key \"%s\" has been removed.").printf (key_name));
-            return true;
+            return;
         }
 
+        properties_view.populate_properties_list_box ((!) key);
         show_properties_view (full_name);
-        return true;
+        return;
     }
     private bool select_folder (string full_name)
     {
@@ -217,25 +210,19 @@ class RegistryView : Grid
     private Widget new_list_box_row (Object item)
     {
         ClickableListBoxRow row;
-        ulong on_row_clicked_handler;
-        if (item is Directory)
-        {
-            SettingObject setting_object = (SettingObject) item;
+        SettingObject setting_object = (SettingObject) item;
+
+        if (setting_object is Directory)
             row = new FolderListBoxRow (setting_object.name, setting_object.full_name);
-            on_row_clicked_handler = row.on_row_clicked.connect (() => {
-                    if (!scroll_to_path (setting_object.full_name))
-                        warning ("Something got wrong with this folder.");
-                });
-        }
         else
         {
-            if (item is GSettingsKey)
-                row = new KeyListBoxRowEditable ((GSettingsKey) item);
+            if (setting_object is GSettingsKey)
+                row = new KeyListBoxRowEditable ((GSettingsKey) setting_object);
             else
-                row = new KeyListBoxRowEditableNoSchema ((DConfKey) item);
+                row = new KeyListBoxRowEditableNoSchema ((DConfKey) setting_object);
 
-            Key key = (Key) item;
-            KeyListBoxRow key_row = ((KeyListBoxRow) row);
+            Key key = (Key) setting_object;
+            KeyListBoxRow key_row = (KeyListBoxRow) row;
             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));
 
@@ -243,21 +230,16 @@ class RegistryView : Grid
             ulong key_planned_value_handler = key.notify ["planned-value"].connect (() => set_delayed_icon 
(row, key));
             set_delayed_icon (row, key);
 
-            on_row_clicked_handler = row.on_row_clicked.connect (() => {
-                    if (!properties_view.populate_properties_list_box (key))  // TODO unduplicate
-                        return;
-
-                    show_properties_view (key.full_name);
-                });
-            // TODO bug: row is always visually activated after the dialog destruction if mouse is over at 
this time
-
             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);
                 });
+            // TODO bug: row is always visually activated after the dialog destruction if mouse is over at 
this time
         }
+
+        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 (() => {
@@ -493,8 +475,9 @@ class RegistryView : Grid
                 else if (object is Key)
                 {
                     Key key = (Key) object;
-                    if ((key is GSettingsKey || !((DConfKey) key).is_ghost) && key_matches (key, 
search_entry.text) && properties_view.populate_properties_list_box (key))
-                    {
+                    if ((key is GSettingsKey || !((DConfKey) key).is_ghost) && key_matches (key, 
search_entry.text))
+                    {   // TODO use request_path (object.full_name); problem with hiding or not the pathbar
+                        properties_view.populate_properties_list_box (key);
                         dir_tree_selection.select_iter (iter);
                         key_list_box.select_row (key_list_box.get_row_at_index (position));
                         show_properties_view (object.full_name);


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