[gnome-weather] Extend Util.initActions() to handle stateful actions
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-weather] Extend Util.initActions() to handle stateful actions
- Date: Mon, 13 May 2013 21:24:31 +0000 (UTC)
commit ffed7787e9d9e47454ac5757daa5259c567da525
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Mon May 13 17:43:13 2013 +0200
Extend Util.initActions() to handle stateful actions
Idea taken from gnome-maps, but the implementation is different
because nested objects and an explicit "signalHandlers" was too much.
src/main.js | 2 +-
src/util.js | 14 ++++++++++----
src/window.js | 14 +++++++-------
3 files changed, 18 insertions(+), 12 deletions(-)
---
diff --git a/src/main.js b/src/main.js
index 216ef3c..e866e4b 100644
--- a/src/main.js
+++ b/src/main.js
@@ -74,7 +74,7 @@ const Application = new Lang.Class({
Util.initActions(this,
[{ name: 'quit',
- callback: this._onQuit }]);
+ activate: this._onQuit }]);
this._initAppMenu();
diff --git a/src/util.js b/src/util.js
index 6d82688..4ee8847 100644
--- a/src/util.js
+++ b/src/util.js
@@ -44,12 +44,18 @@ function loadStyleSheet(file) {
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
}
-function initActions(actionMap, simpleActionEntries) {
+function initActions(actionMap, simpleActionEntries, context) {
simpleActionEntries.forEach(function(entry) {
- let action = new Gio.SimpleAction({ name: entry.name });
-
- if (entry.callback)
- action.connect('activate', Lang.bind(actionMap, entry.callback));
+ let filtered = Params.filter(entry, { activate: null,
+ state_changed: null,
+ context: null });
+ let action = new Gio.SimpleAction(entry);
+
+ let context = filtered.context || actionMap;
+ if (filtered.activate)
+ action.connect('activate', filtered.activate.bind(context));
+ if (filtered.state_changed)
+ action.connect('state-changed', filtered.state_changed.bind(context));
actionMap.add_action(action);
});
diff --git a/src/window.js b/src/window.js
index 577aa92..916a368 100644
--- a/src/window.js
+++ b/src/window.js
@@ -45,19 +45,19 @@ const MainWindow = new Lang.Class({
Util.initActions(this,
[{ name: 'new',
- callback: this._newLocation },
+ activate: this._newLocation },
{ name: 'preferences',
- callback: this._showPreferences },
+ activate: this._showPreferences },
{ name: 'about',
- callback: this._showAbout },
+ activate: this._showAbout },
{ name: 'exit-selection-mode',
- callback: this._exitSelectionMode },
+ activate: this._exitSelectionMode },
{ name: 'select-all',
- callback: this._selectAll },
+ activate: this._selectAll },
{ name: 'select-none',
- callback: this._selectNone },
+ activate: this._selectNone },
{ name: 'delete-selected',
- callback: this._deleteSelected }]);
+ activate: this._deleteSelected }]);
let builder = new Gtk.Builder();
builder.add_from_resource('/org/gnome/weather/window.ui');
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]