[gtk/gbsneto/shortcuts-rebased: 84/105] widget: Keep keybindings as a GListStore
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/gbsneto/shortcuts-rebased: 84/105] widget: Keep keybindings as a GListStore
- Date: Tue, 14 May 2019 15:10:14 +0000 (UTC)
commit 254bdfbbc372f82f2af39d1a01531ee222d31614
Author: Benjamin Otte <otte redhat com>
Date: Mon Aug 20 04:18:28 2018 +0200
widget: Keep keybindings as a GListStore
This way, we can use shortcut_controller_new_for_model() and avoid all
the special casing about run_class.
gtk/gtkshortcutcontroller.c | 19 ------------------
gtk/gtkshortcutcontrollerprivate.h | 2 --
gtk/gtkwidget.c | 40 +++++++++++++++++++++++++-------------
gtk/gtkwidgetprivate.h | 2 --
4 files changed, 27 insertions(+), 36 deletions(-)
---
diff --git a/gtk/gtkshortcutcontroller.c b/gtk/gtkshortcutcontroller.c
index f037661916..b2417d15bc 100644
--- a/gtk/gtkshortcutcontroller.c
+++ b/gtk/gtkshortcutcontroller.c
@@ -53,7 +53,6 @@ struct _GtkShortcutController
GdkModifierType mnemonics_modifiers;
guint custom_shortcuts : 1;
- guint run_class : 1;
guint run_managed : 1;
};
@@ -244,17 +243,6 @@ gtk_shortcut_controller_run_controllers (GtkEventController *controller,
return TRUE;
}
- if (self->run_class)
- {
- widget = gtk_event_controller_get_widget (controller);
-
- for (l = gtk_widget_class_get_shortcuts (GTK_WIDGET_GET_CLASS (widget)); l; l = l->next)
- {
- if (gtk_shortcut_controller_trigger_shortcut (self, l->data, event, enable_mnemonics))
- return TRUE;
- }
- }
-
if (self->run_managed)
{
GtkPropagationPhase current_phase = gtk_event_controller_get_propagation_phase (controller);
@@ -467,13 +455,6 @@ gtk_shortcut_controller_new_for_model (GListModel *model)
NULL);
}
-void
-gtk_shortcut_controller_set_run_class (GtkShortcutController *controller,
- gboolean run_class)
-{
- controller->run_class = run_class;
-}
-
void
gtk_shortcut_controller_set_run_managed (GtkShortcutController *controller,
gboolean run_managed)
diff --git a/gtk/gtkshortcutcontrollerprivate.h b/gtk/gtkshortcutcontrollerprivate.h
index 42594ea6eb..a7086cd678 100644
--- a/gtk/gtkshortcutcontrollerprivate.h
+++ b/gtk/gtkshortcutcontrollerprivate.h
@@ -22,8 +22,6 @@
#include "gtkshortcutcontroller.h"
-void gtk_shortcut_controller_set_run_class (GtkShortcutController *controller,
- gboolean run_class);
void gtk_shortcut_controller_set_run_managed (GtkShortcutController *controller,
gboolean
run_managed);
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 2d5b2f97d1..b35c1dd56b 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -496,7 +496,7 @@ typedef struct {
struct _GtkWidgetClassPrivate
{
GtkWidgetTemplate *template;
- GSList *shortcuts;
+ GListStore *shortcuts;
GType accessible_type;
AtkRole accessible_role;
const char *css_name;
@@ -796,9 +796,29 @@ static void
gtk_widget_base_class_init (gpointer g_class)
{
GtkWidgetClass *klass = g_class;
+ GtkWidgetClassPrivate *priv;
+
+ priv = klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
+
+ priv->template = NULL;
+
+ if (priv->shortcuts == NULL)
+ {
+ priv->shortcuts = g_list_store_new (GTK_TYPE_SHORTCUT);
+ }
+ else
+ {
+ GListModel *parent_shortcuts = G_LIST_MODEL (priv->shortcuts);
+ guint i;
- klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
- klass->priv->template = NULL;
+ priv->shortcuts = g_list_store_new (GTK_TYPE_SHORTCUT);
+ for (i = 0; i < g_list_model_get_n_items (parent_shortcuts); i++)
+ {
+ GtkShortcut *shortcut = g_list_model_get_item (parent_shortcuts, i);
+ g_list_store_append (priv->shortcuts, shortcut);
+ g_object_unref (shortcut);
+ }
+ }
}
static void
@@ -2131,8 +2151,9 @@ gtk_widget_class_init (GtkWidgetClass *klass)
static void
gtk_widget_base_class_finalize (GtkWidgetClass *klass)
{
+
template_data_free (klass->priv->template);
- g_slist_free_full (klass->priv->shortcuts, g_object_unref);
+ g_object_unref (klass->priv->shortcuts);
}
static void
@@ -2850,8 +2871,7 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
if (layout_manager_type != G_TYPE_INVALID)
gtk_widget_set_layout_manager (widget, g_object_new (layout_manager_type, NULL));
- controller = gtk_shortcut_controller_new ();
- gtk_shortcut_controller_set_run_class (GTK_SHORTCUT_CONTROLLER (controller), TRUE);
+ controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (GTK_WIDGET_CLASS
(g_class)->priv->shortcuts));
gtk_widget_add_controller (widget, controller);
}
@@ -4926,13 +4946,7 @@ gtk_widget_class_add_shortcut (GtkWidgetClass *widget_class,
priv = widget_class->priv;
- priv->shortcuts = g_slist_prepend (priv->shortcuts, g_object_ref (shortcut));
-}
-
-const GSList *
-gtk_widget_class_get_shortcuts (GtkWidgetClass *widget_class)
-{
- return widget_class->priv->shortcuts;
+ g_list_store_append (priv->shortcuts, shortcut);
}
static gboolean
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index 937cd672dc..061ab2e944 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -244,8 +244,6 @@ void _gtk_widget_get_preferred_size_and_baseline(GtkWidget *widget,
const gchar* _gtk_widget_get_accel_path (GtkWidget *widget,
gboolean *locked);
-const GSList * gtk_widget_class_get_shortcuts (GtkWidgetClass *widget_class);
-
AtkObject * _gtk_widget_peek_accessible (GtkWidget *widget);
void _gtk_widget_set_has_default (GtkWidget *widget,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]