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



commit cc61572eb3fd4458c90b7afedfd5b5e0664515e0
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 a414751..41221af 100644
--- a/src/application.js
+++ b/src/application.js
@@ -115,26 +115,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);
 
         for (let i = 1; i < 10; i++)
             this.set_accels_for_action('app.nth-room(%d)'.format(i), ['<Alt>' + i]);
diff --git a/src/utils.js b/src/utils.js
index c431304..8d5f25d 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -185,6 +185,27 @@ function openURL(url, timestamp) {
     }
 }
 
+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]