[baobab/reroot-view: 10/35] Re-root the treeview on row activation
- From: Stefano Facchini <sfacchini src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [baobab/reroot-view: 10/35] Re-root the treeview on row activation
- Date: Fri, 26 Jun 2020 08:58:58 +0000 (UTC)
commit 2ef100ae33d63a12b4301e171fb7e76e2f5e5166
Author: Stefano Facchini <stefano facchini gmail com>
Date: Wed Jun 17 18:46:56 2020 +0200
Re-root the treeview on row activation
In this way we can avoid horizontal scrolling in the treeview, at last.
data/ui/baobab-main-window.ui | 13 +++-----
src/baobab-window.vala | 76 +++++++++++++++++++++++++------------------
2 files changed, 48 insertions(+), 41 deletions(-)
---
diff --git a/data/ui/baobab-main-window.ui b/data/ui/baobab-main-window.ui
index e785f94..105dea5 100644
--- a/data/ui/baobab-main-window.ui
+++ b/data/ui/baobab-main-window.ui
@@ -241,6 +241,7 @@
<property name="shadow_type">in</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
+ <property name="hscrollbar-policy">never</property>
<child>
<object class="GtkTreeView" id="treeview">
<property name="visible">True</property>
@@ -250,8 +251,6 @@
</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>
@@ -267,7 +266,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="display_name">4</attribute>
@@ -278,8 +279,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">2</property>
@@ -296,8 +295,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">5</property>
@@ -314,8 +311,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">3</property>
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index 2e35570..c75f7d4 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -51,7 +51,6 @@ namespace Baobab {
public new Gtk.TreePath path {
set {
- print("current_path=%s\n", value.to_string());
Gtk.TreeIter iter;
location.scanner.get_iter (out iter, value);
@@ -192,6 +191,7 @@ namespace Baobab {
rings_chart.item_activated.connect (on_chart_item_activated);
treemap_chart.item_activated.connect (on_chart_item_activated);
+ pathbar.item_activated.connect (on_pathbar_item_activated);
// Setup drag-n-drop
drag_data_received.connect (on_drag_data_received);
@@ -294,7 +294,7 @@ namespace Baobab {
// Update the timestamp for GtkRecentManager
location_list.add_location (location);
- treeview.model = location.scanner;
+ treeview.model = null;
scan_active_location (force);
}
@@ -366,12 +366,11 @@ namespace Baobab {
void on_chart_item_activated (Chart chart, Gtk.TreeIter iter) {
var path = active_location.scanner.get_path (iter);
+ reroot_treeview (path);
+ }
- if (!treeview.is_row_expanded (path)) {
- treeview.expand_to_path (path);
- }
-
- treeview.set_cursor (path, null, false);
+ void on_pathbar_item_activated (Pathbar pathbar, Gtk.TreePath path) {
+ reroot_treeview (path);
}
void on_drag_data_received (Gtk.Widget widget, Gdk.DragContext context, int x, int y,
@@ -441,6 +440,18 @@ namespace Baobab {
}
}
+ bool get_selected_iter (out Gtk.TreeIter iter) {
+ Gtk.TreeIter filter_iter;
+
+ var selection = treeview.get_selection ();
+ var result = selection.get_selected (null, out filter_iter);
+
+ var filter = (Gtk.TreeModelFilter) treeview.model;
+ filter.convert_iter_to_child_iter (out iter, filter_iter);
+
+ return result;
+ }
+
void setup_treeview () {
treeview.button_press_event.connect ((event) => {
if (event.triggers_context_menu ()) {
@@ -459,42 +470,44 @@ namespace Baobab {
});
treeview_popup_open.activate.connect (() => {
- var selection = treeview.get_selection ();
Gtk.TreeIter iter;
- if (selection.get_selected (null, out iter)) {
+ if (get_selected_iter (out iter)) {
open_item (iter);
}
});
treeview_popup_copy.activate.connect (() => {
- var selection = treeview.get_selection ();
Gtk.TreeIter iter;
- if (selection.get_selected (null, out iter)) {
+ if (get_selected_iter (out iter)) {
copy_path (iter);
}
});
treeview_popup_trash.activate.connect (() => {
- var selection = treeview.get_selection ();
Gtk.TreeIter iter;
- if (selection.get_selected (null, out iter)) {
+ if (get_selected_iter (out iter)) {
trash_file (iter);
}
});
- var selection = treeview.get_selection ();
- selection.changed.connect (() => {
- Gtk.TreeIter iter;
- if (selection.get_selected (null, out iter)) {
- var path = active_location.scanner.get_path (iter);
- rings_chart.root = path;
- treemap_chart.root = path;
- folder_display.path = path;
- pathbar.path = path;
- }
+ 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);
});
}
+ void reroot_treeview (Gtk.TreePath path) {
+ 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;
+ }
+
void message (string primary_msg, string secondary_msg, Gtk.MessageType type) {
infobar.message_type = type;
infobar_primary_label.label = "<b>%s</b>".printf (primary_msg);
@@ -555,18 +568,18 @@ namespace Baobab {
main_stack.visible_child = child;
}
- void first_row_has_child (Gtk.TreeModel model, Gtk.TreePath path, Gtk.TreeIter iter) {
- model.row_has_child_toggled.disconnect (first_row_has_child);
- treeview.expand_row (path, false);
+ void scanner_has_first_row (Gtk.TreeModel model, Gtk.TreePath path, Gtk.TreeIter iter) {
+ model.row_has_child_toggled.disconnect (scanner_has_first_row);
+ reroot_treeview (path);
}
- void expand_first_row () {
+ void reroot_when_scanner_not_empty () {
Gtk.TreeIter first;
- if (treeview.model.get_iter_first (out first) && treeview.model.iter_has_child (first)) {
- treeview.expand_row (treeview.model.get_path (first), false);
+ if (active_location.scanner.get_iter_first (out first)) {
+ reroot_treeview (new Gtk.TreePath.first ());
} else {
- treeview.model.row_has_child_toggled.connect (first_row_has_child);
+ active_location.scanner.row_has_child_toggled.connect (scanner_has_first_row);
}
}
@@ -622,8 +635,7 @@ namespace Baobab {
set_ui_state (result_page, true);
scanner.scan (force);
-
- expand_first_row ();
+ reroot_when_scanner_not_empty ();
}
public void scan_directory (File directory, ScanFlags flags=ScanFlags.NONE) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]