[baobab/reroot-view] Re-root the treeview on row activation



commit c3b3b39e84f07d85aa147cf744f7885939f596cd
Author: Stefano Facchini <stefano facchini gmail com>
Date:   Thu Jun 11 14:34:23 2020 +0200

    Re-root the treeview on row activation
    
    In this way we do not waste too much space on the left of the treeview,
    which in turn allows us to disable the horizontal scrolling and simplify
    the navigation.

 src/baobab-main-window.ui | 14 +++++---------
 src/baobab-window.vala    | 46 ++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 45 insertions(+), 15 deletions(-)
---
diff --git a/src/baobab-main-window.ui b/src/baobab-main-window.ui
index 16b9cd3..42d63ff 100644
--- a/src/baobab-main-window.ui
+++ b/src/baobab-main-window.ui
@@ -229,17 +229,17 @@
                       <property name="can_focus">True</property>
                       <property name="shadow_type">in</property>
                       <property name="hexpand">True</property>
+                      <property name="hscrollbar_policy">never</property>
                       <child>
                         <object class="GtkTreeView" id="treeview">
                           <property name="visible">True</property>
                           <property name="can_focus">True</property>
+                          <property name="activate-on-single-click">True</property>">
                           <child internal-child="selection">
                             <object class="GtkTreeSelection" id="treeview_selection1"/>
                           </child>
                           <child>
                             <object class="GtkTreeViewColumn" id="folder_column">
-                              <property name="resizable">True</property>
-                              <property name="sizing">grow-only</property>
                               <property name="title" translatable="yes">Folder</property>
                               <property name="expand">True</property>
                               <property name="reorderable">True</property>
@@ -255,7 +255,9 @@
                                 </attributes>
                               </child>
                               <child>
-                                <object class="BaobabCellRendererName" id="folder_column_text_renderer"/>
+                                <object class="BaobabCellRendererName" id="folder_column_text_renderer">
+                                  <property name="ellipsize">end</property>
+                                </object>
                                 <attributes>
                                   <attribute name="name">0</attribute>
                                   <attribute name="state">7</attribute>
@@ -265,8 +267,6 @@
                           </child>
                           <child>
                             <object class="GtkTreeViewColumn" id="size_column">
-                              <property name="resizable">True</property>
-                              <property name="sizing">grow-only</property>
                               <property name="title" translatable="yes">Size</property>
                               <property name="reorderable">True</property>
                               <property name="sort_column_id">4</property>
@@ -285,8 +285,6 @@
                           </child>
                           <child>
                             <object class="GtkTreeViewColumn" id="contents_column">
-                              <property name="resizable">True</property>
-                              <property name="sizing">grow-only</property>
                               <property name="title" translatable="yes">Contents</property>
                               <property name="reorderable">True</property>
                               <property name="sort_column_id">6</property>
@@ -303,8 +301,6 @@
                           </child>
                           <child>
                             <object class="GtkTreeViewColumn" id="time_modified_column">
-                              <property name="resizable">True</property>
-                              <property name="sizing">grow-only</property>
                               <property name="title" translatable="yes">Modified</property>
                               <property name="reorderable">True</property>
                               <property name="sort_column_id">5</property>
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index 072a9d2..a9afb73 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -78,6 +78,7 @@ namespace Baobab {
         private Gtk.Spinner spinner;
         private Location? active_location;
         private ulong scan_completed_handler;
+        private Gtk.TreeModelFilter filter;
 
         static Gdk.Cursor busy_cursor;
 
@@ -306,12 +307,15 @@ namespace Baobab {
 
         void on_chart_item_activated (Chart chart, Gtk.TreeIter iter) {
             var path = active_location.scanner.get_path (iter);
+            var filter_path = filter.convert_child_path_to_path (path);
+            reroot_treeview (filter_path);
 
-            if (!treeview.is_row_expanded (path)) {
-                treeview.expand_to_path (path);
-            }
+            //if (!treeview.is_row_expanded (path)) {
+            //treeview.collapse_all ();
+                //treeview.expand_to_path (path);
+            //}
 
-            treeview.set_cursor (path, null, false);
+            //treeview.set_cursor (path, null, false);
         }
 
         void on_drag_data_received (Gtk.Widget widget, Gdk.DragContext context, int x, int y,
@@ -427,7 +431,7 @@ namespace Baobab {
                 }
             });
 
-            var selection = treeview.get_selection ();
+            /*var selection = treeview.get_selection ();
             selection.changed.connect (() => {
                 Gtk.TreeIter iter;
                 if (selection.get_selected (null, out iter)) {
@@ -435,7 +439,36 @@ namespace Baobab {
                     rings_chart.root = path;
                     treemap_chart.root = path;
                 }
+            });*/
+
+            treeview.row_activated.connect ((path, column) => {
+                reroot_treeview (path);
+            });
+        }
+
+        void reroot_treeview (Gtk.TreePath activated_path) {
+            if (activated_path.get_depth () == 1) {
+                activated_path.up ();
+            }
+
+            var child_model_path = filter.convert_path_to_child_path (activated_path);
+            var virtual_root_path = child_model_path;
+
+            rings_chart.root = virtual_root_path;
+            treemap_chart.root = virtual_root_path;
+
+            child_model_path.up();
+            if (child_model_path.get_depth () == 0) {
+                child_model_path = null;
+            }
+
+            filter = new Gtk.TreeModelFilter (active_location.scanner, child_model_path);
+            filter.set_visible_func ((model, iter) => {
+                var path = model.get_path (iter);
+                return path.is_descendant (virtual_root_path) || path.compare (virtual_root_path) == 0;
             });
+            treeview.model = filter;
+            expand_first_row ();
         }
 
         void message (string primary_msg, string secondary_msg, Gtk.MessageType type) {
@@ -585,7 +618,8 @@ namespace Baobab {
 
             scanner.scan (force);
 
-            treeview.model = scanner;
+            filter = new Gtk.TreeModelFilter (scanner, null);
+            treeview.model = filter;
             expand_first_row ();
         }
 


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