[gnome-maps] Add a initActions utility



commit 190e7528eacb1ebfb93722725dbfdbba487c35ed
Author: Paolo Borelli <pborelli gnome org>
Date:   Tue Apr 2 00:04:23 2013 +0200

    Add a initActions utility
    
    Add an utility function to declare GActions (borrowed from
    gnome-weather)

 src/application.js |   38 ++++----------------------------------
 src/utils.js       |   13 +++++++++++++
 2 files changed, 17 insertions(+), 34 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 1e580ec..14e197d 100644
--- a/src/application.js
+++ b/src/application.js
@@ -62,33 +62,6 @@ const Application = new Lang.Class({
         this._mainWindow.showAbout();
     },
 
-    _initActions: function() {
-        this._actionEntries.forEach(Lang.bind(this,
-            function(actionEntry) {
-                let state = actionEntry.state;
-                let parameterType = actionEntry.parameter_type ?
-                    GLib.VariantType.new(actionEntry.parameter_type) : null;
-                let action;
-
-                if (state)
-                    action = Gio.SimpleAction.new_stateful(actionEntry.name,
-                        parameterType, actionEntry.state);
-                else
-                    action = new Gio.SimpleAction({ name: actionEntry.name });
-
-                if (actionEntry.create_hook)
-                    actionEntry.create_hook.apply(this, [action]);
-
-                if (actionEntry.callback)
-                    action.connect('activate', Lang.bind(this, actionEntry.callback));
-
-                if (actionEntry.accel)
-                    this.add_accelerator(actionEntry.accel, 'app.' + actionEntry.name, null);
-
-                this.add_action(action);
-            }));
-    },
-
     _initAppMenu: function() {
         let builder = new Gtk.Builder();
         builder.add_from_resource('/org/gnome/maps/app-menu.ui');
@@ -109,14 +82,11 @@ const Application = new Lang.Class({
         application = this;
         settings = new Gio.Settings({ schema: 'org.gnome.maps' });
 
-        this._actionEntries = [
-            { name: 'about',
-              callback: this._onActionAbout },
-            { name: 'quit',
-              callback: this._onActionQuit }
-        ];
+        Utils.initActions(this, [
+            { name: 'about', callback: this._onActionAbout },
+            { name: 'quit', callback: this._onActionQuit }
+        ]);
 
-        this._initActions();
         this._initAppMenu();
     },
 
diff --git a/src/utils.js b/src/utils.js
index 0687ee7..40a2d3c 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -19,7 +19,9 @@
  *         Zeeshan Ali (Khattak) <zeeshanak gnome org>
  */
 
+const Lang = imports.lang;
 const GLib = imports.gi.GLib;
+const Gio = imports.gi.Gio;
 const Signals = imports.signals;
 const Geocode = imports.gi.GeocodeGlib;
 
@@ -46,6 +48,17 @@ function addJSSignalMethods(proto) {
     proto.disconnectAllJS = Signals._disconnectAll;
 }
 
+function initActions(actionMap, simpleActionEntries) {
+    simpleActionEntries.forEach(function(entry) {
+        let action = new Gio.SimpleAction({ name: entry.name });
+
+        if (entry.callback)
+            action.connect('activate', Lang.bind(actionMap, entry.callback));
+
+        actionMap.add_action(action);
+    });
+}
+
 // accuracy: Geocode.LocationAccuracy
 function getZoomLevelForAccuracy(accuracy) {
     switch (accuracy) {


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