summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMattias Bengtsson <mattias.jc.bengtsson@gmail.com>2014-11-11 00:28:33 +0100
committerMattias Bengtsson <mattias.jc.bengtsson@gmail.com>2014-11-11 00:30:37 +0100
commit462cb77198811fcf8f2d7a5ab27beb17ea2cea52 (patch)
treeecdf29fdf70f3fadafb27d919333f7e8447c9a1e
parent21b0806c1db9b84fd67483b2fa2c41effa6c2778 (diff)
downloadgnome-maps-wip/new_actions.tar.gz
Utils: Move accel setup into addActionswip/new_actions
Setting upp accelerators (keybindings) inside addActions feels more natural since you're already working with setting up the actions there to begin with.
-rw-r--r--src/mainWindow.js13
-rw-r--r--src/utils.js19
2 files changed, 22 insertions, 10 deletions
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 50205178..bbdb4bd8 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 0c5fc4a7..aa0d2b0f 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 }) {