[gnome-maps/wip/mlundblad/night-mode: 1/4] utils: Add ability to create actions mapped to a GSettings key
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/night-mode: 1/4] utils: Add ability to create actions mapped to a GSettings key
- Date: Thu, 4 Jun 2020 21:49:52 +0000 (UTC)
commit 36ccf6ca9e1307ec3ca8fc6fa7333b494b2463ba
Author: Marcus Lundblad <ml update uu se>
Date: Tue Jun 2 22:34:14 2020 +0200
utils: Add ability to create actions mapped to a GSettings key
src/utils.js | 41 ++++++++++++++++++++++++++---------------
1 file changed, 26 insertions(+), 15 deletions(-)
---
diff --git a/src/utils.js b/src/utils.js
index 613e87e1..b40707f6 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -84,10 +84,10 @@ function loadStyleSheet(file) {
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
}
-function addActions(actionMap, entries) {
+function addActions(actionMap, entries, settings = null) {
for(let name in entries) {
let entry = entries[name];
- let action = createAction(name, entry);
+ let action = createAction(name, entry, settings);
actionMap.add_action(action);
@@ -110,23 +110,34 @@ function setAccelsForActionMap(actionMap, actionName, accels) {
app.set_accels_for_action(prefix + '.' + actionName, accels);
}
-function createAction(name, { state, paramType, onActivate, onChangeState }) {
- let entry = { name: name };
+function createAction(name,
+ { state, paramType, onActivate, onChangeState, setting },
+ settings = null) {
+ let action;
- if(Array.isArray(state)) {
- let [type, value] = state;
- entry.state = new GLib.Variant.new(type, value);
- }
+ if (setting && settings) {
+ action = settings.create_action(setting);
+
+ if (onChangeState)
+ action.connect('notify::state', onChangeState);
+ } else {
+ let entry = { name: name };
- if(paramType !== undefined)
- entry.parameter_type = GLib.VariantType.new(paramType);
+ if (Array.isArray(state)) {
+ let [type, value] = state;
+ entry.state = new GLib.Variant.new(type, value);
+ }
+
+ if (paramType !== undefined)
+ entry.parameter_type = GLib.VariantType.new(paramType);
- let action = new Gio.SimpleAction(entry);
+ action = new Gio.SimpleAction(entry);
- if(onActivate)
- action.connect('activate', onActivate);
- if(onChangeState)
- action.connect('change-state', onChangeState);
+ if (onActivate)
+ action.connect('activate', onActivate);
+ if (onChangeState)
+ action.connect('change-state', onChangeState);
+ }
return action;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]