[gnome-commander/get_rid_of_xml] Adding keybindings to gsettings
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander/get_rid_of_xml] Adding keybindings to gsettings
- Date: Thu, 24 Jan 2019 20:53:50 +0000 (UTC)
commit 63be66f8bc6d4d4014d9616b32d8ddb3f86b182b
Author: Uwe Scholz <u scholz83 gmx de>
Date: Thu Jan 24 21:51:59 2019 +0100
Adding keybindings to gsettings
data/org.gnome.gnome-commander.gschema.xml | 7 ++
src/gnome-cmd-data.cc | 113 +++++++++++++++++++++++++++++
src/gnome-cmd-data.h | 4 +
src/gnome-cmd-user-actions.h | 4 +-
4 files changed, 126 insertions(+), 2 deletions(-)
---
diff --git a/data/org.gnome.gnome-commander.gschema.xml b/data/org.gnome.gnome-commander.gschema.xml
index ea671af2..dbf1bd77 100644
--- a/data/org.gnome.gnome-commander.gschema.xml
+++ b/data/org.gnome.gnome-commander.gschema.xml
@@ -359,6 +359,13 @@
This option defines the width of the group column.
</description>
</key>
+ <key name="keybindings" type="a(sssbbbbbb)">
+ <default>[]</default>
+ <summary>List of keybindings</summary>
+ <description>
+ Each entry in this list represents a keybinding.
+ </description>
+ </key>
<!-- https://developer.gimp.org/api/2.0/gdk/gdk-Event-Structures.html#GdkWindowState -->
<key name="main-win-state" type="u">
<default>4</default>
diff --git a/src/gnome-cmd-data.cc b/src/gnome-cmd-data.cc
index 2a5ce559..31c27d40 100644
--- a/src/gnome-cmd-data.cc
+++ b/src/gnome-cmd-data.cc
@@ -1940,6 +1940,117 @@ void GnomeCmdData::save_connections()
}
+void GnomeCmdData::save_keybindings()
+{
+ GVariant* keybindingsToStore {nullptr};
+ GVariantBuilder gVariantBuilder;
+ g_variant_builder_init (&gVariantBuilder, G_VARIANT_TYPE_ARRAY);
+ gboolean hasKeybindings {false};
+
+ for (auto thisAction : gcmd_user_actions.action)
+ {
+ if (!ascii_isupper (thisAction.first)) // ignore lowercase keys as they duplicate uppercase ones
+ {
+ hasKeybindings = true;
+
+ guint state = thisAction.first.state;
+ guint key_val = thisAction.first.keyval;
+
+ string name;
+ string action;
+ string option;
+
+ if (ascii_isalnum (key_val))
+ name = (gchar) key_val;
+ else
+ name = gdk_key_names[key_val];
+
+ action = gcmd_user_actions.action_func[thisAction.second.func];
+
+ if (!thisAction.second.user_data.empty())
+ option = thisAction.second.user_data;
+
+ g_variant_builder_add (&gVariantBuilder, GCMD_SETTINGS_KEYBINDING_FORMAT_STRING,
+ name.c_str(),
+ action.c_str(),
+ option.c_str(),
+ state & GDK_SHIFT_MASK,
+ state & GDK_CONTROL_MASK,
+ state & GDK_MOD1_MASK,
+ state & GDK_SUPER_MASK,
+ state & GDK_HYPER_MASK,
+ state & GDK_META_MASK
+ );
+ }
+ }
+
+ if (hasKeybindings)
+ {
+ keybindingsToStore = g_variant_builder_end (&gVariantBuilder);
+ }
+ else
+ {
+ g_variant_builder_clear (&gVariantBuilder);
+ keybindingsToStore = g_settings_get_default_value (options.gcmd_settings->general,
GCMD_SETTINGS_KEYBINDINGS);
+ }
+ g_settings_set_value(options.gcmd_settings->general, GCMD_SETTINGS_KEYBINDINGS, keybindingsToStore);
+}
+
+
+void GnomeCmdData::load_keybindings()
+{
+ GVariant *gvKeybindings, *keybinding;
+ GVariantIter iter;
+
+ gvKeybindings = g_settings_get_value(options.gcmd_settings->general, GCMD_SETTINGS_KEYBINDINGS);
+
+ g_variant_iter_init (&iter, gvKeybindings);
+
+ while ((keybinding = g_variant_iter_next_value (&iter)) != NULL)
+ {
+ gchar *name, *action, *option;
+ gboolean shift, control, alt, super, hyper, meta;
+
+ g_assert (g_variant_is_of_type (keybinding, G_VARIANT_TYPE
(GCMD_SETTINGS_KEYBINDING_FORMAT_STRING)));
+ g_variant_get(keybinding, GCMD_SETTINGS_KEYBINDING_FORMAT_STRING,
+ &name, &action, &option, &shift, &control, &alt, &super, &hyper, &meta);
+
+ if (gcmd_user_actions.has_action(action))
+ {
+ auto keyval = gdk_key_names[name];
+
+ if (keyval == GDK_VoidSymbol)
+ {
+ if (strlen(name) == 1 && ascii_isalnum(*name))
+ {
+ keyval = *name;
+ }
+ }
+
+ if (keyval != GDK_VoidSymbol)
+ {
+ guint accel_mask = 0;
+ if (shift) accel_mask |= GDK_SHIFT_MASK;
+ if (control) accel_mask |= GDK_CONTROL_MASK;
+ if (alt) accel_mask |= GDK_MOD1_MASK;
+ if (super) accel_mask |= GDK_SUPER_MASK;
+ if (hyper) accel_mask |= GDK_HYPER_MASK;
+ if (meta) accel_mask |= GDK_META_MASK;
+
+ gcmd_user_actions.register_action(accel_mask, keyval, action, option);
+ }
+ else
+ g_warning ("<KeyBindings> invalid key name: '%s' - ignored", name);
+ }
+ else
+ g_warning ("<KeyBindings> unknown user action: '%s' - ignored", action);
+
+ g_variant_unref(keybinding);
+ }
+ g_variant_unref(gvKeybindings);
+}
+
+
/**
* Save favourite applications in the given file by means of GKeyFile.
*/
@@ -3656,6 +3767,7 @@ void GnomeCmdData::load()
load_search_profiles ();
load_connections ();
load_bookmarks ();
+ load_keybindings ();
if (load_fav_apps_old(FAV_APPS_FILENAME) == FALSE)
load_fav_apps_from_gsettings();
@@ -4006,6 +4118,7 @@ void GnomeCmdData::save()
save_search_profiles ();
save_connections ();
save_bookmarks ();
+ save_keybindings ();
save_advrename_profiles();
save_intviewer_defaults();
diff --git a/src/gnome-cmd-data.h b/src/gnome-cmd-data.h
index d02ce4d3..df74959e 100644
--- a/src/gnome-cmd-data.h
+++ b/src/gnome-cmd-data.h
@@ -141,6 +141,8 @@ GcmdSettings *gcmd_settings_new (void);
#define GCMD_SETTINGS_BOOKMARKS_WINDOW_HEIGHT "bookmarks-win-height"
#define GCMD_SETTINGS_CONNECTIONS "connections"
#define GCMD_SETTINGS_CONNECTION_FORMAT_STRING "(ss)"
+#define GCMD_SETTINGS_KEYBINDINGS "keybindings"
+#define GCMD_SETTINGS_KEYBINDING_FORMAT_STRING "(sssbbbbbb)"
#define GCMD_PREF_FILTER "org.gnome.gnome-commander.preferences.filter"
#define GCMD_SETTINGS_FILTER_HIDE_UNKNOWN "hide-unknown"
@@ -643,6 +645,8 @@ struct GnomeCmdData
void load_intviewer_defaults();
gboolean save_auto_load_plugins();
void load_bookmarks();
+ void load_keybindings();
+ void save_keybindings();
void load_connections();
void save_connections();
void save_cmdline_history();
diff --git a/src/gnome-cmd-user-actions.h b/src/gnome-cmd-user-actions.h
index 54a1f41d..2d0445e0 100644
--- a/src/gnome-cmd-user-actions.h
+++ b/src/gnome-cmd-user-actions.h
@@ -151,6 +151,8 @@ class GnomeCmdUserActions
UserAction(GnomeCmdUserActionFunc _func, const char *_user_data);
};
+ public:
+
static DICT<GnomeCmdUserActionFunc> action_func;
static DICT<GnomeCmdUserActionFunc> action_name;
@@ -159,8 +161,6 @@ class GnomeCmdUserActions
ACTIONS_COLL action;
- public:
-
void init();
void set_defaults();
void shutdown();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]