[dconf-editor] Introduce ShortPathbar.



commit a08656268b335d1187bd716cdd0dd60d251629ab
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sat Oct 13 15:44:00 2018 +0200

    Introduce ShortPathbar.

 editor/adaptative-pathbar.ui                      | 19 +++++
 editor/adaptative-pathbar.vala                    | 94 +++++++++++++++++++++++
 editor/dconf-editor.gresource.xml                 |  6 +-
 editor/dconf-editor.ui                            |  4 +-
 editor/{pathbar-item.ui => large-pathbar-item.ui} |  2 +-
 editor/{pathbar.ui => large-pathbar.ui}           |  4 +-
 editor/{pathbar.vala => large-pathbar.vala}       | 60 +++++++--------
 editor/meson.build                                | 12 ++-
 editor/pathwidget.ui                              |  4 +-
 editor/pathwidget.vala                            | 18 +++--
 editor/short-pathbar.ui                           | 36 +++++++++
 editor/short-pathbar.vala                         | 94 +++++++++++++++++++++++
 12 files changed, 302 insertions(+), 51 deletions(-)
---
diff --git a/editor/adaptative-pathbar.ui b/editor/adaptative-pathbar.ui
new file mode 100644
index 0000000..7da87f5
--- /dev/null
+++ b/editor/adaptative-pathbar.ui
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <template class="AdaptativePathbar" parent="GtkStack">
+    <property name="hexpand">True</property>
+    <child>
+      <object class="LargePathbar" id="large_pathbar">
+        <property name="visible">True</property>
+        <property name="valign">center</property>
+      </object>
+    </child>
+    <child>
+      <object class="ShortPathbar" id="short_pathbar">
+        <property name="visible">True</property>
+        <property name="valign">center</property>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/editor/adaptative-pathbar.vala b/editor/adaptative-pathbar.vala
new file mode 100644
index 0000000..32d63a6
--- /dev/null
+++ b/editor/adaptative-pathbar.vala
@@ -0,0 +1,94 @@
+/*
+  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 <https://www.gnu.org/licenses/>.
+*/
+
+using Gtk;
+
+[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/adaptative-pathbar.ui")]
+private class AdaptativePathbar : Stack, Pathbar
+{
+    [GtkChild] private LargePathbar large_pathbar;
+    [GtkChild] private ShortPathbar short_pathbar;
+
+    private bool _extra_small_window = false;
+    internal bool extra_small_window
+    {
+        private get { return _extra_small_window; }
+        internal set
+        {
+            _extra_small_window = value;
+
+            if (value)
+                set_visible_child (short_pathbar);
+            else
+                set_visible_child (large_pathbar);
+        }
+    }
+
+    internal string complete_path { get { return large_pathbar.complete_path; }}
+
+    /*\
+    * * keyboard
+    \*/
+
+    internal bool has_popover ()
+    {
+        return large_pathbar.has_popover () || short_pathbar.has_popover ();
+    }
+
+    internal void close_menu ()
+    {
+        large_pathbar.close_menu ();
+        short_pathbar.close_menu ();
+    }
+
+    internal void toggle_menu ()
+    {
+        if (_extra_small_window)
+            short_pathbar.toggle_menu ();
+        else
+            large_pathbar.toggle_menu ();
+    }
+
+    /*\
+    * * main public calls
+    \*/
+
+    internal void set_path (ViewType type, string path)
+    {
+        large_pathbar.set_path (type, path);
+        short_pathbar.set_path (type, path);
+    }
+
+    internal void update_ghosts (string non_ghost_path, bool is_search)
+    {
+        large_pathbar.update_ghosts (non_ghost_path, is_search);
+        short_pathbar.update_ghosts (non_ghost_path, is_search);
+    }
+
+    internal string get_selected_child (string current_path)
+    {
+        return large_pathbar.get_selected_child (current_path);
+    }
+}
+
+private interface Pathbar
+{
+    internal static void add_copy_path_entry (ref GLib.Menu section)
+    {
+        section.append (_("Copy current path"), "kbd.copy-path"); // or "app.copy(\"" + 
get_action_target_value ().get_string () + "\")"
+    }
+}
diff --git a/editor/dconf-editor.gresource.xml b/editor/dconf-editor.gresource.xml
index deb3f57..a1e0567 100644
--- a/editor/dconf-editor.gresource.xml
+++ b/editor/dconf-editor.gresource.xml
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
   <gresource prefix="/ca/desrt/dconf-editor/ui">
+    <file preprocess="xml-stripblanks">adaptative-pathbar.ui</file>
     <file preprocess="xml-stripblanks">bookmark.ui</file>
     <file preprocess="xml-stripblanks">bookmarks.ui</file>
     <file preprocess="xml-stripblanks">browser-headerbar.ui</file>
@@ -13,9 +14,9 @@
     <file preprocess="xml-stripblanks">delayed-setting-view.ui</file>
     <file preprocess="xml-stripblanks">folder-list-box-row.ui</file>
     <file preprocess="xml-stripblanks">key-list-box-row.ui</file>
+    <file preprocess="xml-stripblanks">large-pathbar.ui</file>
+    <file preprocess="xml-stripblanks">large-pathbar-item.ui</file>
     <file preprocess="xml-stripblanks">modifications-revealer.ui</file>
-    <file preprocess="xml-stripblanks">pathbar.ui</file>
-    <file preprocess="xml-stripblanks">pathbar-item.ui</file>
     <file preprocess="xml-stripblanks">pathentry.ui</file>
     <file preprocess="xml-stripblanks">pathwidget.ui</file>
     <file preprocess="xml-stripblanks">property-row.ui</file>
@@ -24,6 +25,7 @@
     <file preprocess="xml-stripblanks">registry-view.ui</file>
     <file preprocess="xml-stripblanks">return-list-box-row.ui</file>
     <file preprocess="xml-stripblanks">search-list-box-row.ui</file>
+    <file preprocess="xml-stripblanks">short-pathbar.ui</file>
   </gresource>
   <gresource prefix="/ca/desrt/dconf-editor/gtk">
     <file preprocess="xml-stripblanks">help-overlay.ui</file>
diff --git a/editor/dconf-editor.ui b/editor/dconf-editor.ui
index a834143..02dfae3 100644
--- a/editor/dconf-editor.ui
+++ b/editor/dconf-editor.ui
@@ -4,8 +4,8 @@
   <template class="DConfWindow" parent="GtkApplicationWindow">
     <property name="visible">False</property>
     <property name="title" translatable="yes">dconf Editor</property>
-    <property name="height-request">290</property> <!-- 294 max for Purism Librem 5 landscape -->
-    <property name="width-request">450</property>  <!-- 360 max for Purism Librem 5 portrait -->
+    <property name="height-request">283</property> <!-- 294 max for Purism Librem 5 landscape -->
+    <property name="width-request">349</property>  <!-- 360 max for Purism Librem 5 portrait -->
     <signal name="key-press-event" handler="on_key_press_event"/>
     <signal name="button-press-event" handler="on_button_press_event"/>
     <signal name="window-state-event" handler="on_window_state_event"/>
diff --git a/editor/pathbar-item.ui b/editor/large-pathbar-item.ui
similarity index 89%
rename from editor/pathbar-item.ui
rename to editor/large-pathbar-item.ui
index 9cee84b..416cf6a 100644
--- a/editor/pathbar-item.ui
+++ b/editor/large-pathbar-item.ui
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
-  <template class="PathBarItem" parent="GtkButton">
+  <template class="LargePathbarItem" parent="GtkButton">
     <property name="focus-on-click">False</property>
     <signal name="clicked" handler="update_cursor"/>
     <child>
diff --git a/editor/pathbar.ui b/editor/large-pathbar.ui
similarity index 85%
rename from editor/pathbar.ui
rename to editor/large-pathbar.ui
index 30f70cc..b2fa502 100644
--- a/editor/pathbar.ui
+++ b/editor/large-pathbar.ui
@@ -1,13 +1,13 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
-  <template class="PathBar" parent="GtkBox">
+  <template class="LargePathbar" parent="GtkBox">
     <property name="orientation">horizontal</property>
     <style>
       <class name="pathbar"/>
     </style>
     <child>
-      <object class="PathBarItem" id="root_button">
+      <object class="LargePathbarItem" id="root_button">
         <property name="visible">True</property>
         <property name="action-name">ui.open-folder</property>
         <property name="alternative-action">ui.open-folder('/')</property>
diff --git a/editor/pathbar.vala b/editor/large-pathbar.vala
similarity index 83%
rename from editor/pathbar.vala
rename to editor/large-pathbar.vala
index 38cd3df..00b3bd4 100644
--- a/editor/pathbar.vala
+++ b/editor/large-pathbar.vala
@@ -17,11 +17,11 @@
 
 using Gtk;
 
-[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/pathbar.ui")]
-private class PathBar : Box
+[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/large-pathbar.ui")]
+private class LargePathbar : Box, Pathbar
 {
-    [GtkChild] private PathBarItem root_button;
-    private PathBarItem active_button;
+    [GtkChild] private LargePathbarItem root_button;
+    private LargePathbarItem active_button;
 
     internal string complete_path { get; private set; default = ""; }
 
@@ -84,7 +84,7 @@ private class PathBar : Box
                     return;
                 }
 
-                PathBarItem item = (PathBarItem) child;
+                LargePathbarItem item = (LargePathbarItem) child;
 
                 if (maintain_all)
                 {
@@ -134,7 +134,7 @@ private class PathBar : Box
             }
         }
 
-        show_all ();
+        @foreach ((child) => child.show ());
     }
     private static inline void update_config_style_class (bool type_is_config, StyleContext context)
     {
@@ -157,9 +157,9 @@ private class PathBar : Box
         string action_target = "";
         @foreach ((child) => {
                 StyleContext context = child.get_style_context ();
-                if (child is PathBarItem)
+                if (child is LargePathbarItem)
                 {
-                    PathBarItem item = (PathBarItem) child;
+                    LargePathbarItem item = (LargePathbarItem) child;
                     Variant? variant = item.get_action_target_value ();
                     if (variant == null)
                         assert_not_reached ();
@@ -175,12 +175,12 @@ private class PathBar : Box
                     {
                         if (is_search)
                         {
-                            item.set_cursor_type (PathBarItem.CursorType.POINTER);
+                            item.set_cursor_type (LargePathbarItem.CursorType.POINTER);
                             item.set_detailed_action_name (item.default_action);
                         }
                         else
                         {
-                            item.set_cursor_type (PathBarItem.CursorType.CONTEXT);
+                            item.set_cursor_type (LargePathbarItem.CursorType.CONTEXT);
                             item.set_action_name ("ui.empty");
                         }
                         if (non_ghost_path.has_prefix (action_target))
@@ -190,13 +190,13 @@ private class PathBar : Box
                     }
                     else if (non_ghost_path.has_prefix (action_target))
                     {
-                        item.set_cursor_type (PathBarItem.CursorType.POINTER);
+                        item.set_cursor_type (LargePathbarItem.CursorType.POINTER);
                         item.set_detailed_action_name (item.default_action);
                         context.remove_class ("inexistent");
                     }
                     else
                     {
-                        item.set_cursor_type (PathBarItem.CursorType.DEFAULT);
+                        item.set_cursor_type (LargePathbarItem.CursorType.DEFAULT);
                         item.set_detailed_action_name (item.alternative_action);
                         context.add_class ("inexistent");
                     }
@@ -208,16 +208,16 @@ private class PathBar : Box
             });
     }
 
-    private static inline void update_active_button_cursor (ViewType type, ref PathBarItem active_button)
+    private static inline void update_active_button_cursor (ViewType type, ref LargePathbarItem 
active_button)
     {
         if (type == ViewType.CONFIG)
         {
-            active_button.set_cursor_type (PathBarItem.CursorType.POINTER);
+            active_button.set_cursor_type (LargePathbarItem.CursorType.POINTER);
             active_button.set_detailed_action_name (active_button.default_action);
         }
         else
         {
-            active_button.set_cursor_type (PathBarItem.CursorType.CONTEXT);
+            active_button.set_cursor_type (LargePathbarItem.CursorType.CONTEXT);
             active_button.set_action_name ("ui.empty");
         }
     }
@@ -233,61 +233,61 @@ private class PathBar : Box
 
     private void add_path_bar_item (string label, string complete_path, bool is_folder, bool block)
     {
-        PathBarItem path_bar_item = create_path_bar_item (label, complete_path, is_folder);
+        LargePathbarItem path_bar_item = create_path_bar_item (label, complete_path, is_folder);
         add (path_bar_item);
         activate_item (path_bar_item, block);   // has to be after add()
     }
-    private static inline PathBarItem create_path_bar_item (string label, string complete_path, bool 
is_folder)
+    private static inline LargePathbarItem create_path_bar_item (string label, string complete_path, bool 
is_folder)
     {
-        PathBarItem path_bar_item;
+        LargePathbarItem path_bar_item;
         if (is_folder)
             init_folder_path_bar_item (label, complete_path, out path_bar_item);
         else
             init_object_path_bar_item (label, complete_path, out path_bar_item);
         return path_bar_item;
     }
-    private static inline void init_folder_path_bar_item (string label, string complete_path, out 
PathBarItem path_bar_item)
+    private static inline void init_folder_path_bar_item (string label, string complete_path, out 
LargePathbarItem path_bar_item)
     {
         Variant variant = new Variant.string (complete_path);
         string _variant = variant.print (false);
-        path_bar_item = new PathBarItem (label, "ui.open-folder(" + _variant + ")", 
"ui.notify-folder-emptied(" + _variant + ")");
+        path_bar_item = new LargePathbarItem (label, "ui.open-folder(" + _variant + ")", 
"ui.notify-folder-emptied(" + _variant + ")");
     }
-    private static inline void init_object_path_bar_item (string label, string complete_path, out 
PathBarItem path_bar_item)
+    private static inline void init_object_path_bar_item (string label, string complete_path, out 
LargePathbarItem path_bar_item)
     {
         Variant variant = new Variant ("(sq)", complete_path, ModelUtils.undefined_context_id);
         string _variant = variant.print (true);
-        path_bar_item = new PathBarItem (label, "ui.open-object(" + _variant + ")", 
"ui.notify-object-deleted(" + _variant + ")");
+        path_bar_item = new LargePathbarItem (label, "ui.open-object(" + _variant + ")", 
"ui.notify-object-deleted(" + _variant + ")");
     }
 
-    private void activate_item (PathBarItem item, bool state)   // never called when current_view is search
+    private void activate_item (LargePathbarItem item, bool state)   // never called when current_view is 
search
     {
         if (state)
             active_button = item;
         _activate_item (item, state);
     }
-    private static inline void _activate_item (PathBarItem item, bool state)
+    private static inline void _activate_item (LargePathbarItem item, bool state)
     {
         if (state == item.is_active)
             return;
         if (state)
         {
             item.is_active = true;
-            item.set_cursor_type (PathBarItem.CursorType.CONTEXT);
+            item.set_cursor_type (LargePathbarItem.CursorType.CONTEXT);
             item.set_action_name ("ui.empty");
             item.get_style_context ().add_class ("active");
         }
         else
         {
             item.is_active = false;
-            item.set_cursor_type (PathBarItem.CursorType.POINTER);
+            item.set_cursor_type (LargePathbarItem.CursorType.POINTER);
             item.set_detailed_action_name (item.default_action);
             item.get_style_context ().remove_class ("active");
         }
     }
 }
 
-[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/pathbar-item.ui")]
-private class PathBarItem : Button
+[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/large-pathbar-item.ui")]
+private class LargePathbarItem : Button
 {
     public bool is_active { internal get; internal set; default = false; }
 
@@ -355,7 +355,7 @@ private class PathBarItem : Button
         ((!) popover).popup ();
     }
 
-    internal PathBarItem (string label, string _default_action, string _alternative_action)
+    internal LargePathbarItem (string label, string _default_action, string _alternative_action)
     {
         Object (text_string: label, default_action: _default_action, alternative_action: 
_alternative_action);
         text_label.set_text (label);
@@ -387,7 +387,7 @@ private class PathBarItem : Button
     private void generate_popover ()
     {
         GLib.Menu menu = new GLib.Menu ();
-        menu.append (_("Copy current path"), "kbd.copy-path"); // or "app.copy(\"" + get_action_target_value 
().get_string () + "\")"
+        Pathbar.add_copy_path_entry (ref menu);
         menu.freeze ();
 
         popover = new Popover.from_model (this, (MenuModel) menu);
diff --git a/editor/meson.build b/editor/meson.build
index d44c691..566ce54 100644
--- a/editor/meson.build
+++ b/editor/meson.build
@@ -66,6 +66,7 @@ install_data(
 )
 
 sources = files(
+  'adaptative-pathbar.vala',
   'bookmarks.vala',
   'browser-headerbar.vala',
   'browser-infobar.vala',
@@ -77,11 +78,11 @@ sources = files(
   'dconf-window.vala',
   'delayed-setting-view.vala',
   'key-list-box-row.vala',
+  'large-pathbar.vala',
   'model-utils.vala',
   'modifications-handler.vala',
   'modifications-revealer.vala',
   'night-light-monitor.vala',
-  'pathbar.vala',
   'pathentry.vala',
   'pathwidget.vala',
   'registry-info.vala',
@@ -91,10 +92,12 @@ sources = files(
   'registry-view.vala',
   'schemas-utility.vala',
   'setting-object.vala',
+  'short-pathbar.vala',
   'source-manager.vala'
 )
 
 resource_data = files(
+  'adaptative-pathbar.ui',
   'bookmarks.ui',
   'bookmark.ui',
   'browser-headerbar.ui',
@@ -108,9 +111,9 @@ resource_data = files(
   'folder-list-box-row.ui',
   'help-overlay.ui',
   'key-list-box-row.ui',
+  'large-pathbar-item.ui',
+  'large-pathbar.ui',
   'modifications-revealer.ui',
-  'pathbar-item.ui',
-  'pathbar.ui',
   'pathentry.ui',
   'pathwidget.ui',
   'property-row.ui',
@@ -118,7 +121,8 @@ resource_data = files(
   'registry-placeholder.ui',
   'registry-view.ui',
   'return-list-box-row.ui',
-  'search-list-box-row.ui'
+  'search-list-box-row.ui',
+  'short-pathbar.ui'
 )
 
 sources += gnome.compile_resources(
diff --git a/editor/pathwidget.ui b/editor/pathwidget.ui
index c3588b5..4198e28 100644
--- a/editor/pathwidget.ui
+++ b/editor/pathwidget.ui
@@ -4,7 +4,7 @@
   <template class="PathWidget" parent="GtkBox">
     <property name="spacing">6</property>
     <child>
-      <object class="GtkStack" id="pathbar_stack">
+      <object class="GtkStack" id="pathwidget_stack">
         <property name="visible">True</property>
         <property name="valign">center</property>
         <property name="visible-child">pathbar_grid</property> <!-- uses the "id" attribute -->
@@ -26,7 +26,7 @@
           <object class="GtkGrid" id="pathbar_grid">
             <property name="visible">True</property>
             <child>
-              <object class="PathBar" id="pathbar">
+              <object class="AdaptativePathbar" id="pathbar">
                 <property name="visible">True</property>
                 <property name="valign">center</property>
               </object>
diff --git a/editor/pathwidget.vala b/editor/pathwidget.vala
index 6d63c95..7919e4f 100644
--- a/editor/pathwidget.vala
+++ b/editor/pathwidget.vala
@@ -20,12 +20,12 @@ using Gtk;
 [GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/pathwidget.ui")]
 private class PathWidget : Box
 {
-    [GtkChild] private ModelButton  search_toggle;  // most window size button
-    [GtkChild] private ModelButton  search_button;  // extra-small-window only
-    [GtkChild] private Stack        pathbar_stack;
-    [GtkChild] private Grid         pathbar_grid;
-    [GtkChild] private PathBar      pathbar;
-    [GtkChild] private PathEntry    searchentry;
+    [GtkChild] private ModelButton          search_toggle;      // most window size button
+    [GtkChild] private ModelButton          search_button;      // extra-small-window only
+    [GtkChild] private Stack                pathwidget_stack;
+    [GtkChild] private Grid                 pathbar_grid;
+    [GtkChild] private AdaptativePathbar    pathbar;
+    [GtkChild] private PathEntry            searchentry;
 
     internal signal void search_changed ();
     internal signal void search_stopped ();
@@ -45,6 +45,8 @@ private class PathWidget : Box
         {
             _extra_small_window = value;
 
+            pathbar.extra_small_window = value;
+
             if (value)
             {
                 search_toggle.hide ();
@@ -70,14 +72,14 @@ private class PathWidget : Box
     {
         search_mode_enabled = true;
         search_toggle.set_action_target_value (false);
-        pathbar_stack.set_visible_child (searchentry);
+        pathwidget_stack.set_visible_child (searchentry);
     }
 
     private void leave_search_mode ()
     {
         search_mode_enabled = false;
         search_toggle.set_action_target_value (true);
-        pathbar_stack.set_visible_child (pathbar_grid);
+        pathwidget_stack.set_visible_child (pathbar_grid);
     }
 
     /*\
diff --git a/editor/short-pathbar.ui b/editor/short-pathbar.ui
new file mode 100644
index 0000000..0d1e8f5
--- /dev/null
+++ b/editor/short-pathbar.ui
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <template class="ShortPathbar" parent="GtkGrid">
+    <property name="orientation">horizontal</property>
+    <property name="column-spacing">6</property>
+    <child>
+      <object class="GtkMenuButton" id="menu_button">
+        <property name="visible">True</property>
+        <style>
+          <class name="image-button"/>
+        </style>
+        <child>
+          <object class="GtkImage">
+            <property name="visible">True</property>
+            <property name="icon-name">ca.desrt.dconf-editor-symbolic</property>
+            <property name="icon-size">1</property>
+          </object>
+        </child>
+        <!-- child internal-child="accessible">
+          <object class="AtkObject">
+            <property name="AtkObject::accessible-name" translatable="yes">Search</property>
+            <property name="AtkObject::accessible-description" translatable="yes">Search keys</property>
+          </object>
+        </child -->
+      </object>
+    </child>
+    <child>
+      <object class="GtkLabel" id="view_label">
+        <property name="visible">True</property>
+        <property name="xalign">0</property>
+        <property name="ellipsize">end</property>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/editor/short-pathbar.vala b/editor/short-pathbar.vala
new file mode 100644
index 0000000..c512670
--- /dev/null
+++ b/editor/short-pathbar.vala
@@ -0,0 +1,94 @@
+/*
+  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 <https://www.gnu.org/licenses/>.
+*/
+
+using Gtk;
+
+[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/short-pathbar.ui")]
+private class ShortPathbar : Grid, Pathbar
+{
+    [GtkChild] private MenuButton   menu_button;
+    [GtkChild] private Label        view_label;
+
+    /*\
+    * * keyboard
+    \*/
+
+    internal bool has_popover ()
+    {
+        return menu_button.active;
+    }
+
+    internal void close_menu ()
+    {
+        menu_button.active = false;
+    }
+
+    internal void toggle_menu ()
+    {
+        menu_button.active = !menu_button.active;
+    }
+
+    /*\
+    * * main public calls
+    \*/
+
+    internal void set_path (ViewType type, string path)
+    {
+        if (type == ViewType.SEARCH)
+            return;
+
+        view_label.set_text (ModelUtils.get_name (path));
+
+        GLib.Menu menu = new GLib.Menu ();
+        GLib.Menu section = new GLib.Menu ();
+
+        string [] split = ModelUtils.get_parent_path (path).split ("/", /* max tokens disabled */ 0);
+        if (split.length < 2)
+            assert_not_reached ();
+        split = split [1:split.length - 1];    // excludes initial and last ""
+
+        // slash folder
+        string complete_path = "/";
+
+        if (path != "/")
+            menu.append ("/", "ui.open-folder('/')");
+
+        // parent folders
+        foreach (string item in split)
+        {
+            complete_path += item + "/";
+            menu.append (item, "ui.open-folder('" + complete_path + "')");  // TODO append or prepend?
+        }
+
+        section.freeze ();
+        menu.append_section (null, section);
+
+        section = new GLib.Menu ();
+
+        Pathbar.add_copy_path_entry (ref section);
+
+        section.freeze ();
+        menu.append_section (null, section);
+
+        menu.freeze ();
+        menu_button.set_menu_model (menu);
+    }
+
+    internal void update_ghosts (string non_ghost_path, bool is_search)
+    {
+    }
+}


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