[gimp] app: check selected items changed before running "select-items".



commit ca3c4803146cb8fac1dfbb5ecd241035f54372a8
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 3d1d158594..fcd271bbef 100644
--- a/app/widgets/gimpcontainerview.c
+++ b/app/widgets/gimpcontainerview.c
@@ -146,6 +146,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)
 
@@ -632,8 +635,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;
 }
@@ -1430,3 +1436,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]