[dconf-editor] Only destroy the unwanted PathBarItem.



commit 8806d69e27a39b0420418eaec1642c4835d95a9f
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sat Jul 30 02:12:01 2016 +0200

    Only destroy the unwanted PathBarItem.

 editor/dconf-editor.css   |    1 +
 editor/pathbar-item.ui    |    2 +-
 editor/pathbar.vala       |   90 ++++++++++++++++++++++++++++----------------
 editor/registry-view.vala |    4 +-
 4 files changed, 60 insertions(+), 37 deletions(-)
---
diff --git a/editor/dconf-editor.css b/editor/dconf-editor.css
index 2767c15..c8e1914 100644
--- a/editor/dconf-editor.css
+++ b/editor/dconf-editor.css
@@ -163,6 +163,7 @@ window > popover.menu {
   border-width:2px 0px;
   border-style:solid;
   border-color:transparent;
+  transition:border-bottom-color 0.3s;
 }
 
 .pathbar > button:hover > .item {
diff --git a/editor/pathbar-item.ui b/editor/pathbar-item.ui
index dc43202..fc2177e 100644
--- a/editor/pathbar-item.ui
+++ b/editor/pathbar-item.ui
@@ -3,7 +3,7 @@
   <!-- interface-requires gtk+ 3.0 -->
   <template class="PathBarItem" parent="GtkButton">
     <child>
-      <object class="GtkLabel" id="text">
+      <object class="GtkLabel" id="text_label">
         <property name="visible">True</property>
         <property name="ellipsize">middle</property>
         <style>
diff --git a/editor/pathbar.vala b/editor/pathbar.vala
index 9fa6cca..932f6a3 100644
--- a/editor/pathbar.vala
+++ b/editor/pathbar.vala
@@ -24,6 +24,11 @@ public class PathBar : Box
 
     public signal bool path_selected (string path);
 
+    construct
+    {
+        add (new Label ("/"));
+    }
+
     public void set_path_and_notify (string path)
     {
         set_path (path);
@@ -34,49 +39,66 @@ public class PathBar : Box
     public void set_path (string path)
         requires (path [0] == '/')
     {
+        string complete_path = "/";
+        string [] split = path.split ("/", /* max tokens disabled */ 0);
+        split = split [1:split.length];
+
+        bool destroy_all = false;
         @foreach ((child) => {
-                if (child != root_button)
+                if (child == root_button)
+                    return;
+
+                if (!(child is PathBarItem))
                 {
-                    if (child is PathBarItem)
-                    {
-                        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);
-                    }
-                    child.destroy ();
+                    if (destroy_all)
+                        child.destroy ();
+                    return;
                 }
-            });
 
-        string [] split = path.split ("/", 0);
-        string last = split [split.length - 1];
-        bool is_key_path = last != "";
+                if (!destroy_all && ((PathBarItem) child).text_string == split [0])
+                {
+                    complete_path += split [0] + "/";
+                    if (split.length > 0)
+                        split = split [1:split.length];
+                    return;
+                }
 
-        /* add initial text (set to "settings://"?) */
-        string complete_path = "/";
-        add (new Label ("/"));
+                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);
+
+                child.destroy ();
+                destroy_all = true;
+            });
 
-        /* add one item per folder */
-        if (split.length > 2)
+        if (split.length > 0)
         {
-            uint index = 0;
-            foreach (string item in split [1:split.length - 1])
+            string last = split [split.length - 1];
+            bool is_key_path = last != "";
+
+            /* add one item per folder */
+            if (split.length > 1)
             {
-                index++;
-                complete_path += item + "/";
-                PathBarItem path_bar_item = new PathBarItem (item);
-                if (is_key_path || (index != split.length - 2))
+                uint index = 0;
+                foreach (string item in split [0: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); });
+                    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 ("/"));
+                    index++;
                 }
-                add (path_bar_item);
-                add (new Label ("/"));
             }
-        }
 
-        /* if key path */
-        if (is_key_path)
-            add (new PathBarItem (last));
+            /* if key path */
+            if (is_key_path)
+                add (new PathBarItem (last));
+        }
 
         /* only draw when finished, for CSS :last-child rendering */
         show_all ();
@@ -94,10 +116,12 @@ private class PathBarItem : Button
 {
     public ulong path_bar_item_clicked_handler = 0;
 
-    [GtkChild] private Label text;
+    public string text_string { get; private set; }
+    [GtkChild] private Label text_label;
 
     public PathBarItem (string label)
     {
-        text.set_text (label);
+        text_string = label;
+        text_label.set_text (label);
     }
 }
diff --git a/editor/registry-view.vala b/editor/registry-view.vala
index 1eee781..4b5af59 100644
--- a/editor/registry-view.vala
+++ b/editor/registry-view.vala
@@ -78,7 +78,7 @@ class RegistryView : Grid
     {
         revealer.path_changed ();
         current_path = path;
-        get_dconf_window ().update_hamburger_menu ();
+        invalidate_popovers ();
     }
 
     /*\
@@ -162,7 +162,6 @@ class RegistryView : Grid
         }
 
         update_current_path (full_name);
-        invalidate_popovers ();
         show_properties_view ();
         return true;
     }
@@ -206,7 +205,6 @@ class RegistryView : Grid
     private void open_folder (string folder_path)
     {
         update_current_path (folder_path);
-        invalidate_popovers ();
         show_browse_view ();
     }
 


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