[dconf-editor] Do not share model with pathbar.



commit 5362f6925fd66cf15dbe0549e9014a4fcb1d33c0
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Jan 24 08:01:43 2018 +0100

    Do not share model with pathbar.
    
    This reworks simpler the grey-out of inexistent pathbar items.
    See reference commit 3a31e7e78d67bfe085077209c01a9cac2224f651.

 editor/dconf-editor.css  |   11 +++++--
 editor/dconf-model.vala  |   13 ++++++++-
 editor/dconf-window.vala |    4 +-
 editor/pathbar.vala      |   66 +++++++++++++++++++--------------------------
 4 files changed, 50 insertions(+), 44 deletions(-)
---
diff --git a/editor/dconf-editor.css b/editor/dconf-editor.css
index a79e35b..f71143e 100644
--- a/editor/dconf-editor.css
+++ b/editor/dconf-editor.css
@@ -215,9 +215,14 @@
   border-bottom-color:@theme_selected_bg_color;
 }
 
-.pathbar > button.dim-label:backdrop,
-.pathbar > label.dim-label:backdrop {
-  opacity: 1;
+/* inexistent items */
+.pathbar > label,
+.pathbar > button.inexistent > label.item {
+  color:@insensitive_fg_color;
+}
+
+.pathbar > button.inexistent:hover > label.item {
+  border-bottom-color:transparent;
 }
 
 /* search changes */
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index b73150c..5566438 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -351,8 +351,19 @@ public class SettingsModel : Object
 
     public string get_fallback_path (string path, out bool warning_multiple_schemas)
     {
-        Directory? dir = get_directory (path);
         string fallback_path = path;
+        if (is_key_path (path))
+        {
+            Key? key = get_key (path);
+            if (key != null)
+            {
+                warning_multiple_schemas = true;   // TODO meaningless
+                return path;
+            }
+            fallback_path = get_parent_path (path);
+        }
+
+        Directory? dir = get_directory (fallback_path);
         while (dir == null)
         {
             fallback_path = get_parent_path (fallback_path);
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index a8d8e9d..b6f68d6 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -147,7 +147,6 @@ class DConfWindow : ApplicationWindow
                 first_path = settings.get_string ("saved-view");
         }
 
-        pathbar.model = model;
         prepare_model ();
 
         if (first_path == null)
@@ -203,7 +202,8 @@ class DConfWindow : ApplicationWindow
                     else    // search
                         reload_search_action.set_enabled (true);
                 }
-                pathbar.set_path (current_path); // update "ghost" status
+                bool meaningless;
+                pathbar.update_ghosts (model.get_fallback_path (pathbar.complete_path, out meaningless));
             });
     }
 
diff --git a/editor/pathbar.vala b/editor/pathbar.vala
index 6ce1a82..5eaecf1 100644
--- a/editor/pathbar.vala
+++ b/editor/pathbar.vala
@@ -22,7 +22,6 @@ public class PathBar : Box
 {
     [GtkChild] private PathBarItem root_button;
 
-    public SettingsModel model { private get; set; }
     public string complete_path { get; private set; default = ""; }
 
     construct
@@ -44,7 +43,6 @@ public class PathBar : Box
         string last = split [split.length - 1];
         bool is_key_path = last != "";
 
-        PathBarItem? last_item = null;
         bool destroy_all = false;
         bool maintain_all = false;
         @foreach ((child) => {
@@ -53,21 +51,11 @@ public class PathBar : Box
                     if (destroy_all)
                         child.destroy ();
                     else
-                    {
                         complete_path += "/";
-                        if (last_item != null)
-                        {
-                            bool is_ghost = !(model.path_exists (complete_path));
-                            set_is_ghost ((!) last_item, is_ghost);
-                            last_item = null;
-                            set_is_ghost (child, is_ghost);
-                        }
-                    }
                     return;
                 }
 
                 PathBarItem item = (PathBarItem) child;
-                last_item = item;
 
                 if (maintain_all)
                 {
@@ -94,13 +82,6 @@ public class PathBar : Box
                 destroy_all = true;
             });
 
-        if (last_item != null)
-        {
-            bool is_ghost = !(model.path_exists (complete_path));
-            set_is_ghost ((!) last_item, is_ghost);
-            last_item = null;
-        }
-
         if (split.length > 0)
         {
             /* add one item per folder */
@@ -110,9 +91,8 @@ public class PathBar : Box
                 foreach (string item in split [0:split.length - 1])
                 {
                     complete_path += item + "/";
-                    bool is_ghost = !(model.path_exists (complete_path));
-                    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);
+                    add_path_bar_item (item, complete_path, true, !is_key_path && (index == split.length - 
2));
+                    add_slash_label ();
                     index++;
                 }
             }
@@ -121,8 +101,7 @@ public class PathBar : Box
             if (is_key_path)
             {
                 complete_path += last;
-                bool is_ghost = !(model.path_exists (complete_path));
-                set_is_ghost (add_path_bar_item (last, complete_path, false, true), is_ghost);
+                add_path_bar_item (last, complete_path, false, true);
             }
         }
 
@@ -137,38 +116,49 @@ public class PathBar : Box
         return index_of_last_slash == -1 ? complete_path : complete_path.slice (0, index_of_last_slash + 1);
     }
 
+    public void update_ghosts (string non_ghost_path)
+    {
+        string action_target = "";
+        @foreach ((child) => {
+                if (child is PathBarItem)
+                {
+                    PathBarItem item = (PathBarItem) child;
+                    Variant? variant = item.get_action_target_value ();
+                    if (variant == null)
+                        assert_not_reached ();
+                    action_target = ((!) variant).get_string ();
+                }
+                StyleContext context = child.get_style_context ();
+                if (non_ghost_path.has_prefix (action_target))
+                    context.remove_class ("inexistent");
+                else
+                    context.add_class ("inexistent");
+            });
+    }
+
     /*\
     * * widgets management
     \*/
 
-    private Label add_slash_label ()
+    private void add_slash_label ()
     {
-        Label slash_label = new Label ("/");
-        add (slash_label);
-        return slash_label;
+        add (new Label ("/"));
     }
 
-    private PathBarItem add_path_bar_item (string label, string complete_path, bool is_folder, bool block)
+    private void add_path_bar_item (string label, string complete_path, bool is_folder, bool block)
     {
         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);
         activate_item (path_bar_item, block);   // has to be after add()
-        return path_bar_item;
-    }
-
-    private void set_is_ghost (Widget child, bool is_ghost)
-    {
-        if (is_ghost)
-            child.get_style_context ().add_class ("dim-label");
-        else
-            child.get_style_context ().remove_class ("dim-label");
     }
 
     private void activate_item (PathBarItem item, bool state)
     {
         StyleContext context = item.get_style_context ();
+        if (state == context.has_class ("active"))
+            return;
         if (state)
         {
             item.cursor_type = PathBarItem.CursorType.CONTEXT;


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