[dconf-editor] Add a basic pathbar.



commit 41af53e9a98504b0e2f4f5598e5ae86f5a9e339e
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Apr 27 01:43:13 2016 +0200

    Add a basic pathbar.

 editor/Makefile.am                |    7 ++-
 editor/dconf-editor.css           |   35 ++++++++++++++++
 editor/dconf-editor.gresource.xml |    2 +
 editor/dconf-editor.ui            |   16 +++++++-
 editor/dconf-window.vala          |    3 +
 editor/pathbar-item.ui            |   13 ++++++
 editor/pathbar.ui                 |   10 +++++
 editor/pathbar.vala               |   78 +++++++++++++++++++++++++++++++++++++
 8 files changed, 161 insertions(+), 3 deletions(-)
---
diff --git a/editor/Makefile.am b/editor/Makefile.am
index 4b35d9b..bcf158e 100644
--- a/editor/Makefile.am
+++ b/editor/Makefile.am
@@ -29,7 +29,9 @@ resource_data = \
        key-editor-no-schema.ui \
        bookmarks.ui \
        bookmark.ui \
-       help-overlay.ui
+       help-overlay.ui \
+       pathbar.ui \
+       pathbar-item.ui
 
 resources.c: $(resource_data)
        $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --target=$@ --generate-source $<
@@ -43,7 +45,8 @@ dconf_editor_SOURCES = \
        dconf-model.vala \
        dconf-view.vala \
        bookmarks.vala \
-       key-list-box-row.vala
+       key-list-box-row.vala \
+       pathbar.vala
 
 desktopdir = $(datadir)/applications
 desktop_in_files = ca.desrt.dconf-editor.desktop.in.in
diff --git a/editor/dconf-editor.css b/editor/dconf-editor.css
index 8a286e9..a827235 100644
--- a/editor/dconf-editor.css
+++ b/editor/dconf-editor.css
@@ -18,3 +18,38 @@
 scrolledwindow.sidebar {
   min-width:15em;
 }
+
+.pathbar {
+  margin-left:8px;
+  margin-right:8px;
+}
+
+.pathbar > button {
+  padding-left:0.2em;
+  padding-right:0.2em;
+  margin-left:0.1em;
+  margin-right:0.1em;
+
+  border:none;
+  border-color:transparent;
+  box-shadow:none;
+  background:none;
+  background-color:transparent;
+}
+
+.pathbar > button > label {
+  border-width:2px 0px;
+  border-style:solid;
+  border-color:transparent;
+}
+
+.pathbar > button:hover > label {
+  border-bottom-color:grey;
+}
+
+.pathbar > button:last-child > label,
+.pathbar > button:last-child:hover > label,
+.pathbar > button:nth-last-child(2) > label,
+.pathbar > button:nth-last-child(2):hover > label {
+  border-bottom-color:blue;
+}
diff --git a/editor/dconf-editor.gresource.xml b/editor/dconf-editor.gresource.xml
index 005978a..901ca48 100644
--- a/editor/dconf-editor.gresource.xml
+++ b/editor/dconf-editor.gresource.xml
@@ -8,6 +8,8 @@
     <file preprocess="xml-stripblanks">key-list-box-row.ui</file>
     <file preprocess="xml-stripblanks">key-editor.ui</file>
     <file preprocess="xml-stripblanks">key-editor-no-schema.ui</file>
+    <file preprocess="xml-stripblanks">pathbar.ui</file>
+    <file preprocess="xml-stripblanks">pathbar-item.ui</file>
   </gresource>
   <gresource prefix="/ca/desrt/dconf-editor/gtk">
     <file preprocess="xml-stripblanks" alias="menus.ui">dconf-editor-menu.ui</file>
diff --git a/editor/dconf-editor.ui b/editor/dconf-editor.ui
index b735799..fb47230 100644
--- a/editor/dconf-editor.ui
+++ b/editor/dconf-editor.ui
@@ -15,9 +15,23 @@
       <object class="GtkHeaderBar">
         <property name="visible">True</property>
         <property name="show-close-button">True</property>
-        <property name="title" translatable="yes">dconf Editor</property>
         <property name="has-subtitle">False</property>
         <child>
+          <object class="PathBar" id="pathbar">
+            <property name="visible">True</property>
+            <property name="valign">center</property>
+            <signal name="path_selected" handler="scroll_to_path"/>
+          </object>
+          <packing>
+            <property name="pack-type">start</property>
+          </packing>
+        </child>
+        <child type="title">
+          <object class="GtkBox">
+            <property name="visible">False</property>
+          </object>
+        </child>
+        <child>
           <object class="GtkMenuButton" id="info_button">
             <property name="visible">True</property>
             <property name="valign">center</property>
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index cc2ce4a..bde41a9 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -48,6 +48,8 @@ class DConfWindow : ApplicationWindow
 
     [GtkChild] private MenuButton info_button;
 
+    [GtkChild] private PathBar pathbar;
+
     public DConfWindow ()
     {
         add_action_entries (action_entries, this);
@@ -148,6 +150,7 @@ class DConfWindow : ApplicationWindow
             key_model = model.get_directory (iter).key_model;
             current_path = model.get_directory (iter).full_name;
             bookmarks_button.current_path = current_path;
+            pathbar.set_path (current_path);
 
             GLib.Menu menu = new GLib.Menu ();
             menu.append (_("Copy current path"), "app.copy(\"" + current_path + "\")");   // TODO protection 
against some chars in text? 1/2
diff --git a/editor/pathbar-item.ui b/editor/pathbar-item.ui
new file mode 100644
index 0000000..86a6188
--- /dev/null
+++ b/editor/pathbar-item.ui
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <template class="PathBarItem" parent="GtkButton">
+    <signal name="clicked" handler="on_path_bar_item_clicked"/>
+    <child>
+      <object class="GtkLabel" id="text">
+        <property name="visible">True</property>
+        <property name="ellipsize">middle</property>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/editor/pathbar.ui b/editor/pathbar.ui
new file mode 100644
index 0000000..e66b9e8
--- /dev/null
+++ b/editor/pathbar.ui
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <template class="PathBar" parent="GtkBox">
+    <property name="orientation">horizontal</property>
+    <style>
+      <class name="pathbar"/>
+    </style>
+  </template>
+</interface>
diff --git a/editor/pathbar.vala b/editor/pathbar.vala
new file mode 100644
index 0000000..96670e8
--- /dev/null
+++ b/editor/pathbar.vala
@@ -0,0 +1,78 @@
+/*
+  This file is part of Dconf Editor
+
+  Dconf Editor is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  Dconf Editor is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with Dconf Editor.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+using Gtk;
+
+[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/pathbar.ui")]
+public class PathBar : Box
+{
+    public signal bool path_selected (string path);
+
+    public void set_path (string path, bool notify = false)
+        requires (path [0] == '/')
+    {
+        @foreach ((child) => { child.destroy (); });
+
+        string [] split = path.split ("/", 0);
+
+        /* add initial text (set to "settings://"?) */
+        string complete_path = "/";
+        add (new Label ("/"));
+
+        /* add one item per folder */
+        if (split.length > 2)
+            foreach (string item in split [1:split.length - 1])
+            {
+                complete_path += item + "/";
+                add (new PathBarItem (item, complete_path));
+                add (new Label ("/"));
+            }
+
+        /* if key path */
+        string last = split [split.length - 1];
+        if (last != "")
+            add (new PathBarItem (last, complete_path + last));
+
+        /* only draw when finished, for CSS :last-child rendering */
+        show_all ();
+
+        /* notify if requested */
+        if (notify)
+            if (!path_selected (path))
+                warning ("something has got wrong with pathbar");
+    }
+}
+
+[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/pathbar-item.ui")]
+private class PathBarItem : Button
+{
+    public string complete_path { get; construct; }
+
+    [GtkChild] private Label text;
+
+    public PathBarItem (string label, string path)
+    {
+        Object (complete_path: path);
+        text.set_text (label);
+    }
+
+    [GtkCallback]
+    private void on_path_bar_item_clicked ()
+    {
+        ((PathBar) get_parent ()).set_path (complete_path, true);
+    }
+}


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