[gnome-maps/wip/new_actions: 2/2] Utils: Move accel setup into addActions
- From: Mattias Bengtsson <mattiasb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/new_actions: 2/2] Utils: Move accel setup into addActions
- Date: Mon, 10 Nov 2014 23:31:21 +0000 (UTC)
commit 462cb77198811fcf8f2d7a5ab27beb17ea2cea52
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date: Tue Nov 11 00:28:33 2014 +0100
Utils: Move accel setup into addActions
Setting upp accelerators (keybindings) inside addActions feels more
natural since you're already working with setting up the actions there
to begin with.
src/mainWindow.js | 13 +++----------
src/utils.js | 19 +++++++++++++++++++
2 files changed, 22 insertions(+), 10 deletions(-)
---
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 5020517..bbdb4bd 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -84,7 +84,6 @@ const MainWindow = new Lang.Class({
this._initHeaderbar();
this._initActions();
- this._initAccelerators();
this._initSignals();
this._restoreWindowGeometry();
@@ -128,15 +127,6 @@ const MainWindow = new Lang.Class({
return sidebar;
},
- _initAccelerators: function() {
- this.window.application.set_accels_for_action('win.zoom-in',
- ['<Primary>plus']);
- this.window.application.set_accels_for_action('win.zoom-out',
- ['<Primary>minus']);
- this.window.application.set_accels_for_action('win.find',
- ['<Primary>F']);
- },
-
_initActions: function() {
Utils.addActions(this.window, {
'close': {
@@ -162,12 +152,15 @@ const MainWindow = new Lang.Class({
onChangeState: this._onToggleSidebarChangeState.bind(this)
},
'zoom-in': {
+ accels: ['<Primary>plus'],
onActivate: this.mapView.view.zoom_in.bind(this.mapView.view)
},
'zoom-out': {
+ accels: ['<Primary>minus'],
onActivate: this.mapView.view.zoom_out.bind(this.mapView.view)
},
'find': {
+ accels: ['<Primary>F'],
onActivate: this._placeEntry.grab_focus.bind(this._placeEntry)
}
});
diff --git a/src/utils.js b/src/utils.js
index 0c5fc4a..aa0d2b0 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -94,7 +94,26 @@ function addActions(actionMap, entries) {
let action = createAction(name, entry);
actionMap.add_action(action);
+
+ if(entry.accels)
+ setAccelsForActionMap(actionMap, name, entry.accels);
+ }
+}
+
+function setAccelsForActionMap(actionMap, actionName, accels) {
+ let app;
+ let prefix;
+
+ if(actionMap instanceof Gtk.Application) {
+ app = actionMap;
+ prefix = "app";
+ } else if(actionMap instanceof Gtk.Window) {
+ app = actionMap.application;
+ prefix = "win";
}
+
+ app.set_accels_for_action(prefix + '.' + actionName,
+ accels);
}
function createAction(name, { state, paramType, onActivate, onChangeState }) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]