[gimp/wip/Jehan/layers-dockable-refresh: 68/74] app: check selected items changed before running "select-items".




commit fb5ae91bc1042892aa5900a60c1685b89c4ac033
Author: Jehan <jehan girinstud io>
Date:   Tue Nov 2 17:38:28 2021 +0100

    app: check selected items changed before running "select-items".
    
    This prevents repeatitively running the same signals when it is useless.
    
    In particular, I encountered a case of infinite loops between
    "floating-selection-changed" and "select-items" ending up infinitely
    calling each other (then crashing GIMP).

 app/widgets/gimpcontainerview.c | 39 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)
---
diff --git a/app/widgets/gimpcontainerview.c b/app/widgets/gimpcontainerview.c
index 3e30826a88..faf11ae4dd 100644
--- a/app/widgets/gimpcontainerview.c
+++ b/app/widgets/gimpcontainerview.c
@@ -147,6 +147,9 @@ static gint  gimp_container_view_real_get_selected (GimpContainerView    *view,
                                                     GList               **list,
                                                     GList               **paths);
 
+static gboolean gimp_container_view_are_selected_items (GimpContainerView    *view,
+                                                        GList                *items);
+
 
 G_DEFINE_INTERFACE (GimpContainerView, gimp_container_view, GTK_TYPE_WIDGET)
 
@@ -645,8 +648,11 @@ gimp_container_view_select_items (GimpContainerView *view,
   if (gimp_container_frozen (private->container))
     return TRUE;
 
-  g_signal_emit (view, view_signals[SELECT_ITEMS], 0,
-                 viewables, NULL, &success);
+  if (gimp_container_view_are_selected_items (view, viewables))
+    success = TRUE;
+  else
+    g_signal_emit (view, view_signals[SELECT_ITEMS], 0,
+                   viewables, NULL, &success);
 
   return success;
 }
@@ -1474,3 +1480,32 @@ gimp_container_view_button_viewable_dropped (GtkWidget    *widget,
       gtk_button_clicked (GTK_BUTTON (widget));
     }
 }
+
+static gboolean
+gimp_container_view_are_selected_items (GimpContainerView *view,
+                                        GList             *items)
+{
+  GList    *selected;
+  gboolean  identical = FALSE;
+
+  gimp_container_view_get_selected (view, &selected, NULL);
+
+  if (g_list_length (items) == g_list_length (selected))
+    {
+      GList *iter;
+
+      identical = TRUE;
+      for (iter = items; iter; iter = iter->next)
+        {
+          if (g_list_find (selected, iter->data) == NULL)
+            {
+              identical = FALSE;
+              break;
+            }
+        }
+    }
+
+  g_list_free (selected);
+
+  return identical;
+}


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