[libdazzle] shortcuts: add dzl_shortcut_controller_remove_accel()
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libdazzle] shortcuts: add dzl_shortcut_controller_remove_accel()
- Date: Sun, 11 Aug 2019 03:43:08 +0000 (UTC)
commit e11c2e483074c43bd3f6bbdeb1e657b9f66e4e8d
Author: Christian Hergert <chergert redhat com>
Date: Sat Aug 10 20:42:48 2019 -0700
shortcuts: add dzl_shortcut_controller_remove_accel()
This is a helper to remove accels based on previously added commands. It
is mostly just useful for auto-generated keybindings situations.
src/shortcuts/dzl-shortcut-controller.c | 37 +++++++++++++++++++++++++++++++++
src/shortcuts/dzl-shortcut-controller.h | 4 ++++
2 files changed, 41 insertions(+)
---
diff --git a/src/shortcuts/dzl-shortcut-controller.c b/src/shortcuts/dzl-shortcut-controller.c
index 03b3578..7019f40 100644
--- a/src/shortcuts/dzl-shortcut-controller.c
+++ b/src/shortcuts/dzl-shortcut-controller.c
@@ -1248,3 +1248,40 @@ dzl_shortcut_controller_get_widget (DzlShortcutController *self)
return priv->widget;
}
+
+void
+dzl_shortcut_controller_remove_accel (DzlShortcutController *self,
+ const gchar *accel,
+ DzlShortcutPhase phase)
+{
+ DzlShortcutControllerPrivate *priv = dzl_shortcut_controller_get_instance_private (self);
+ g_autoptr(DzlShortcutChord) chord = NULL;
+
+ g_return_if_fail (DZL_IS_SHORTCUT_CONTROLLER (self));
+ g_return_if_fail (accel != NULL);
+
+ chord = dzl_shortcut_chord_new_from_string (accel);
+
+ if (chord != NULL)
+ {
+ DzlShortcutContext *context;
+ DzlShortcutManager *manager;
+ DzlShortcutTheme *theme;
+
+ /* Add the chord to our chord table for lookups */
+ if (priv->commands_table != NULL)
+ dzl_shortcut_chord_table_remove (priv->commands_table, chord);
+
+ /* Set the value in the theme so it can have overrides by users */
+ manager = dzl_shortcut_controller_get_manager (self);
+ theme = _dzl_shortcut_manager_get_internal_theme (manager);
+ dzl_shortcut_theme_set_chord_for_command (theme, NULL, chord, 0);
+
+ if (priv->widget != NULL)
+ {
+ context = _dzl_shortcut_theme_find_default_context_with_phase (theme, priv->widget, phase);
+ if (context && _dzl_shortcut_context_contains (context, chord))
+ dzl_shortcut_context_remove (context, accel);
+ }
+ }
+}
diff --git a/src/shortcuts/dzl-shortcut-controller.h b/src/shortcuts/dzl-shortcut-controller.h
index 73bd6d5..fd8e7af 100644
--- a/src/shortcuts/dzl-shortcut-controller.h
+++ b/src/shortcuts/dzl-shortcut-controller.h
@@ -60,6 +60,10 @@ gboolean dzl_shortcut_controller_execute_command (DzlShortc
const gchar *command);
DZL_AVAILABLE_IN_ALL
const DzlShortcutChord *dzl_shortcut_controller_get_current_chord (DzlShortcutController *self);
+DZL_AVAILABLE_IN_3_34
+void dzl_shortcut_controller_remove_accel (DzlShortcutController *self,
+ const gchar *accel,
+ DzlShortcutPhase phase);
DZL_AVAILABLE_IN_ALL
void dzl_shortcut_controller_add_command_action (DzlShortcutController *self,
const gchar *command_id,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]