[polari/wip/fmuellner/window-experiments: 348/356] app: Split out addActionEntries() utility function



commit 2e79e46288d4318bc3a1af024f6396f1368e78c3
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Jul 14 16:04:43 2016 +0200

    app: Split out addActionEntries() utility function
    
    We currently store all actions in the application, which works fine
    for a single-window application, even though some actions conceptually
    belong to the window. However if we want to support multiple windows,
    we'll have to split our actions - in preparation for this, move our
    g_action_map_add_action_entries() replacement into Utils.

 src/application.js |   21 +--------------------
 src/utils.js       |   21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 20 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 4b1084b..37a67f0 100644
--- a/src/application.js
+++ b/src/application.js
@@ -193,26 +193,7 @@ const Application = new Lang.Class({
           { name: 'previous-pending-room',
             accels: ['<Alt><Shift>Up', '<Primary><Shift>Page_Up']}
         ];
-        actionEntries.forEach(Lang.bind(this,
-            function(actionEntry) {
-                let props = {};
-                ['name', 'state', 'parameter_type'].forEach(
-                    function(prop) {
-                        if (actionEntry[prop])
-                            props[prop] = actionEntry[prop];
-                    });
-                let action = new Gio.SimpleAction(props);
-                if (actionEntry.create_hook)
-                    actionEntry.create_hook(action);
-                if (actionEntry.activate)
-                    action.connect('activate', actionEntry.activate);
-                if (actionEntry.change_state)
-                    action.connect('change-state', actionEntry.change_state);
-                if (actionEntry.accels)
-                    this.set_accels_for_action('app.' + actionEntry.name,
-                                               actionEntry.accels);
-                this.add_action(action);
-        }));
+        Utils.addActionEntries(this, 'app', actionEntries);
 
         this._settings = new Gio.Settings({ schema_id: 'org.gnome.Polari' });
         let action = this._settings.create_action('run-in-background');
diff --git a/src/utils.js b/src/utils.js
index 40b2583..b819917 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -202,6 +202,27 @@ function updateTerms(terms, str) {
     return changed;
 }
 
+function addActionEntries(map, prefix, entries) {
+    let app = Gio.Application.get_default();
+    entries.forEach(entry => {
+        let props = {};
+        for (let prop of ['name', 'state', 'parameter_type'])
+            if (entry[prop])
+                props[prop] = entry[prop];
+
+        let action = new Gio.SimpleAction(props);
+        if (entry.create_hook)
+            entry.create_hook(action);
+        if (entry.activate)
+            action.connect('activate', entry.activate);
+        if (entry.change_state)
+            action.connect('change-state', entry.change_state);
+        if (entry.accels)
+            app.set_accels_for_action(prefix + '.' + entry.name, entry.accels);
+        map.add_action(action);
+    });
+}
+
 function gpaste(text, title, callback) {
     if (title.length > MAX_PASTE_TITLE_LENGTH)
         title = title.substr(0, MAX_PASTE_TITLE_LENGTH - 1) + '…';


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]