[libdazzle] shortcuts: add helper to check for match in context



commit 2d19578174def63d827122c031b4d95fa99b8949
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jul 19 23:34:17 2017 -0700

    shortcuts: add helper to check for match in context
    
    This can be useful to avoid re-adding controller items when
    creating them dynamically at runtime.

 src/shortcuts/dzl-shortcut-context.c |   14 ++++++++++++++
 src/shortcuts/dzl-shortcut-private.h |    2 ++
 2 files changed, 16 insertions(+), 0 deletions(-)
---
diff --git a/src/shortcuts/dzl-shortcut-context.c b/src/shortcuts/dzl-shortcut-context.c
index aae7c4c..66f944a 100644
--- a/src/shortcuts/dzl-shortcut-context.c
+++ b/src/shortcuts/dzl-shortcut-context.c
@@ -175,6 +175,20 @@ dzl_shortcut_context_get_name (DzlShortcutContext *self)
   return priv->name;
 }
 
+gboolean
+_dzl_shortcut_context_contains (DzlShortcutContext     *self,
+                                const DzlShortcutChord *chord)
+{
+  DzlShortcutContextPrivate *priv = dzl_shortcut_context_get_instance_private (self);
+  gpointer data;
+
+  g_return_val_if_fail (DZL_IS_SHORTCUT_CONTEXT (self), FALSE);
+  g_return_val_if_fail (chord != NULL, FALSE);
+
+  return priv->table != NULL &&
+         dzl_shortcut_chord_table_lookup (priv->table, chord, &data) == DZL_SHORTCUT_MATCH_EQUAL;
+}
+
 DzlShortcutMatch
 dzl_shortcut_context_activate (DzlShortcutContext     *self,
                                GtkWidget              *widget,
diff --git a/src/shortcuts/dzl-shortcut-private.h b/src/shortcuts/dzl-shortcut-private.h
index 5d58c72..3e1f399 100644
--- a/src/shortcuts/dzl-shortcut-private.h
+++ b/src/shortcuts/dzl-shortcut-private.h
@@ -132,6 +132,8 @@ DzlShortcutMatch       _dzl_shortcut_theme_match                    (DzlShortcut
                                                                      DzlShortcutPhase            phase,
                                                                      const DzlShortcutChord     *chord,
                                                                      DzlShortcutClosureChain   **chain);
+gboolean               _dzl_shortcut_context_contains               (DzlShortcutContext         *self,
+                                                                     const DzlShortcutChord     *chord);
 DzlShortcutChordTable *_dzl_shortcut_context_get_table              (DzlShortcutContext         *self);
 void                   _dzl_shortcut_context_merge                  (DzlShortcutContext         *self,
                                                                      DzlShortcutContext         *layer);


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