[gnome-weather/wip/christopherdavis/es6: 3/4] Remove initActions
- From: Christopher Davis <christopherdavis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-weather/wip/christopherdavis/es6: 3/4] Remove initActions
- Date: Sun, 24 Feb 2019 08:43:02 +0000 (UTC)
commit 49d857396fded7a907d26723678a62dfb631c4a7
Author: Christopher Davis <brainblasted disroot org>
Date: Sun Feb 24 03:19:42 2019 -0500
Remove initActions
Instead of using initActions we can just declare the actions
manually. Allows us to remove params.js completely
src/app/main.js | 35 ++++++++++++++++++++++++++---------
src/app/window.js | 28 +++++++++++++++++++++-------
src/misc/util.js | 17 -----------------
src/service/main.js | 9 ++++++---
4 files changed, 53 insertions(+), 36 deletions(-)
---
diff --git a/src/app/main.js b/src/app/main.js
index 33a425c..799dc71 100644
--- a/src/app/main.js
+++ b/src/app/main.js
@@ -98,15 +98,32 @@ const Application = GObject.registerClass(
if (this.model.loading)
this.mark_busy();
- Util.initActions(this,
- [{ name: 'quit',
- activate: this._onQuit },
- { name: 'show-location',
- activate: this._onShowLocation,
- parameter_type: new GLib.VariantType('v') },
- { name: 'show-search',
- activate: this._onShowSearch,
- parameter_type: new GLib.VariantType('s') }]);
+ let quitAction = new Gio.SimpleAction({
+ enabled: true,
+ name: 'quit'
+ });
+ quitAction.connect('activate', () => this._onQuit());
+ this.add_action(quitAction);
+
+ let showLocationAction = new Gio.SimpleAction({
+ enabled: true,
+ name: 'show-location',
+ parameter_type: new GLib.VariantType('v'),
+ });
+ showLocationAction.connect('activate', (action, parameter) => {
+ this._onShowLocation();
+ });
+ this.add_action(showLocationAction);
+
+ let showSearchAction = new Gio.SimpleAction({
+ enabled: true,
+ name: 'show-search',
+ parameter_type: new GLib.VariantType('v'),
+ })
+ showSearchAction.connect('activate', (action, parameter) => {
+ this._onShowSearch();
+ });
+ this.add_action(showSearchAction);
let gwSettings = new Gio.Settings({ schema_id: 'org.gnome.GWeather' });
// we would like to use g_settings_create_action() here
diff --git a/src/app/window.js b/src/app/window.js
index 93013c3..0338124 100644
--- a/src/app/window.js
+++ b/src/app/window.js
@@ -16,6 +16,7 @@
// with Gnome Weather; if not, write to the Free Software Foundation,
// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+const Gio = imports.gi.Gio;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const GWeather = imports.gi.GWeather;
@@ -43,13 +44,26 @@ var MainWindow = GObject.registerClass(
this._currentPage = Page.SEARCH;
this._pageWidgets = [[],[]];
- Util.initActions(this,
- [{ name: 'about',
- activate: this._showAbout },
- { name: 'close',
- activate: this._close },
- { name: 'refresh',
- activate: this.update }]);
+ let aboutAction = new Gio.SimpleAction({
+ enabled: true,
+ name: 'about'
+ });
+ aboutAction.connect('activate', () => this._showAbout());
+ this.add_action(aboutAction);
+
+ let closeAction = new Gio.SimpleAction({
+ enabled: true,
+ name: 'close'
+ });
+ closeAction.connect('activate', () => this._close());
+ this.add_action(closeAction);
+
+ let refreshAction = new Gio.SimpleAction({
+ enabled: true,
+ name: 'refresh'
+ });
+ refreshAction.connect('activate', () => this.update());
+ this.add_action(refreshAction);
let builder = new Gtk.Builder();
builder.add_from_resource('/org/gnome/Weather/window.ui');
diff --git a/src/misc/util.js b/src/misc/util.js
index 6d2a656..2dc3974 100644
--- a/src/misc/util.js
+++ b/src/misc/util.js
@@ -53,23 +53,6 @@ function loadStyleSheet(resource) {
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
}
-function initActions(actionMap, simpleActionEntries, context) {
- simpleActionEntries.forEach(function(entry) {
- 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);
- });
-}
-
function arrayEqual(one, two) {
if (one.length != two.length)
return false;
diff --git a/src/service/main.js b/src/service/main.js
index ec1ad20..1e12058 100644
--- a/src/service/main.js
+++ b/src/service/main.js
@@ -87,9 +87,12 @@ const BackgroundService = GObject.registerClass(
});
}
- Util.initActions(this,
- [{ name: 'quit',
- activate: this._onQuit }]);
+ let quitAction = new Gio.SimpleAction({
+ enabled: true,
+ name: 'quit'
+ });
+ quitAction.connect('activate', () => this._onQuit());
+ this.add_action(quitAction);
}
vfunc_activate() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]