shortcutcontroller: Add a way to update accels

This will be used to make accel changes propagate.
This commit is contained in:
Matthias Clasen 2021-06-17 08:31:13 -04:00
parent d5054f9b99
commit 3254a3feab
2 changed files with 19 additions and 5 deletions

View File

@ -480,16 +480,17 @@ update_accel (GtkShortcut *shortcut,
g_free (accel);
}
static void
gtk_shortcut_controller_set_widget (GtkEventController *controller,
GtkWidget *widget)
void
gtk_shortcut_controller_update_accels (GtkShortcutController *self)
{
GtkShortcutController *self = GTK_SHORTCUT_CONTROLLER (controller);
GListModel *shortcuts = self->shortcuts;
GtkWidget *widget;
GtkActionMuxer *muxer;
guint i, p;
GTK_EVENT_CONTROLLER_CLASS (gtk_shortcut_controller_parent_class)->set_widget (controller, widget);
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (self));
if (!widget)
return;
muxer = _gtk_widget_get_action_muxer (widget, TRUE);
for (i = 0, p = g_list_model_get_n_items (shortcuts); i < p; i++)
@ -499,6 +500,17 @@ gtk_shortcut_controller_set_widget (GtkEventController *controller,
update_accel (shortcut, muxer, TRUE);
g_object_unref (shortcut);
}
}
static void
gtk_shortcut_controller_set_widget (GtkEventController *controller,
GtkWidget *widget)
{
GtkShortcutController *self = GTK_SHORTCUT_CONTROLLER (controller);
GTK_EVENT_CONTROLLER_CLASS (gtk_shortcut_controller_parent_class)->set_widget (controller, widget);
gtk_shortcut_controller_update_accels (self);
if (_gtk_widget_get_root (widget))
gtk_shortcut_controller_root (self);

View File

@ -25,4 +25,6 @@
void gtk_shortcut_controller_root (GtkShortcutController *controller);
void gtk_shortcut_controller_unroot (GtkShortcutController *controller);
void gtk_shortcut_controller_update_accels (GtkShortcutController *self);
#endif /* __GTK_SHORTCUT_CONTROLLER_H__ */