[gtk/class-shortcut-conflicts] Don't allow duplicate shortcuts for widget classes




commit 7fc5a894f926b8193cc25e9d9c0849f89940b848
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Aug 3 15:38:13 2021 -0400

    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

 gtk/gtkwidget.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
---
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`


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]