[gimp/wip/Jehan/layers-dockable-refresh: 36/70] app: more "select-item" signal handlers changed to "select-items" ones.




commit 6d362a2df317db99c5c0723936f5769b27d6666d
Author: Jehan <jehan girinstud io>
Date:   Fri Jun 11 22:01:35 2021 +0200

    app: more "select-item" signal handlers changed to "select-items" ones.

 app/dialogs/layer-add-mask-dialog.c | 14 ++++++------
 app/dialogs/preferences-dialog.c    | 20 ++++++++++-------
 app/widgets/gimpcontainercombobox.c | 24 ++++++++++++++++++++-
 app/widgets/gimpcontainerview.c     | 27 +++++++++++------------
 app/widgets/gimpitemtreeview.c      | 30 +++++++++++++++-----------
 app/widgets/gimpsettingsbox.c       |  2 +-
 app/widgets/gimptooleditor.c        |  2 +-
 app/widgets/gimpundoeditor.c        | 43 +++++++++++++++++++++----------------
 8 files changed, 101 insertions(+), 61 deletions(-)
---
diff --git a/app/dialogs/layer-add-mask-dialog.c b/app/dialogs/layer-add-mask-dialog.c
index 9c2ff78c50..77f12627b5 100644
--- a/app/dialogs/layer-add-mask-dialog.c
+++ b/app/dialogs/layer-add-mask-dialog.c
@@ -62,8 +62,8 @@ static void       layer_add_mask_dialog_response         (GtkWidget          *di
                                                           gint                response_id,
                                                           LayerAddMaskDialog *private);
 static gboolean   layer_add_mask_dialog_channel_selected (GimpContainerView  *view,
-                                                          GimpViewable       *viewable,
-                                                          gpointer            insert_data,
+                                                          GList              *viewables,
+                                                          GList              *paths,
                                                           LayerAddMaskDialog *dialog);
 
 
@@ -165,7 +165,7 @@ layer_add_mask_dialog_new (GList               *layers,
                              GIMP_ADD_MASK_CHANNEL, TRUE);
   gtk_widget_show (combo);
 
-  g_signal_connect (combo, "select-item",
+  g_signal_connect (combo, "select-items",
                     G_CALLBACK (layer_add_mask_dialog_channel_selected),
                     private);
 
@@ -231,11 +231,13 @@ layer_add_mask_dialog_response (GtkWidget          *dialog,
 
 static gboolean
 layer_add_mask_dialog_channel_selected (GimpContainerView  *view,
-                                        GimpViewable       *viewable,
-                                        gpointer            insert_data,
+                                        GList              *viewables,
+                                        GList              *paths,
                                         LayerAddMaskDialog *private)
 {
-  private->channel = GIMP_CHANNEL (viewable);
+  g_return_val_if_fail (g_list_length (viewables) < 2, FALSE);
+
+  private->channel = viewables? GIMP_CHANNEL (viewables->data) : NULL;
 
   return TRUE;
 }
diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c
index ad07a7252c..27e9a60060 100644
--- a/app/dialogs/preferences-dialog.c
+++ b/app/dialogs/preferences-dialog.c
@@ -514,20 +514,24 @@ prefs_path_reset (GtkWidget *widget,
     gimp_config_reset_property (config, writable_property);
 }
 
-static void
+static gboolean
 prefs_template_select_callback (GimpContainerView *view,
-                                GimpTemplate      *template,
-                                gpointer           insert_data,
+                                GList             *templates,
+                                GList             *paths,
                                 GimpTemplate      *edit_template)
 {
-  if (template)
+  g_return_val_if_fail (g_list_length (templates) < 2, FALSE);
+
+  if (templates)
     {
       /*  make sure the resolution values are copied first (see bug #546924)  */
-      gimp_config_sync (G_OBJECT (template), G_OBJECT (edit_template),
+      gimp_config_sync (G_OBJECT (templates->data), G_OBJECT (edit_template),
                         GIMP_TEMPLATE_PARAM_COPY_FIRST);
-      gimp_config_sync (G_OBJECT (template), G_OBJECT (edit_template),
+      gimp_config_sync (G_OBJECT (templates->data), G_OBJECT (edit_template),
                         0);
     }
+
+  return TRUE;
 }
 
 static void
@@ -1795,9 +1799,9 @@ prefs_dialog_new (Gimp       *gimp,
                                _("_Template:"),  0.0, 0.5,
                                combo, 1);
 
-    gimp_container_view_select_item (GIMP_CONTAINER_VIEW (combo), NULL);
+    gimp_container_view_select_items (GIMP_CONTAINER_VIEW (combo), NULL);
 
-    g_signal_connect (combo, "select-item",
+    g_signal_connect (combo, "select-items",
                       G_CALLBACK (prefs_template_select_callback),
                       core_config->default_image);
   }
diff --git a/app/widgets/gimpcontainercombobox.c b/app/widgets/gimpcontainercombobox.c
index 16b1ab9fe3..42f5c7c464 100644
--- a/app/widgets/gimpcontainercombobox.c
+++ b/app/widgets/gimpcontainercombobox.c
@@ -403,7 +403,29 @@ gimp_container_combo_box_select_items (GimpContainerView *view,
 
       if (viewables)
         {
-          gimp_container_view_item_selected (view, viewables->data);
+          GtkTreeModel *model = gtk_combo_box_get_model (GTK_COMBO_BOX (view));
+          GtkTreeIter   iter;
+          gboolean      iter_valid;
+
+          for (iter_valid = gtk_tree_model_get_iter_first (model, &iter);
+               iter_valid;
+               iter_valid = gtk_tree_model_iter_next (model, &iter))
+            {
+              GimpViewRenderer *renderer;
+
+              gtk_tree_model_get (model, &iter,
+                                  GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER, &renderer,
+                                  -1);
+
+              if (renderer->viewable == viewables->data)
+                {
+                  gtk_combo_box_set_active_iter (combo_box, &iter);
+                  g_object_unref (renderer);
+
+                  break;
+                }
+              g_object_unref (renderer);
+            }
         }
       else
         {
diff --git a/app/widgets/gimpcontainerview.c b/app/widgets/gimpcontainerview.c
index 9f8ac1e354..46e3a8b865 100644
--- a/app/widgets/gimpcontainerview.c
+++ b/app/widgets/gimpcontainerview.c
@@ -412,7 +412,7 @@ gimp_container_view_real_set_container (GimpContainerView *view,
       if (private->context)
         gimp_container_view_disconnect_context (view);
 
-      gimp_container_view_select_item (view, NULL);
+      gimp_container_view_select_items (view, NULL);
 
       /* freeze/thaw is only supported for the toplevel container */
       g_signal_handlers_disconnect_by_func (private->container,
@@ -664,26 +664,25 @@ gimp_container_view_select_items (GimpContainerView *view,
   return success;
 }
 
+/* Mostly a convenience function calling the more generic
+ * gimp_container_view_select_items().
+ * This is to be used when you want to select one viewable only (or
+ * because the container this is called from only handles single
+ * selection anyway).
+ */
 gboolean
 gimp_container_view_select_item (GimpContainerView *view,
                                  GimpViewable      *viewable)
 {
-  GimpContainerViewPrivate *private;
-  gboolean                  success = FALSE;
-  gpointer                  insert_data;
-
-  g_return_val_if_fail (GIMP_IS_CONTAINER_VIEW (view), FALSE);
-  g_return_val_if_fail (viewable == NULL || GIMP_IS_VIEWABLE (viewable), FALSE);
-
-  private = GIMP_CONTAINER_VIEW_GET_PRIVATE (view);
+  GList    *viewables = NULL;
+  gboolean  success;
 
-  if (gimp_container_frozen (private->container))
-    return TRUE;
+  if (viewable)
+    viewables = g_list_prepend (viewables, viewable);
 
-  insert_data = g_hash_table_lookup (private->item_hash, viewable);
+  success = gimp_container_view_select_items (view, viewables);
 
-  g_signal_emit (view, view_signals[SELECT_ITEM], 0,
-                 viewable, insert_data, &success);
+  g_list_free (viewables);
 
   return success;
 }
diff --git a/app/widgets/gimpitemtreeview.c b/app/widgets/gimpitemtreeview.c
index e6fe065b4d..3b00941fff 100644
--- a/app/widgets/gimpitemtreeview.c
+++ b/app/widgets/gimpitemtreeview.c
@@ -2065,15 +2065,13 @@ gimp_item_tree_view_row_expanded (GtkTreeView      *tree_view,
                                   GimpItemTreeView *item_view)
 {
   GimpItemTreeViewClass *item_view_class;
-  GimpItem              *active_item;
+  GList                 *selected_items;
+  GList                 *list;
 
   item_view_class = GIMP_ITEM_TREE_VIEW_GET_CLASS (item_view);
-  active_item = item_view_class->get_active_item (item_view->priv->image);
+  selected_items  = item_view_class->get_selected_items (item_view->priv->image);
 
-  /*  don't select the item while it is being inserted  */
-  if (active_item &&
-      gimp_container_view_lookup (GIMP_CONTAINER_VIEW (item_view),
-                                  GIMP_VIEWABLE (active_item)))
+  if (selected_items)
     {
       GimpViewRenderer *renderer;
       GimpItem         *expanded_item;
@@ -2084,14 +2082,22 @@ gimp_item_tree_view_row_expanded (GtkTreeView      *tree_view,
       expanded_item = GIMP_ITEM (renderer->viewable);
       g_object_unref (renderer);
 
-      /*  select the active item only if it was made visible by expanding
-       *  its immediate parent. See bug #666561.
-       */
-      if (gimp_item_get_parent (active_item) == expanded_item)
+      for (list = selected_items; list; list = list->next)
         {
-          gimp_container_view_select_item (GIMP_CONTAINER_VIEW (item_view),
-                                           GIMP_VIEWABLE (active_item));
+          /*  don't select an item while it is being inserted  */
+          if (! gimp_container_view_lookup (GIMP_CONTAINER_VIEW (item_view),
+                                            list->data))
+            return;
+
+          /*  select items only if they were made visible by expanding
+           *  their immediate parent. See bug #666561.
+           */
+          if (gimp_item_get_parent (list->data) != expanded_item)
+            return;
         }
+
+      gimp_container_view_select_items (GIMP_CONTAINER_VIEW (item_view),
+                                        selected_items);
     }
 }
 
diff --git a/app/widgets/gimpsettingsbox.c b/app/widgets/gimpsettingsbox.c
index a0190b2c34..8f4f3c8d20 100644
--- a/app/widgets/gimpsettingsbox.c
+++ b/app/widgets/gimpsettingsbox.c
@@ -968,5 +968,5 @@ gimp_settings_box_unset (GimpSettingsBox *box)
 
   private = GET_PRIVATE (box);
 
-  gimp_container_view_select_item (GIMP_CONTAINER_VIEW (private->combo), NULL);
+  gimp_container_view_select_items (GIMP_CONTAINER_VIEW (private->combo), NULL);
 }
diff --git a/app/widgets/gimptooleditor.c b/app/widgets/gimptooleditor.c
index 0bc7f52905..c78a2ff895 100644
--- a/app/widgets/gimptooleditor.c
+++ b/app/widgets/gimptooleditor.c
@@ -387,7 +387,7 @@ gimp_tool_editor_drop_viewables (GimpContainerTreeView   *tree_view,
                                                                  drop_pos);
 
   if (src_viewables)
-    gimp_container_view_select_item (container_view, src_viewables->data);
+    gimp_container_view_select_items (container_view, src_viewables);
 }
 
 static void
diff --git a/app/widgets/gimpundoeditor.c b/app/widgets/gimpundoeditor.c
index 585d967437..52e8ef51aa 100644
--- a/app/widgets/gimpundoeditor.c
+++ b/app/widgets/gimpundoeditor.c
@@ -72,9 +72,9 @@ static void   gimp_undo_editor_undo_event     (GimpImage         *image,
                                                GimpUndo          *undo,
                                                GimpUndoEditor    *editor);
 
-static void   gimp_undo_editor_select_item    (GimpContainerView *view,
-                                               GimpUndo          *undo,
-                                               gpointer           insert_data,
+static gboolean gimp_undo_editor_select_items (GimpContainerView *view,
+                                               GList             *undos,
+                                               GList             *paths,
                                                GimpUndoEditor    *editor);
 
 
@@ -138,8 +138,8 @@ gimp_undo_editor_constructed (GObject *object)
   gtk_box_pack_start (GTK_BOX (undo_editor), undo_editor->view, TRUE, TRUE, 0);
   gtk_widget_show (undo_editor->view);
 
-  g_signal_connect (undo_editor->view, "select-item",
-                    G_CALLBACK (gimp_undo_editor_select_item),
+  g_signal_connect (undo_editor->view, "select-items",
+                    G_CALLBACK (gimp_undo_editor_select_items),
                     undo_editor);
 
   undo_editor->undo_button =
@@ -299,7 +299,7 @@ gimp_undo_editor_fill (GimpUndoEditor *editor)
   top_undo_item = gimp_undo_stack_peek (undo_stack);
 
   g_signal_handlers_block_by_func (editor->view,
-                                   gimp_undo_editor_select_item,
+                                   gimp_undo_editor_select_items,
                                    editor);
 
   /*  select the current state of the image  */
@@ -317,7 +317,7 @@ gimp_undo_editor_fill (GimpUndoEditor *editor)
     }
 
   g_signal_handlers_unblock_by_func (editor->view,
-                                     gimp_undo_editor_select_item,
+                                     gimp_undo_editor_select_items,
                                      editor);
 }
 
@@ -347,7 +347,7 @@ gimp_undo_editor_undo_event (GimpImage      *image,
     {
     case GIMP_UNDO_EVENT_UNDO_PUSHED:
       g_signal_handlers_block_by_func (editor->view,
-                                       gimp_undo_editor_select_item,
+                                       gimp_undo_editor_select_items,
                                        editor);
 
       gimp_container_insert (editor->container, GIMP_OBJECT (undo), -1);
@@ -356,7 +356,7 @@ gimp_undo_editor_undo_event (GimpImage      *image,
       gimp_undo_create_preview (undo, editor->context, FALSE);
 
       g_signal_handlers_unblock_by_func (editor->view,
-                                         gimp_undo_editor_select_item,
+                                         gimp_undo_editor_select_items,
                                          editor);
       break;
 
@@ -368,7 +368,7 @@ gimp_undo_editor_undo_event (GimpImage      *image,
     case GIMP_UNDO_EVENT_UNDO:
     case GIMP_UNDO_EVENT_REDO:
       g_signal_handlers_block_by_func (editor->view,
-                                       gimp_undo_editor_select_item,
+                                       gimp_undo_editor_select_items,
                                        editor);
 
       if (top_undo_item)
@@ -385,7 +385,7 @@ gimp_undo_editor_undo_event (GimpImage      *image,
         }
 
       g_signal_handlers_unblock_by_func (editor->view,
-                                         gimp_undo_editor_select_item,
+                                         gimp_undo_editor_select_items,
                                          editor);
       break;
 
@@ -404,19 +404,24 @@ gimp_undo_editor_undo_event (GimpImage      *image,
     }
 }
 
-static void
-gimp_undo_editor_select_item (GimpContainerView *view,
-                              GimpUndo          *undo,
-                              gpointer           insert_data,
-                              GimpUndoEditor    *editor)
+static gboolean
+gimp_undo_editor_select_items (GimpContainerView *view,
+                               GList             *undos,
+                               GList             *paths,
+                               GimpUndoEditor    *editor)
 {
   GimpImage     *image      = GIMP_IMAGE_EDITOR (editor)->image;
   GimpUndoStack *undo_stack = gimp_image_get_undo_stack (image);
   GimpUndoStack *redo_stack = gimp_image_get_redo_stack (image);
   GimpUndo      *top_undo_item;
+  GimpUndo      *undo;
+
+  g_return_val_if_fail (g_list_length (undos) < 2, FALSE);
 
-  if (! undo)
-    return;
+  if (! undos)
+    return TRUE;
+
+  undo = undos->data;
 
   top_undo_item = gimp_undo_stack_peek (undo_stack);
 
@@ -460,4 +465,6 @@ gimp_undo_editor_select_item (GimpContainerView *view,
     }
 
   gimp_image_flush (image);
+
+  return TRUE;
 }


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