Commit c31d0be6 authored by Christopher Davis's avatar Christopher Davis

Remove initActions

Instead of using initActions we can just declare the actions
manually. Allows us to remove params.js completely
parent e8d3d203
......@@ -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
......
......@@ -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');
......
......@@ -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;
......
......@@ -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() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment