[libdazzle/libdazzle-3-26] shortcuts: activate default actions from theme



commit 0cc53ebf697990a59eabf93be2f7b4f4a77863f6
Author: Christian Hergert <chergert redhat com>
Date:   Tue Nov 21 18:43:57 2017 -0800

    shortcuts: activate default actions from theme
    
    If we have actions defined in the theme instead of in the
    GtkApplication action registration, we might need to find these
    in the internal theme.

 src/shortcuts/dzl-shortcut-manager.c |   28 +++++++++++++++++++++++++++-
 1 files changed, 27 insertions(+), 1 deletions(-)
---
diff --git a/src/shortcuts/dzl-shortcut-manager.c b/src/shortcuts/dzl-shortcut-manager.c
index 35c5e7a..7452bda 100644
--- a/src/shortcuts/dzl-shortcut-manager.c
+++ b/src/shortcuts/dzl-shortcut-manager.c
@@ -804,6 +804,8 @@ dzl_shortcut_manager_run_fallbacks (DzlShortcutManager     *self,
                                     GtkWidget              *toplevel,
                                     const DzlShortcutChord *chord)
 {
+  DzlShortcutManagerPrivate *priv = dzl_shortcut_manager_get_instance_private (self);
+
   g_assert (DZL_IS_SHORTCUT_MANAGER (self));
   g_assert (GTK_IS_WIDGET (widget));
   g_assert (GTK_IS_WIDGET (toplevel));
@@ -812,6 +814,7 @@ dzl_shortcut_manager_run_fallbacks (DzlShortcutManager     *self,
   if (dzl_shortcut_chord_get_length (chord) == 1)
     {
       GApplication *app = g_application_get_default ();
+      const gchar *action;
       GdkModifierType state;
       guint keyval;
 
@@ -826,6 +829,28 @@ dzl_shortcut_manager_run_fallbacks (DzlShortcutManager     *self,
           gtk_window_mnemonic_activate (GTK_WINDOW (toplevel), keyval, state))
         return TRUE;
 
+      /*
+       * See if we have something defined for this theme that
+       * can be activated directly.
+       */
+      action = _dzl_shortcut_theme_lookup_action (priv->internal_theme, chord);
+
+      if (action != NULL)
+        {
+          g_autofree gchar *prefix = NULL;
+          g_autofree gchar *name = NULL;
+          g_autoptr(GVariant) target = NULL;
+
+          dzl_g_action_name_parse_full (action, &prefix, &name, &target);
+
+          if (dzl_gtk_widget_action (toplevel, prefix, name, target))
+            return TRUE;
+        }
+
+      /*
+       * Now fallback to trying to activate the action within GtkApplication
+       * as the legacy Gtk bindings would do.
+       */
       if (GTK_IS_APPLICATION (app))
         {
           g_autofree gchar *accel = dzl_shortcut_chord_to_string (chord);
@@ -837,11 +862,12 @@ dzl_shortcut_manager_run_fallbacks (DzlShortcutManager     *self,
             {
               for (guint i = 0; actions[i] != NULL; i++)
                 {
-                  const gchar *action = actions[i];
                   g_autofree gchar *prefix = NULL;
                   g_autofree gchar *name = NULL;
                   g_autoptr(GVariant) param = NULL;
 
+                  action = actions[i];
+
                   if (!dzl_g_action_name_parse_full (action, &prefix, &name, &param))
                     {
                       g_warning ("Failed to parse: %s", action);


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