mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-26 21:51:08 +00:00
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.
This commit is contained in:
parent
a1e9ae5259
commit
3cd4eb0310
@ -53,7 +53,6 @@ struct _GtkShortcutController
|
||||
GdkModifierType mnemonics_modifiers;
|
||||
|
||||
guint custom_shortcuts : 1;
|
||||
guint run_class : 1;
|
||||
guint run_managed : 1;
|
||||
};
|
||||
|
||||
@ -246,17 +245,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);
|
||||
@ -495,13 +483,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)
|
||||
|
@ -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);
|
||||
|
||||
|
@ -769,9 +769,29 @@ static void
|
||||
gtk_widget_base_class_init (gpointer g_class)
|
||||
{
|
||||
GtkWidgetClass *klass = g_class;
|
||||
GtkWidgetClassPrivate *priv;
|
||||
|
||||
klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
|
||||
klass->priv->template = NULL;
|
||||
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;
|
||||
|
||||
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
|
||||
@ -1721,8 +1741,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
|
||||
@ -2438,9 +2459,8 @@ 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 ();
|
||||
controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (GTK_WIDGET_CLASS (g_class)->priv->shortcuts));
|
||||
gtk_event_controller_set_name (controller, "gtk-widget-class-shortcuts");
|
||||
gtk_shortcut_controller_set_run_class (GTK_SHORTCUT_CONTROLLER (controller), TRUE);
|
||||
gtk_widget_add_controller (widget, controller);
|
||||
}
|
||||
|
||||
@ -4506,13 +4526,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
|
||||
|
@ -211,7 +211,7 @@ typedef struct
|
||||
struct _GtkWidgetClassPrivate
|
||||
{
|
||||
GtkWidgetTemplate *template;
|
||||
GSList *shortcuts;
|
||||
GListStore *shortcuts;
|
||||
GType accessible_type;
|
||||
AtkRole accessible_role;
|
||||
GQuark css_name;
|
||||
@ -248,8 +248,6 @@ void _gtk_widget_add_attached_window (GtkWidget *widget,
|
||||
void _gtk_widget_remove_attached_window (GtkWidget *widget,
|
||||
GtkWindow *window);
|
||||
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user