[baobab/reroot-view: 10/35] Do not reroot at empty rows



commit c7c204fc486619d337ca54c90419413841a76c28
Author: Stefano Facchini <stefano facchini gmail com>
Date:   Wed Jun 17 19:30:16 2020 +0200

    Do not reroot at empty rows

 src/baobab-chart.vala  |  4 +---
 src/baobab-window.vala | 18 +++++++++++++-----
 2 files changed, 14 insertions(+), 8 deletions(-)
---
diff --git a/src/baobab-chart.vala b/src/baobab-chart.vala
index ea9ac3e..f726412 100644
--- a/src/baobab-chart.vala
+++ b/src/baobab-chart.vala
@@ -171,9 +171,7 @@ namespace Baobab {
             }
         }
 
-        public virtual signal void item_activated (Gtk.TreeIter iter) {
-            root = model.get_path (iter);
-        }
+        public signal void item_activated (Gtk.TreeIter iter);
 
         protected virtual void post_draw  (Cairo.Context cr) {
         }
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index c75f7d4..a2a3f60 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -493,19 +493,27 @@ namespace Baobab {
             treeview.row_activated.connect ((filter_path, column) => {
                 var filter = (Gtk.TreeModelFilter) treeview.model;
                 var path = filter.convert_path_to_child_path (filter_path);
-                reroot_treeview (path);
-                treeview.set_cursor (new Gtk.TreePath.first (), null, false);
+                reroot_treeview (path, true);
             });
         }
 
-        void reroot_treeview (Gtk.TreePath path) {
+        void reroot_treeview (Gtk.TreePath path, bool select_first = false) {
+            Gtk.TreeIter iter;
+            active_location.scanner.get_iter (out iter, path);
+            if (!active_location.scanner.iter_has_child (iter)) {
+                return;
+            }
+
             rings_chart.root = path;
             treemap_chart.root = path;
             folder_display.path = path;
             pathbar.path = path;
 
-            var filter = new Gtk.TreeModelFilter (active_location.scanner, path);
-            treeview.model = filter;
+            treeview.model = new Gtk.TreeModelFilter (active_location.scanner, path);
+
+            if (select_first) {
+                treeview.set_cursor (new Gtk.TreePath.first (), null, false);
+            }
         }
 
         void message (string primary_msg, string secondary_msg, Gtk.MessageType type) {


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