[gnome-maps/wip/mlundblad/night-mode: 1/3] utils: Add ability to set a create hook for actions



commit 1321e50824f7f05f02bd8456ab5da18d3d0235a4
Author: Marcus Lundblad <ml update uu se>
Date:   Tue Jun 2 22:34:14 2020 +0200

    utils: Add ability to set a create hook for actions

 src/utils.js | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
---
diff --git a/src/utils.js b/src/utils.js
index 613e87e1..5c235f6b 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -110,22 +110,30 @@ function setAccelsForActionMap(actionMap, actionName, accels) {
     app.set_accels_for_action(prefix + '.' + actionName, accels);
 }
 
-function createAction(name, { state, paramType, onActivate, onChangeState }) {
+function createAction(name, { state, paramType, onActivate, onChangeState,
+                              createHook }) {
     let entry = { name: name };
 
-    if(Array.isArray(state)) {
+    if (Array.isArray(state)) {
         let [type, value] = state;
         entry.state = new GLib.Variant.new(type, value);
     }
 
-    if(paramType !== undefined)
+    if (paramType !== undefined)
         entry.parameter_type = GLib.VariantType.new(paramType);
 
-    let action = new Gio.SimpleAction(entry);
+    let action;
 
-    if(onActivate)
+    if (entry.state)
+        action = Gio.SimpleAction.new_stateful(name, null, entry.state);
+    else
+        action = new Gio.SimpleAction(entry);
+
+    if (createHook)
+        createHook(action);
+    if (onActivate)
         action.connect('activate', onActivate);
-    if(onChangeState)
+    if (onChangeState)
         action.connect('change-state', onChangeState);
 
     return action;


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