diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-08-03 15:38:13 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-08-03 15:40:37 -0400 |
commit | 7fc5a894f926b8193cc25e9d9c0849f89940b848 (patch) | |
tree | 542d45c1c2131d1df87f2edba9cc35578fa5c6ff | |
parent | ca547b87168f2a1354af099464a76f670b5973e9 (diff) | |
download | gtk+-class-shortcut-conflicts.tar.gz |
Don't allow duplicate shortcuts for widget classesclass-shortcut-conflicts
Make gtk_widget_class_add_shortcut() remove an existing
shortcut with the same trigger before adding the new
shortcut. Whenever this happens, this is most likely
the intention.
Fixes: #4130
-rw-r--r-- | gtk/gtkwidget.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index a032876e55..2186e34c97 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -4425,9 +4425,21 @@ gtk_widget_class_add_shortcut (GtkWidgetClass *widget_class, priv = widget_class->priv; + for (int i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (priv->shortcuts)); i++) + { + GObject *s = g_list_model_get_item (G_LIST_MODEL (priv->shortcuts), i); + + g_object_unref (s); + if (gtk_shortcut_trigger_equal (gtk_shortcut_get_trigger (GTK_SHORTCUT (s)), + gtk_shortcut_get_trigger (shortcut))) + { + g_list_store_remove (priv->shortcuts, i); + break; + } + } + g_list_store_append (priv->shortcuts, shortcut); } - /** * gtk_widget_mnemonic_activate: * @widget: a `GtkWidget` |