[baobab/reroot-view: 30/48] Add a Pathbar widget



commit 03cc9b83d868d9c6aed811eb440b819322e5a485
Author: Stefano Facchini <stefano facchini gmail com>
Date:   Wed Jun 17 16:29:40 2020 +0200

    Add a Pathbar widget
    
    Again, just a stub.

 data/baobab.gresource.xml     |  1 +
 data/ui/baobab-main-window.ui |  7 +++-
 data/ui/baobab-pathbutton.ui  | 14 +++++++
 src/baobab-pathbar.vala       | 90 +++++++++++++++++++++++++++++++++++++++++++
 src/baobab-window.vala        |  6 +++
 src/meson.build               |  1 +
 6 files changed, 118 insertions(+), 1 deletion(-)
---
diff --git a/data/baobab.gresource.xml b/data/baobab.gresource.xml
index 1465bbc..be3480b 100644
--- a/data/baobab.gresource.xml
+++ b/data/baobab.gresource.xml
@@ -6,6 +6,7 @@
     <file compressed="true">ui/baobab-location-list.ui</file>
     <file compressed="true">ui/baobab-location-row.ui</file>
     <file compressed="true">ui/baobab-main-window.ui</file>
+    <file compressed="true">ui/baobab-pathbutton.ui</file>
     <file compressed="true">gtk/help-overlay.ui</file>
     <file compressed="true">gtk/menus.ui</file>
     <file compressed="true">icons/scalable/actions/view-ringschart-symbolic.svg</file>
diff --git a/data/ui/baobab-main-window.ui b/data/ui/baobab-main-window.ui
index fa1f5e9..e785f94 100644
--- a/data/ui/baobab-main-window.ui
+++ b/data/ui/baobab-main-window.ui
@@ -432,7 +432,12 @@
         </packing>
       </child>
     </object>
-
   </child>
   </template>
+  <object class="BaobabPathbar" id="pathbar">
+    <property name="visible">True</property>
+    <style>
+      <class name="linked"/>
+    </style>
+  </object>
 </interface>
diff --git a/data/ui/baobab-pathbutton.ui b/data/ui/baobab-pathbutton.ui
new file mode 100644
index 0000000..98f41ef
--- /dev/null
+++ b/data/ui/baobab-pathbutton.ui
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <template class="BaobabPathButton" parent="GtkButton">
+    <property name="visible">True</property>
+    <child>
+      <object class="GtkLabel" id="label">
+        <property name="visible">True</property>
+        <property name="ellipsize">middle</property>
+        <property name="max_width_chars">15</property>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/baobab-pathbar.vala b/src/baobab-pathbar.vala
new file mode 100644
index 0000000..e4eb662
--- /dev/null
+++ b/src/baobab-pathbar.vala
@@ -0,0 +1,90 @@
+/* Baobab - disk usage analyzer
+ *
+ * Copyright (C) 2020 Stefano Facchini <stefano facchini gmail com>
+ *
+ * This program 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 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+namespace Baobab {
+
+    [GtkTemplate (ui = "/org/gnome/baobab/ui/baobab-pathbutton.ui")]
+    public class PathButton : Gtk.Button {
+        [GtkChild]
+        new Gtk.Label label;
+
+        public PathButton (string name) {
+            label.label = name;
+        }
+
+    }
+
+    public class Pathbar : Gtk.Box {
+        public signal void item_activated (Gtk.TreePath path);
+
+        public Location location { set; get; }
+
+        public new Gtk.TreePath path {
+            set {
+                if (location == null || location.scanner == null) {
+                    return;
+                }
+
+                clear ();
+
+                Gtk.TreePath path_tmp = value;
+
+                List<PathButton> buttons = null;
+
+                while (path_tmp.get_depth () > 0) {
+                    buttons.append (make_button (path_tmp));
+                    path_tmp.up ();
+                }
+
+                buttons.reverse ();
+                foreach (var button in buttons) {
+                    add (button);
+                }
+            }
+        }
+
+        void clear () {
+            this.foreach ((widget) => { widget.destroy (); });
+        }
+
+        PathButton make_button (Gtk.TreePath path) {
+            string label;
+
+            if (path.get_depth () == 1) {
+                label = location.name;
+            } else {
+                Gtk.TreeIter iter;
+                string name;
+                string display_name;
+                location.scanner.get_iter (out iter, path);
+                location.scanner.get (iter,
+                                      Scanner.Columns.NAME, out name,
+                                      Scanner.Columns.DISPLAY_NAME, out display_name);
+                label = display_name != null ? display_name : name;
+            }
+
+            var button = new PathButton (label);
+            button.clicked.connect (() => {
+                item_activated (path);
+            });
+
+            return button;
+        }
+    }
+}
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index d4ffb1f..464f3b8 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -83,6 +83,8 @@ namespace Baobab {
         [GtkChild]
         private Gtk.HeaderBar header_bar;
         [GtkChild]
+        private Pathbar pathbar;
+        [GtkChild]
         private Gtk.Button back_button;
         [GtkChild]
         private Gtk.Button reload_button;
@@ -282,6 +284,7 @@ namespace Baobab {
 
             active_location = location;
 
+            pathbar.location = location;
             folder_display.location = location;
 
             // Update the timestamp for GtkRecentManager
@@ -483,6 +486,7 @@ namespace Baobab {
                     rings_chart.root = path;
                     treemap_chart.root = path;
                     folder_display.path = path;
+                    pathbar.path = path;
                 }
             });
         }
@@ -536,10 +540,12 @@ namespace Baobab {
                 var action = lookup_action ("reload") as SimpleAction;
                 action.set_enabled (false);
                 header_bar.title = _("Devices & Locations");
+                header_bar.custom_title = null;
             } else {
                 var action = lookup_action ("reload") as SimpleAction;
                 action.set_enabled (true);
                 header_bar.title = active_location.name;
+                header_bar.custom_title = pathbar;
             }
 
             main_stack.visible_child = child;
diff --git a/src/meson.build b/src/meson.build
index 6cc9bc1..0e265f0 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -8,6 +8,7 @@ baobab_vala_sources = [
   'baobab-chart.vala',
   'baobab-location-list.vala',
   'baobab-location.vala',
+  'baobab-pathbar.vala',
   'baobab-ringschart.vala',
   'baobab-scanner.vala',
   'baobab-treemap.vala',


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