[gnome-builder/wip/gtk4-port] libide/gui: setup shortcuts in specific phases



commit c88b6197fa40b4f3dfaa4a84750fc7a935825728
Author: Christian Hergert <chergert redhat com>
Date:   Thu May 5 17:54:13 2022 -0700

    libide/gui: setup shortcuts in specific phases

 src/libide/gui/ide-shortcut-bundle.c |  1 +
 src/libide/gui/ide-workbench.c       | 35 +++++++++++++++++++++++++++++++----
 2 files changed, 32 insertions(+), 4 deletions(-)
---
diff --git a/src/libide/gui/ide-shortcut-bundle.c b/src/libide/gui/ide-shortcut-bundle.c
index 208ddf9d8..b8136df36 100644
--- a/src/libide/gui/ide-shortcut-bundle.c
+++ b/src/libide/gui/ide-shortcut-bundle.c
@@ -405,6 +405,7 @@ populate_from_object (IdeShortcutBundle  *self,
                                       (GDestroyNotify) ide_shortcut_free);
   shortcut = gtk_shortcut_new (g_steal_pointer (&trigger),
                                g_steal_pointer (&callback));
+  g_object_set_data (G_OBJECT (shortcut), "PHASE", GINT_TO_POINTER (phase));
   g_ptr_array_add (self->items, g_steal_pointer (&shortcut));
 
   return TRUE;
diff --git a/src/libide/gui/ide-workbench.c b/src/libide/gui/ide-workbench.c
index 5c35aa121..d9c35de8b 100644
--- a/src/libide/gui/ide-workbench.c
+++ b/src/libide/gui/ide-workbench.c
@@ -773,6 +773,21 @@ insert_action_groups_foreach_cb (IdeWorkspace *workspace,
     }
 }
 
+static gboolean
+shortcut_phase_filter (gpointer item,
+                       gpointer user_data)
+{
+  return g_object_get_data (item, "PHASE") == user_data;
+}
+
+static GtkFilter *
+create_shortcut_filter (GtkPropagationPhase phase)
+{
+  return GTK_FILTER (gtk_custom_filter_new (shortcut_phase_filter,
+                                            GINT_TO_POINTER (phase),
+                                            NULL));
+}
+
 /**
  * ide_workbench_add_workspace:
  * @self: an #IdeWorkbench
@@ -785,6 +800,8 @@ ide_workbench_add_workspace (IdeWorkbench *self,
                              IdeWorkspace *workspace)
 {
   g_autoptr(GPtrArray) addins = NULL;
+  g_autoptr(GtkFilterListModel) capture = NULL;
+  g_autoptr(GtkFilterListModel) bubble = NULL;
   IdeCommandManager *command_manager;
   GtkEventController *shortcuts;
   GList *mru_link;
@@ -829,10 +846,20 @@ ide_workbench_add_workspace (IdeWorkbench *self,
   if (self->project_info != NULL)
     insert_action_groups_foreach_cb (workspace, self);
 
-  /* Setup shortcut controller for workspace */
-  /* TODO: do separate for capture/bubble w/ filter list model */
-  shortcuts = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (self->shortcuts));
-  gtk_event_controller_set_name (shortcuts, "ide-shortcuts");
+  /* Setup capture shortcut controller for workspace */
+  capture = gtk_filter_list_model_new (g_object_ref (G_LIST_MODEL (self->shortcuts)),
+                                       create_shortcut_filter (GTK_PHASE_CAPTURE));
+  shortcuts = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (g_steal_pointer (&capture)));
+  gtk_event_controller_set_name (shortcuts, "ide-shortcuts-capture");
+  gtk_event_controller_set_propagation_phase (shortcuts, GTK_PHASE_CAPTURE);
+  gtk_widget_add_controller (GTK_WIDGET (workspace), shortcuts);
+
+  /* Setup bubble shortcut controller for workspace */
+  bubble = gtk_filter_list_model_new (g_object_ref (G_LIST_MODEL (self->shortcuts)),
+                                      create_shortcut_filter (GTK_PHASE_BUBBLE));
+  shortcuts = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (g_steal_pointer (&bubble)));
+  gtk_event_controller_set_name (shortcuts, "ide-shortcuts-bubble");
+  gtk_event_controller_set_propagation_phase (shortcuts, GTK_PHASE_BUBBLE);
   gtk_widget_add_controller (GTK_WIDGET (workspace), shortcuts);
 
   /* Track toplevel focus changes to maintain a most-recently-used queue. */


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