[gnome-maps] Utils: Move accel setup into addActions



commit a5e14c2ccf2f65e27f6d6e44799299fd1bfbd535
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.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=739933

 src/mainWindow.js |   13 +++----------
 src/utils.js      |   17 +++++++++++++++++
 2 files changed, 20 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..cbc6c35 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -94,7 +94,24 @@ 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]