Compare commits

...

1 Commits

Author SHA1 Message Date
Matthias Clasen
7fc5a894f9 Don't allow duplicate shortcuts for widget classes
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
2021-08-03 15:40:37 -04:00

View File

@@ -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`