[dconf-editor] Improve PathBar.



commit 00508c4f5dc2b0f755e28caa43665b0fa0d6285a
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Mon Aug 1 00:45:26 2016 +0200

    Improve PathBar.

 editor/dconf-editor.css |   22 ++++++++-----
 editor/pathbar.vala     |   78 +++++++++++++++++++++++++++++++---------------
 2 files changed, 66 insertions(+), 34 deletions(-)
---
diff --git a/editor/dconf-editor.css b/editor/dconf-editor.css
index c8e1914..95b060b 100644
--- a/editor/dconf-editor.css
+++ b/editor/dconf-editor.css
@@ -159,6 +159,7 @@ window > popover.menu {
   background-color:transparent;
 }
 
+/* underline selected label */
 .pathbar > button > .item {
   border-width:2px 0px;
   border-style:solid;
@@ -170,17 +171,22 @@ window > popover.menu {
   border-bottom-color:#8b8e8f;  /* color mostly used for backdrop things */
 }
 
-.pathbar:dir(ltr) > button:last-child > .item,
-.pathbar:dir(ltr) > button:last-child:hover > .item,
-.pathbar:dir(ltr) > button:nth-last-child(2) > .item,
-.pathbar:dir(ltr) > button:nth-last-child(2):hover > .item,
-.pathbar:dir(rtl) > button:first-child > .item,
-.pathbar:dir(rtl) > button:first-child:hover > .item,
-.pathbar:dir(rtl) > button:nth-child(2) > .item,
-.pathbar:dir(rtl) > button:nth-child(2):hover > .item {
+.pathbar:dir(ltr) > button:disabled       > .item,
+.pathbar:dir(ltr) > button:disabled:hover > .item {
   border-bottom-color: @theme_selected_bg_color;
 }
 
+/* ensure label color */
+.pathbar          > button          > .item,
+.pathbar          > button:disabled > .item {
+  color:@theme_fg_color;
+}
+
+.pathbar:backdrop > button          > .item,
+.pathbar:backdrop > button:disabled > .item {
+  color:@theme_unfocused_fg_color;
+}
+
 /*\
 * * properties list
 \*/
diff --git a/editor/pathbar.vala b/editor/pathbar.vala
index 932f6a3..e8ef9c9 100644
--- a/editor/pathbar.vala
+++ b/editor/pathbar.vala
@@ -26,7 +26,7 @@ public class PathBar : Box
 
     construct
     {
-        add (new Label ("/"));
+        add_slash_label ();
     }
 
     public void set_path_and_notify (string path)
@@ -39,43 +39,52 @@ public class PathBar : Box
     public void set_path (string path)
         requires (path [0] == '/')
     {
-        string complete_path = "/";
+        root_button.set_sensitive (path != "/");
+
+        string complete_path = "";
         string [] split = path.split ("/", /* max tokens disabled */ 0);
-        split = split [1:split.length];
+        string last = split [split.length - 1];
+        bool is_key_path = last != "";
 
         bool destroy_all = false;
+        bool maintain_all = false;
         @foreach ((child) => {
-                if (child == root_button)
-                    return;
-
-                if (!(child is PathBarItem))
+                if (child is Label)
                 {
                     if (destroy_all)
                         child.destroy ();
+                    else
+                        complete_path += "/";
                     return;
                 }
 
-                if (!destroy_all && ((PathBarItem) child).text_string == split [0])
+                if (maintain_all)
                 {
-                    complete_path += split [0] + "/";
-                    if (split.length > 0)
-                        split = split [1:split.length];
+                    child.set_sensitive (true);
                     return;
                 }
 
-                ulong path_bar_item_clicked_handler = ((PathBarItem) child).path_bar_item_clicked_handler;
-                if (path_bar_item_clicked_handler != 0)
-                    child.disconnect (((PathBarItem) child).path_bar_item_clicked_handler);
+                if (child == root_button || (!destroy_all && ((PathBarItem) child).text_string == split [0]))
+                {
+                    complete_path += split [0];
+                    split = split [1:split.length];
+                    if (split.length == 0 || (split.length == 1 && !is_key_path))
+                    {
+                        child.set_sensitive (false);
+                        maintain_all = true;
+                    }
+                    else
+                        child.set_sensitive (true);
+                    return;
+                }
 
+                child.disconnect (((PathBarItem) child).path_bar_item_clicked_handler);
                 child.destroy ();
                 destroy_all = true;
             });
 
         if (split.length > 0)
         {
-            string last = split [split.length - 1];
-            bool is_key_path = last != "";
-
             /* add one item per folder */
             if (split.length > 1)
             {
@@ -83,32 +92,49 @@ public class PathBar : Box
                 foreach (string item in split [0:split.length - 1])
                 {
                     complete_path += item + "/";
-                    PathBarItem path_bar_item = new PathBarItem (item);
-                    if (is_key_path || (index != split.length - 1))
-                    {
-                        string local_complete_path = complete_path;
-                        path_bar_item.path_bar_item_clicked_handler = path_bar_item.clicked.connect (() => 
set_path_and_notify (local_complete_path));
-                    }
-                    add (path_bar_item);
-                    add (new Label ("/"));
+                    add_path_bar_item (item, complete_path, !is_key_path && (index == split.length - 2));
+                    add_slash_label ();
                     index++;
                 }
             }
 
             /* if key path */
             if (is_key_path)
-                add (new PathBarItem (last));
+            {
+                complete_path += last;
+                add_path_bar_item (last, complete_path, true);
+            }
         }
 
         /* only draw when finished, for CSS :last-child rendering */
         show_all ();
     }
 
+    /*\
+    * * widgets
+    \*/
+
     [GtkCallback]
     private void set_root_path ()
     {
+        root_button.set_sensitive (false);
         set_path_and_notify ("/");
     }
+
+    private void add_slash_label ()
+    {
+        add (new Label ("/"));
+    }
+
+    private void add_path_bar_item (string label, string complete_path, bool block)
+    {
+        PathBarItem path_bar_item = new PathBarItem (label);
+
+        path_bar_item.path_bar_item_clicked_handler = path_bar_item.clicked.connect (() => 
set_path_and_notify (complete_path));
+        path_bar_item.set_sensitive (!block);
+
+        add (path_bar_item);
+    }
 }
 
 [GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/pathbar-item.ui")]


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