[baobab/wip/new-design: 10/59] expand first row when it is added
- From: Stefano Facchini <sfacchini src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [baobab/wip/new-design: 10/59] expand first row when it is added
- Date: Sun, 1 Apr 2012 17:10:31 +0000 (UTC)
commit e8434ab58d8e3f1f0285871fb4827329db1aad22
Author: Ryan Lortie <desrt desrt ca>
Date: Thu Jan 5 21:03:55 2012 -0500
expand first row when it is added
and refactor baobab-window a bit
src/baobab-window.vala | 47 ++++++++++++++++++++++++++++++++++-------------
1 files changed, 34 insertions(+), 13 deletions(-)
---
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index 7fd6337..215dc04 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -1,19 +1,25 @@
namespace Baobab {
public class Window : Gtk.ApplicationWindow {
- Gtk.TreeModel? model;
- Gtk.Builder builder;
+ Gtk.TreeView treeview;
+ Chart rings_chart;
+ Chart treemap;
public Window (Application app) {
Object (application: app);
// Build ourselves.
- builder = new Gtk.Builder ();
+ var builder = new Gtk.Builder ();
try {
builder.add_from_file (Config.PKGDATADIR + "/baobab-main-window.ui");
} catch (Error e) {
error ("loading main builder file: %s", e.message);
}
+ // Cache some objects from the builder.
+ rings_chart = builder.get_object ("rings-chart") as Chart;
+ treemap = builder.get_object ("treemap") as Chart;
+ treeview = builder.get_object ("treeview") as Gtk.TreeView;
+
var ui_settings = Application.get_ui_settings ();
// Setup the logic for switching between the chart types.
@@ -61,16 +67,22 @@ namespace Baobab {
}
}
- public void scan_directory (File directory) {
- if (!check_dir (directory)) {
- return;
+ 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 set_model (Scanner model) {
+ Gtk.TreeIter first;
+
+ treeview.model = model;
+
+ if (model.iter_children (out first, null) && model.iter_has_child (first)) {
+ treeview.expand_row (model.get_path (first), false);
+ } else {
+ model.row_has_child_toggled.connect (first_row_has_child);
}
- var scanner = new ThreadedScanner ();
- scanner.scan (directory);
- model = scanner;
- var rings_chart = builder.get_object ("rings-chart") as Chart;
- var treemap = builder.get_object ("treemap") as Chart;
model.bind_property ("max-depth", rings_chart, "max-depth", BindingFlags.SYNC_CREATE);
model.bind_property ("max-depth", treemap, "max-depth", BindingFlags.SYNC_CREATE);
treemap.set_model_with_columns (model,
@@ -85,8 +97,17 @@ namespace Baobab {
Scanner.Columns.PARSE_NAME,
Scanner.Columns.PERCENT,
Scanner.Columns.ELEMENTS, null);
- var treeview = builder.get_object ("treeview") as Gtk.TreeView;
- treeview.model = model;
+ }
+
+ public void scan_directory (File directory) {
+ if (!check_dir (directory)) {
+ return;
+ }
+
+ var scanner = new ThreadedScanner ();
+ scanner.scan (directory);
+
+ set_model (scanner);
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]