[gimp/wip/Jehan/layers-dockable-refresh: 48/58] app: duplicate and delete channel actions multi-channel aware.




commit befb271389a7d6c87d98a5fca74937d3d0f8cd77
Author: Jehan <jehan girinstud io>
Date:   Sun Jun 20 16:32:32 2021 +0200

    app: duplicate and delete channel actions multi-channel aware.

 app/actions/channels-actions.c  | 10 +++---
 app/actions/channels-commands.c | 74 ++++++++++++++++++++++++++++++-----------
 app/core/core-enums.c           |  2 ++
 app/core/core-enums.h           |  1 +
 4 files changed, 63 insertions(+), 24 deletions(-)
---
diff --git a/app/actions/channels-actions.c b/app/actions/channels-actions.c
index eb91e6f7a0..9e6efdfe79 100644
--- a/app/actions/channels-actions.c
+++ b/app/actions/channels-actions.c
@@ -68,15 +68,15 @@ static const GimpActionEntry channels_actions[] =
     GIMP_HELP_CHANNEL_NEW },
 
   { "channels-duplicate", GIMP_ICON_OBJECT_DUPLICATE,
-    NC_("channels-action", "D_uplicate Channel"), NULL,
+    NC_("channels-action", "D_uplicate Channels"), NULL,
     NC_("channels-action",
-        "Create a duplicate of this channel and add it to the image"),
+        "Create duplicates of selected channels and add them to the image"),
     channels_duplicate_cmd_callback,
     GIMP_HELP_CHANNEL_DUPLICATE },
 
   { "channels-delete", GIMP_ICON_EDIT_DELETE,
-    NC_("channels-action", "_Delete Channel"), NULL,
-    NC_("channels-action", "Delete this channel"),
+    NC_("channels-action", "_Delete Channels"), NULL,
+    NC_("channels-action", "Delete selected channels"),
     channels_delete_cmd_callback,
     GIMP_HELP_CHANNEL_DELETE },
 
@@ -335,7 +335,7 @@ channels_actions_update (GimpActionGroup *group,
 
   SET_SENSITIVE ("channels-new",             !fs && image);
   SET_SENSITIVE ("channels-new-last-values", !fs && image);
-  SET_SENSITIVE ("channels-duplicate",       !fs && (n_selected_channels == 1 || component));
+  SET_SENSITIVE ("channels-duplicate",       !fs && (n_selected_channels > 0 || component));
   SET_SENSITIVE ("channels-delete",          !fs && n_selected_channels > 0);
 
   SET_SENSITIVE ("channels-raise",           !fs && n_selected_channels > 0 && have_prev);
diff --git a/app/actions/channels-commands.c b/app/actions/channels-commands.c
index 5515ee37f5..463d3b9177 100644
--- a/app/actions/channels-commands.c
+++ b/app/actions/channels-commands.c
@@ -359,16 +359,17 @@ channels_duplicate_cmd_callback (GimpAction *action,
                                  GVariant   *value,
                                  gpointer    data)
 {
-  GimpImage   *image;
-  GimpChannel *new_channel;
+  GimpImage   *image  = NULL;
+  GList       *channels;
   GimpChannel *parent = GIMP_IMAGE_ACTIVE_PARENT;
+  return_if_no_channels (image, channels, data);
 
   if (GIMP_IS_COMPONENT_EDITOR (data))
     {
       GimpChannelType  component;
+      GimpChannel     *new_channel;
       const gchar     *desc;
       gchar           *name;
-      return_if_no_image (image, data);
 
       component = GIMP_COMPONENT_EDITOR (data)->clicked_component;
 
@@ -384,26 +385,43 @@ channels_duplicate_cmd_callback (GimpAction *action,
        *  of components don't affect each other
        */
       gimp_item_set_visible (GIMP_ITEM (new_channel), FALSE, FALSE);
+      gimp_image_add_channel (image, new_channel, parent, -1, TRUE);
 
       g_free (name);
     }
   else
     {
-      GimpChannel *channel;
-      return_if_no_channel (image, channel, data);
+      GList *new_channels = NULL;
+      GList *iter;
+
+      channels = g_list_copy (channels);
+      gimp_image_undo_group_start (image,
+                                   GIMP_UNDO_GROUP_CHANNEL_ADD,
+                                   _("Duplicate channels"));
+      for (iter = channels; iter; iter = iter->next)
+        {
+          GimpChannel *new_channel;
+
+          new_channel = GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (iter->data),
+                                                           G_TYPE_FROM_INSTANCE (iter->data)));
+
+          /*  use the actual parent here, not GIMP_IMAGE_ACTIVE_PARENT because
+           *  the latter would add a duplicated group inside itself instead of
+           *  above it
+           */
+          gimp_image_add_channel (image, new_channel,
+                                  gimp_channel_get_parent (iter->data),
+                                  gimp_item_get_index (iter->data),
+                                  TRUE);
+          new_channels = g_list_prepend (new_channels, new_channel);
+        }
 
-      new_channel =
-        GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (channel),
-                                           G_TYPE_FROM_INSTANCE (channel)));
+      gimp_image_set_selected_channels (image, new_channels);
+      g_list_free (channels);
+      g_list_free (new_channels);
 
-      /*  use the actual parent here, not GIMP_IMAGE_ACTIVE_PARENT because
-       *  the latter would add a duplicated group inside itself instead of
-       *  above it
-       */
-      parent = gimp_channel_get_parent (channel);
+      gimp_image_undo_group_end (image);
     }
-
-  gimp_image_add_channel (image, new_channel, parent, -1, TRUE);
   gimp_image_flush (image);
 }
 
@@ -412,11 +430,29 @@ channels_delete_cmd_callback (GimpAction *action,
                               GVariant   *value,
                               gpointer    data)
 {
-  GimpImage   *image;
-  GimpChannel *channel;
-  return_if_no_channel (image, channel, data);
+  GimpImage *image;
+  GList     *channels;
+  GList     *iter;
+  return_if_no_channels (image, channels, data);
+
+  channels = g_list_copy (channels);
+  if (g_list_length (channels) > 1)
+    {
+      gchar *undo_name;
+
+      undo_name = g_strdup_printf (C_("undo-type", "Remove %d Channels"),
+                                   g_list_length (channels));
+      gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_ITEM_REMOVE,
+                                   undo_name);
+    }
+
+  for (iter = channels; iter; iter = iter->next)
+    gimp_image_remove_channel (image, iter->data, TRUE, NULL);
+
+  if (g_list_length (channels) > 1)
+    gimp_image_undo_group_end (image);
 
-  gimp_image_remove_channel (image, channel, TRUE, NULL);
+  g_list_free (channels);
   gimp_image_flush (image);
 }
 
diff --git a/app/core/core-enums.c b/app/core/core-enums.c
index a2a10b0193..5ebeb849cc 100644
--- a/app/core/core-enums.c
+++ b/app/core/core-enums.c
@@ -1191,6 +1191,7 @@ gimp_undo_type_get_type (void)
     { GIMP_UNDO_GROUP_LAYER_LOCK_ALPHA, "GIMP_UNDO_GROUP_LAYER_LOCK_ALPHA", "group-layer-lock-alpha" },
     { GIMP_UNDO_GROUP_LAYER_OPACITY, "GIMP_UNDO_GROUP_LAYER_OPACITY", "group-layer-opacity" },
     { GIMP_UNDO_GROUP_LAYER_MODE, "GIMP_UNDO_GROUP_LAYER_MODE", "group-layer-mode" },
+    { GIMP_UNDO_GROUP_CHANNEL_ADD, "GIMP_UNDO_GROUP_CHANNEL_ADD", "group-channel-add" },
     { GIMP_UNDO_GROUP_FS_TO_LAYER, "GIMP_UNDO_GROUP_FS_TO_LAYER", "group-fs-to-layer" },
     { GIMP_UNDO_GROUP_FS_FLOAT, "GIMP_UNDO_GROUP_FS_FLOAT", "group-fs-float" },
     { GIMP_UNDO_GROUP_FS_ANCHOR, "GIMP_UNDO_GROUP_FS_ANCHOR", "group-fs-anchor" },
@@ -1300,6 +1301,7 @@ gimp_undo_type_get_type (void)
     { GIMP_UNDO_GROUP_LAYER_LOCK_ALPHA, NC_("undo-type", "Lock/Unlock alpha channels"), NULL },
     { GIMP_UNDO_GROUP_LAYER_OPACITY, NC_("undo-type", "Set layers opacity"), NULL },
     { GIMP_UNDO_GROUP_LAYER_MODE, NC_("undo-type", "Set layers mode"), NULL },
+    { GIMP_UNDO_GROUP_CHANNEL_ADD, NC_("undo-type", "Add channels"), NULL },
     { GIMP_UNDO_GROUP_FS_TO_LAYER, NC_("undo-type", "Floating selection to layer"), NULL },
     { GIMP_UNDO_GROUP_FS_FLOAT, NC_("undo-type", "Float selection"), NULL },
     { GIMP_UNDO_GROUP_FS_ANCHOR, NC_("undo-type", "Anchor floating selection"), NULL },
diff --git a/app/core/core-enums.h b/app/core/core-enums.h
index 6104431b23..5eb8825f53 100644
--- a/app/core/core-enums.h
+++ b/app/core/core-enums.h
@@ -558,6 +558,7 @@ typedef enum /*< pdb-skip >*/
   GIMP_UNDO_GROUP_LAYER_LOCK_ALPHA,      /*< desc="Lock/Unlock alpha channels"     >*/
   GIMP_UNDO_GROUP_LAYER_OPACITY,         /*< desc="Set layers opacity"             >*/
   GIMP_UNDO_GROUP_LAYER_MODE,            /*< desc="Set layers mode"                >*/
+  GIMP_UNDO_GROUP_CHANNEL_ADD,           /*< desc="Add channels"                   >*/
   GIMP_UNDO_GROUP_FS_TO_LAYER,           /*< desc="Floating selection to layer"    >*/
   GIMP_UNDO_GROUP_FS_FLOAT,              /*< desc="Float selection"                >*/
   GIMP_UNDO_GROUP_FS_ANCHOR,             /*< desc="Anchor floating selection"      >*/


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