[dconf-editor] Rework how path is updated.



commit f41c7f40ae1ce69a1496615500f51203475c3778
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sun Jan 14 10:30:27 2018 +0100

    Rework how path is updated.

 editor/bookmark.ui           |    1 -
 editor/bookmarks.vala        |    4 ++
 editor/browser-view.vala     |    8 ++--
 editor/dconf-editor.vala     |    1 +
 editor/dconf-model.vala      |   21 ++++++--
 editor/dconf-window.vala     |  106 +++++++++++++++++++++++++++++------------
 editor/key-list-box-row.vala |   18 ++++----
 editor/pathbar-item.ui       |    1 -
 editor/pathbar.ui            |    3 +-
 editor/pathbar.vala          |   20 ++++----
 editor/registry-search.vala  |   12 +++--
 editor/registry-view.vala    |   12 +++--
 12 files changed, 138 insertions(+), 69 deletions(-)
---
diff --git a/editor/bookmark.ui b/editor/bookmark.ui
index 180993c..5e4c1f6 100644
--- a/editor/bookmark.ui
+++ b/editor/bookmark.ui
@@ -2,7 +2,6 @@
 <interface domain="dconf-editor">
   <!-- interface-requires gtk+ 3.0 -->
   <template class="Bookmark" parent="GtkListBoxRow">
-    <property name="action-name">ui.open-path</property>
     <child>
       <object class="GtkGrid">
         <property name="visible">True</property>
diff --git a/editor/bookmarks.vala b/editor/bookmarks.vala
index e014b14..40f7466 100644
--- a/editor/bookmarks.vala
+++ b/editor/bookmarks.vala
@@ -94,6 +94,10 @@ public class Bookmarks : MenuButton
             unduplicated_bookmarks += bookmark;
 
             Bookmark bookmark_row = new Bookmark (bookmark);
+            if (SettingsModel.is_key_path (bookmark))
+                bookmark_row.action_name = "ui.open-object";
+            else
+                bookmark_row.action_name = "ui.open-folder";
             bookmark_row.action_target = bookmark;
             ulong destroy_button_clicked_handler = bookmark_row.destroy_button.clicked.connect (() => 
remove_bookmark (bookmark));
             bookmark_row.destroy_button.destroy.connect (() => bookmark_row.destroy_button.disconnect 
(destroy_button_clicked_handler));
diff --git a/editor/browser-view.vala b/editor/browser-view.vala
index 8695127..54cc935 100644
--- a/editor/browser-view.vala
+++ b/editor/browser-view.vala
@@ -68,13 +68,13 @@ class BrowserView : Grid
             });
     }
 
-    public string? get_selected_row_name ()
+    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 null;
+        return "";
     }
 
     public void prepare_browse_view (GLib.ListStore key_model, bool is_ancestor, bool 
warning_multiple_schemas)
@@ -88,10 +88,10 @@ class BrowserView : Grid
         browse_view.show_multiple_schemas_warning (warning_multiple_schemas);
     }
 
-    public void select_row (string? selected)
+    public void select_row (string selected)
     {
         bool grab_focus = true;     // unused, for now
-        if (selected != null)
+        if (selected != "")
             browse_view.select_row_named ((!) selected, grab_focus);
         else
             browse_view.select_first_row (grab_focus);
diff --git a/editor/dconf-editor.vala b/editor/dconf-editor.vala
index 0aae02e..812bc4a 100644
--- a/editor/dconf-editor.vala
+++ b/editor/dconf-editor.vala
@@ -250,6 +250,7 @@ class ConfigurationEditor : Gtk.Application
         Gtk.Window.set_default_icon_name ("ca.desrt.dconf-editor");
 
         add_action_entries (action_entries, this);
+//        set_accels_for_action ("win.", { "<Primary><Shift>x" });
 
         Gtk.CssProvider css_provider = new Gtk.CssProvider ();
         css_provider.load_from_resource ("/ca/desrt/dconf-editor/ui/dconf-editor.css");
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index d6186f2..aa7f48d 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -819,12 +819,23 @@ public class SettingsModel : Object
     {
         if (!is_key_path (path))
             return get_directory (path);
+        else if (strict)
+            return get_key (path);
+        else
+        {
+            GLib.ListStore? key_model = get_children (get_directory (get_parent_path (path)));
+            string name = get_name (path);
+            SettingObject? key = get_key_from_path_and_name (key_model, name);
+            if (key != null || strict)
+                return key;
+            return get_folder_from_path_and_name (key_model, name);
+        }
+    }
+
+    public Key? get_key (string path)
+    {
         GLib.ListStore? key_model = get_children (get_directory (get_parent_path (path)));
-        string name = get_name (path);
-        SettingObject? key = get_key_from_path_and_name (key_model, name);
-        if (key != null || strict)
-            return key;
-        return get_folder_from_path_and_name (key_model, name);
+        return get_key_from_path_and_name (key_model, get_name (path));
     }
 
     public static string[] to_segments (string path)
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 61cc97c..aa557ec 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -145,7 +145,11 @@ class DConfWindow : ApplicationWindow
         if (first_path == null)
             first_path = "/";
 
-        request_path ((!) first_path, true, strict);
+        SettingObject? found_object = model.get_object ((!) first_path, false);
+        if (found_object == null || (!) found_object is Key)
+            request_object_path ((!) first_path);
+        else
+            request_folder_path (((!) found_object).full_name);
     }
 
     private void prepare_model ()
@@ -342,8 +346,9 @@ class DConfWindow : ApplicationWindow
 
     private const GLib.ActionEntry [] action_entries =
     {
-        { "open-path", open_path, "s" },
-        { "open-path-with-selection", open_path_with_selection, "(ss)" },
+        { "open-folder", open_folder, "s" },
+        { "open-object", open_object, "s" },
+        { "open-parent", open_parent, "s" },
         { "reload", reload },
 
         { "reset-recursive", reset_recursively, "s" },
@@ -351,22 +356,29 @@ class DConfWindow : ApplicationWindow
         { "enter-delay-mode", enter_delay_mode }
     };
 
-    private void open_path (SimpleAction action, Variant? path_variant)
+    private void open_folder (SimpleAction action, Variant? path_variant)
+        requires (path_variant != null)
+    {
+        if (bookmarks_button.active)
+            bookmarks_button.active = false;
+        string full_name = ((!) path_variant).get_string ();
+        request_folder_path (full_name);
+    }
+
+    private void open_object (SimpleAction action, Variant? path_variant)
         requires (path_variant != null)
     {
         if (bookmarks_button.active)
             bookmarks_button.active = false;
-        request_path (((!) path_variant).get_string ());
+        string full_name = ((!) path_variant).get_string ();
+        request_object_path (full_name);
     }
 
-    private void open_path_with_selection (SimpleAction action, Variant? path_variant)
+    private void open_parent (SimpleAction action, Variant? path_variant)
         requires (path_variant != null)
     {
-        string full_name;
-        string selection;
-        ((!) path_variant).@get ("(ss)", out full_name, out selection);
-        request_path (selection);   // TODO better
-        request_path (full_name);
+        string full_name = ((!) path_variant).get_string ();
+        request_folder_path (SettingsModel.get_parent_path (full_name), full_name);
     }
 
     private void reload (/* SimpleAction action, Variant? path_variant */)
@@ -402,46 +414,61 @@ class DConfWindow : ApplicationWindow
     * * Directories tree
     \*/
 
-    private void request_path (string full_name, bool notify_missing = true, bool strict = true)
+    private void request_folder_path (string full_name, string selected_or_empty = "")
     {
-        SettingObject? found_object = model.get_object (full_name, strict);
+        Directory? found_object = model.get_directory (full_name);
         bool not_found = found_object == null;
 
         string fallback_path = full_name;
         while (found_object == null)
         {
             fallback_path = SettingsModel.get_parent_path (fallback_path);
-            found_object = model.get_object (fallback_path);
+            found_object = model.get_directory (fallback_path);
         }
+        if (selected_or_empty == "")
+            set_directory ((!) found_object, pathbar.get_selected_child (fallback_path));
+        else
+            set_directory ((!) found_object, selected_or_empty);
 
-        if (found_object is Key)
+        if (not_found)
+            cannot_find_folder (full_name);
+
+        search_bar.search_mode_enabled = false; // do last to avoid flickering RegistryView before 
PropertiesView when selecting a search result
+    }
+
+    private void request_object_path (string full_name, bool notify_missing = true)
+    {
+        SettingObject? found_object = model.get_key (full_name);
+        bool not_found = found_object == null;
+        if (not_found)
+            request_folder_path (SettingsModel.get_parent_path (full_name), full_name);
+        else
         {
             Directory parent_directory = (!) model.get_directory (SettingsModel.get_parent_path (full_name));
             browser_view.prepare_properties_view ((Key) found_object, current_path == 
SettingsModel.get_parent_path (full_name), parent_directory.warning_multiple_schemas);
             update_current_path (strdup (full_name));
         }
-        else
-            set_directory ((Directory) found_object, pathbar.get_selected_child (full_name));
 
         if (not_found && notify_missing)
         {
             if (SettingsModel.is_key_path (full_name))
-                show_notification (_("Cannot find key “%s”.").printf (full_name));
+                cannot_find_key (full_name);
             else
-                show_notification (_("Cannot find folder “%s”.").printf (full_name));
+                cannot_find_folder (full_name);
         }
 
         search_bar.search_mode_enabled = false; // do last to avoid flickering RegistryView before 
PropertiesView when selecting a search result
     }
 
-    private void set_directory (Directory directory, string? selected)
+    private void set_directory (Directory directory, string selected_or_empty)
     {
         GLib.ListStore? key_model = model.get_children (directory);
         if (key_model == null)
             return;
         browser_view.prepare_browse_view ((!) key_model, current_path.has_prefix (directory.full_name), 
directory.warning_multiple_schemas);
         update_current_path (directory.full_name);
-        browser_view.select_row (selected);
+
+        browser_view.select_row (selected_or_empty);
     }
 
     private void reload_view (bool notify_missing)
@@ -450,15 +477,15 @@ class DConfWindow : ApplicationWindow
         {
             Directory? directory = model.get_directory (current_path);
             if (directory == null)
-                request_path (current_path, notify_missing); // rely on fallback detection
+                request_folder_path (current_path); // rely on fallback detection
             else
             {
-                string? saved_selection = browser_view.get_selected_row_name ();
+                string saved_selection = browser_view.get_selected_row_name ();
                 set_directory ((!) directory, saved_selection);
             }
         }
         else if (browser_view.current_view_is_properties_view ())
-            request_path (current_path, notify_missing);
+            request_object_path (current_path, notify_missing);
         else if (browser_view.current_view_is_search_results_view ())
             browser_view.reload_search (current_path, settings.get_strv ("bookmarks"));
     }
@@ -747,37 +774,54 @@ class DConfWindow : ApplicationWindow
         if (current_path == "/")
             return;
         if (shift)
-            request_path ("/");
+            request_folder_path ("/");
         else
-            request_path (SettingsModel.get_parent_path (current_path));
+            request_folder_path (SettingsModel.get_parent_path (current_path), current_path.dup ());
     }
     private void go_forward (bool shift)
     {
         string complete_path = pathbar.complete_path;
 
         browser_view.discard_row_popover ();
+        if (current_path == complete_path)
+            return;
+
         if (shift)
         {
-            request_path (complete_path);
+            if (SettingsModel.is_key_path (complete_path))
+                request_object_path (complete_path);
+            else
+                request_folder_path (complete_path);
             return;
         }
-        if (current_path == complete_path)
-            return;
 
         int index_of_last_slash = complete_path.index_of ("/", ((!) current_path).length);
-        request_path (index_of_last_slash == -1 ? complete_path : complete_path.slice (0, 
index_of_last_slash + 1));
+        if (index_of_last_slash != -1)
+            request_folder_path (complete_path.slice (0, index_of_last_slash + 1));
+        else if (SettingsModel.is_key_path (complete_path))
+            request_object_path (complete_path);
+        else
+            request_folder_path (complete_path);
     }
 
     /*\
     * * Non-existant path notifications
     \*/
-
     private void show_notification (string notification)
     {
         notification_label.set_text (notification);
         notification_revealer.set_reveal_child (true);
     }
 
+    private void cannot_find_key (string full_name)
+    {
+        show_notification (_("Cannot find key “%s”.").printf (full_name));
+    }
+    private void cannot_find_folder (string full_name)
+    {
+        show_notification (_("Cannot find folder “%s”.").printf (full_name));
+    }
+
     [GtkCallback]
     private void hide_notification ()
     {
diff --git a/editor/key-list-box-row.vala b/editor/key-list-box-row.vala
index 354bc78..8213697 100644
--- a/editor/key-list-box-row.vala
+++ b/editor/key-list-box-row.vala
@@ -183,13 +183,13 @@ private class FolderListBoxRow : ClickableListBoxRow
 
         if (search_result_mode)
         {
-            variant = new Variant ("(ss)", parent_path, full_name);
-            popover.new_gaction ("open_parent", "ui.open-path-with-selection(" + variant.print (false) + 
")");
+            variant = new Variant.string (full_name);
+            popover.new_gaction ("open_parent", "ui.open-parent(" + variant.print (false) + ")");
             popover.new_section ();
         }
 
         variant = new Variant.string (full_name);
-        popover.new_gaction ("open", "ui.open-path(" + variant.print (false) + ")");
+        popover.new_gaction ("open", "ui.open-folder(" + variant.print (false) + ")");
         popover.new_copy_action (get_text ());
 
         popover.new_section ();
@@ -357,13 +357,13 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
 
         if (search_result_mode)
         {
-            variant = new Variant ("(ss)", key.parent_path, key.full_name);
-            popover.new_gaction ("open_parent", "ui.open-path-with-selection(" + variant.print (false) + 
")");
+            variant = new Variant.string (key.full_name);
+            popover.new_gaction ("open_parent", "ui.open-parent(" + variant.print (false) + ")");
             popover.new_section ();
         }
 
         variant = new Variant.string (key.full_name);
-        popover.new_gaction ("customize", "ui.open-path(" + variant.print (false) + ")");
+        popover.new_gaction ("customize", "ui.open-object(" + variant.print (false) + ")");
         popover.new_copy_action (get_text ());
 
 
@@ -492,8 +492,8 @@ private class KeyListBoxRowEditable : KeyListBoxRow
 
         if (search_result_mode)
         {
-            variant = new Variant ("(ss)", key.parent_path, key.full_name);
-            popover.new_gaction ("open_parent", "ui.open-path-with-selection(" + variant.print (false) + 
")");
+            variant = new Variant.string (key.full_name);
+            popover.new_gaction ("open_parent", "ui.open-parent(" + variant.print (false) + ")");
             popover.new_section ();
         }
 
@@ -502,7 +502,7 @@ private class KeyListBoxRowEditable : KeyListBoxRow
         Variant? planned_value = modifications_handler.get_key_planned_value (key);
 
         variant = new Variant.string (key.full_name);
-        popover.new_gaction ("customize", "ui.open-path(" + variant.print (false) + ")");
+        popover.new_gaction ("customize", "ui.open-object(" + variant.print (false) + ")");
         popover.new_copy_action (get_text ());
 
         if (key.type_string == "b" || key.type_string == "<enum>" || key.type_string == "mb"
diff --git a/editor/pathbar-item.ui b/editor/pathbar-item.ui
index d2fdfe2..9cee84b 100644
--- a/editor/pathbar-item.ui
+++ b/editor/pathbar-item.ui
@@ -3,7 +3,6 @@
   <!-- interface-requires gtk+ 3.0 -->
   <template class="PathBarItem" parent="GtkButton">
     <property name="focus-on-click">False</property>
-    <property name="action-name">ui.open-path</property>
     <signal name="clicked" handler="update_cursor"/>
     <child>
       <object class="GtkLabel" id="text_label">
diff --git a/editor/pathbar.ui b/editor/pathbar.ui
index ea214f0..0616aa2 100644
--- a/editor/pathbar.ui
+++ b/editor/pathbar.ui
@@ -9,7 +9,8 @@
     <child>
       <object class="PathBarItem" id="root_button">
         <property name="visible">True</property>
-        <property name="action-name">ui.open-path</property>
+        <property name="action-name">ui.open-folder</property>
+        <property name="default-action">ui.open-folder</property>
         <property name="action-target">'/'</property>
         <style>
           <class name="root-button"/>
diff --git a/editor/pathbar.vala b/editor/pathbar.vala
index e4681ff..15a77a2 100644
--- a/editor/pathbar.vala
+++ b/editor/pathbar.vala
@@ -111,7 +111,7 @@ public class PathBar : Box
                 {
                     complete_path += item + "/";
                     bool is_ghost = model.get_directory (complete_path) == null;
-                    set_is_ghost (add_path_bar_item (item, complete_path, !is_key_path && (index == 
split.length - 2)), is_ghost);
+                    set_is_ghost (add_path_bar_item (item, complete_path, true, !is_key_path && (index == 
split.length - 2)), is_ghost);
                     set_is_ghost (add_slash_label (), is_ghost);
                     index++;
                 }
@@ -122,17 +122,17 @@ public class PathBar : Box
             {
                 complete_path += last;
                 bool is_ghost = !(model.get_object (complete_path) is Key);
-                set_is_ghost (add_path_bar_item (last, complete_path, true), is_ghost);
+                set_is_ghost (add_path_bar_item (last, complete_path, false, true), is_ghost);
             }
         }
 
         show_all ();
     }
 
-    public string? get_selected_child (string current_path)
+    public string get_selected_child (string current_path)
     {
         if (!complete_path.has_prefix (current_path) || complete_path == current_path)
-            return null;
+            return "";
         int index_of_last_slash = complete_path.index_of ("/", current_path.length);
         return index_of_last_slash == -1 ? complete_path : complete_path.slice (0, index_of_last_slash + 1);
     }
@@ -148,9 +148,9 @@ public class PathBar : Box
         return slash_label;
     }
 
-    private PathBarItem add_path_bar_item (string label, string complete_path, bool block)
+    private PathBarItem add_path_bar_item (string label, string complete_path, bool is_folder, bool block)
     {
-        PathBarItem path_bar_item = new PathBarItem (label);
+        PathBarItem path_bar_item = new PathBarItem (label, is_folder ? "ui.open-folder" : "ui.open-object");
         path_bar_item.action_target = new Variant.string (complete_path);
 
         add (path_bar_item);
@@ -179,7 +179,7 @@ public class PathBar : Box
         else
         {
             item.cursor_type = PathBarItem.CursorType.POINTER;
-            item.set_action_name ("ui.open-path");
+            item.set_action_name (item.default_action);
             context.remove_class ("active");
         }
     }
@@ -188,6 +188,7 @@ public class PathBar : Box
 [GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/pathbar-item.ui")]
 private class PathBarItem : Button
 {
+    public string default_action { get; construct; }
     public string text_string { get; construct; }
     [GtkChild] private Label text_label;
 
@@ -235,9 +236,10 @@ private class PathBarItem : Button
         popover_test.popup ();
     }
 
-    public PathBarItem (string label)
+    public PathBarItem (string label, string action)
     {
-        Object (text_string: label);
+        Object (text_string: label, default_action: action);
         text_label.set_text (label);
+        set_action_name (action);
     }
 }
diff --git a/editor/registry-search.vala b/editor/registry-search.vala
index 1eb3fac..dc93b7f 100644
--- a/editor/registry-search.vala
+++ b/editor/registry-search.vala
@@ -168,11 +168,15 @@ class RegistrySearch : Grid, BrowsableView
         wrapper.set_halign (Align.CENTER);
         wrapper.add (row);
         if (row is FolderListBoxRow)
+        {
             wrapper.get_style_context ().add_class ("folder-row");
+            wrapper.action_name = "ui.open-folder";
+        }
         else
+        {
             wrapper.get_style_context ().add_class ("key-row");
-
-        wrapper.action_name = "ui.open-path";
+            wrapper.action_name = "ui.open-object";
+        }
         wrapper.action_target = setting_object.full_name;
 
         return wrapper;
@@ -266,7 +270,7 @@ class RegistrySearch : Grid, BrowsableView
         rows_possibly_with_popover.remove_all ();
     }
 
-    public string? get_selected_row_name ()
+    public string get_selected_row_name ()
     {
         ListBoxRow? selected_row = key_list_box.get_selected_row ();
         if (selected_row != null)
@@ -275,7 +279,7 @@ class RegistrySearch : Grid, BrowsableView
             return ((SettingObject) ((!) search_results_model).get_object (position)).full_name;
         }
         else
-            return null;
+            return "";
     }
 
     /*\
diff --git a/editor/registry-view.vala b/editor/registry-view.vala
index b5a54b1..fbd6d60 100644
--- a/editor/registry-view.vala
+++ b/editor/registry-view.vala
@@ -208,11 +208,15 @@ class RegistryView : Grid, BrowsableView
         wrapper.set_halign (Align.CENTER);
         wrapper.add (row);
         if (row is FolderListBoxRow)
+        {
             wrapper.get_style_context ().add_class ("folder-row");
+            wrapper.action_name = "ui.open-folder";
+        }
         else
+        {
             wrapper.get_style_context ().add_class ("key-row");
-
-        wrapper.action_name = "ui.open-path";
+            wrapper.action_name = "ui.open-object";
+        }
         wrapper.action_target = setting_object.full_name;
 
         return wrapper;
@@ -290,7 +294,7 @@ class RegistryView : Grid, BrowsableView
         rows_possibly_with_popover.remove_all ();
     }
 
-    public string? get_selected_row_name ()
+    public string get_selected_row_name ()
     {
         ListBoxRow? selected_row = key_list_box.get_selected_row ();
         if (selected_row != null)
@@ -299,7 +303,7 @@ class RegistryView : Grid, BrowsableView
             return ((SettingObject) ((!) key_model).get_object (position)).full_name;
         }
         else
-            return null;
+            return "";
     }
 
     /*\


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