[baobab/wip/vala] Use GAction for the chart type buttons
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [baobab/wip/vala] Use GAction for the chart type buttons
- Date: Thu, 26 Jan 2012 17:45:00 +0000 (UTC)
commit f344df566b657e5c495c7e52fa4b723994022f59
Author: Ryan Lortie <desrt desrt ca>
Date: Thu Jan 26 12:43:50 2012 -0500
Use GAction for the chart type buttons
...and hook them up to GSettings.
data/baobab-main-window.ui | 9 ++++++---
src/baobab-window.vala | 43 ++++++++++++++++++++++++++-----------------
2 files changed, 32 insertions(+), 20 deletions(-)
---
diff --git a/data/baobab-main-window.ui b/data/baobab-main-window.ui
index 60831b1..e912f73 100644
--- a/data/baobab-main-window.ui
+++ b/data/baobab-main-window.ui
@@ -199,7 +199,7 @@
<class name="linked"/>
</style>
<child>
- <object class="GtkRadioButton" id="rings-button">
+ <object class="GtkToggleButton" id="rings-button">
<property name="label" translatable="yes">Rings</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -208,6 +208,8 @@
<property name="xalign">0.5</property>
<property name="active">True</property>
<property name="draw_indicator">False</property>
+ <property name="action_name">win.chart-type</property>
+ <property name="action_target">'rings'</property>
</object>
<packing>
<property name="expand">False</property>
@@ -216,7 +218,7 @@
</packing>
</child>
<child>
- <object class="GtkRadioButton" id="treemap-button">
+ <object class="GtkToggleButton" id="treemap-button">
<property name="label" translatable="yes">Treemap</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -225,7 +227,8 @@
<property name="xalign">0.5</property>
<property name="active">True</property>
<property name="draw_indicator">False</property>
- <property name="group">rings-button</property>
+ <property name="action_name">win.chart-type</property>
+ <property name="action_target">'treemap'</property>
</object>
<packing>
<property name="expand">False</property>
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index 0ec47e8..eee63bc 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -1,16 +1,20 @@
namespace Baobab {
public class Window : Gtk.ApplicationWindow {
+ Settings ui_settings;
Gtk.TreeView treeview;
Gtk.Notebook chart_notebook;
Chart rings_chart;
Chart treemap_chart;
- Gtk.ToggleButton rings_chart_button;
- Gtk.ToggleButton treemap_chart_button;
Scanner? scanner;
static Gdk.Cursor busy_cursor;
+ void radio_activate (SimpleAction action, Variant? parameter) {
+ action.change_state (parameter);
+ }
+
private const GLib.ActionEntry[] action_entries = {
+ { "active-chart", radio_activate, "s", "'rings'", on_chart_type_changed },
{ "scan-home", on_scan_home_activate },
{ "scan-filesystem", on_scan_filesystem_activate },
{ "scan-folder", on_scan_folder_activate },
@@ -69,19 +73,10 @@ namespace Baobab {
chart_notebook = builder.get_object ("chart-notebook") as Gtk.Notebook;
rings_chart = builder.get_object ("rings-chart") as Chart;
treemap_chart = builder.get_object ("treemap-chart") as Chart;
- rings_chart_button = builder.get_object ("rings-button") as Gtk.ToggleButton;
- treemap_chart_button = builder.get_object ("treemap-button") as Gtk.ToggleButton;
treeview = builder.get_object ("treeview") as Gtk.TreeView;
- var ui_settings = Application.get_ui_settings ();
-
- // Setup the logic for switching between the chart types.
- rings_chart_button.toggled.connect (() => {
- chart_notebook.page = 0;
- });
- treemap_chart_button.toggled.connect (() => {
- chart_notebook.page = 1;
- });
+ ui_settings = Application.get_ui_settings ();
+ lookup_action ("active-chart").change_state (ui_settings.get_value ("active-chart"));
// Setup drag-n-drop
drag_data_received.connect(on_drag_data_received);
@@ -97,6 +92,22 @@ namespace Baobab {
show ();
}
+ void on_chart_type_changed (SimpleAction action, Variant value) {
+ switch (value as string) {
+ case "rings":
+ chart_notebook.page = 0;
+ break;
+ case "treemap":
+ chart_notebook.page = 1;
+ break;
+ default:
+ return;
+ }
+
+ ui_settings.set_value ("active-chart", value);
+ action.set_state (value);
+ }
+
void on_scan_home_activate () {
var dir = File.new_for_path (GLib.Environment.get_home_dir ());
scan_directory (dir);
@@ -236,14 +247,12 @@ namespace Baobab {
disable_drop ();
rings_chart.freeze_updates();
treemap_chart.freeze_updates ();
- rings_chart_button.set_sensitive (false);
- treemap_chart_button.set_sensitive (false);
+ (lookup_action ("active-chart") as SimpleAction).set_enabled (false);
} else {
enable_drop ();
rings_chart.thaw_updates();
treemap_chart.thaw_updates ();
- rings_chart_button.set_sensitive (true);
- treemap_chart_button.set_sensitive (true);
+ (lookup_action ("active-chart") as SimpleAction).set_enabled (true);
}
var window = get_window ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]