[gimp/wip/Jehan/layers-dockable-refresh: 94/126] app: raise/lower channels one step or to top/bottom multi-channel aware.




commit 7e4b05f0d926a4c5da43357ed6d9a3c50244365a
Author: Jehan <jehan girinstud io>
Date:   Sun Jun 20 15:50:22 2021 +0200

    app: raise/lower channels one step or to top/bottom multi-channel aware.

 app/actions/actions.h           |   6 ++
 app/actions/channels-actions.c  |  24 ++++----
 app/actions/channels-commands.c | 124 ++++++++++++++++++++++++++++++++++------
 3 files changed, 126 insertions(+), 28 deletions(-)
---
diff --git a/app/actions/actions.h b/app/actions/actions.h
index f1cdc6bc28..b34636c828 100644
--- a/app/actions/actions.h
+++ b/app/actions/actions.h
@@ -122,6 +122,12 @@ void               action_message          (GimpDisplay          *display,
   if (! channel) \
     return
 
+#define return_if_no_channels(image,channels,data) \
+  return_if_no_image (image,data); \
+  channels = gimp_image_get_selected_channels (image); \
+  if (! channels) \
+    return
+
 #define return_if_no_vectors(image,vectors,data) \
   return_if_no_image (image,data); \
   vectors = gimp_image_get_active_vectors (image); \
diff --git a/app/actions/channels-actions.c b/app/actions/channels-actions.c
index 7a05302320..eb91e6f7a0 100644
--- a/app/actions/channels-actions.c
+++ b/app/actions/channels-actions.c
@@ -81,28 +81,28 @@ static const GimpActionEntry channels_actions[] =
     GIMP_HELP_CHANNEL_DELETE },
 
   { "channels-raise", GIMP_ICON_GO_UP,
-    NC_("channels-action", "_Raise Channel"), NULL,
-    NC_("channels-action", "Raise this channel one step in the channel stack"),
+    NC_("channels-action", "_Raise Channels"), NULL,
+    NC_("channels-action", "Raise these channels one step in the channel stack"),
     channels_raise_cmd_callback,
     GIMP_HELP_CHANNEL_RAISE },
 
   { "channels-raise-to-top", GIMP_ICON_GO_TOP,
-    NC_("channels-action", "Raise Channel to _Top"), NULL,
+    NC_("channels-action", "Raise Channels to _Top"), NULL,
     NC_("channels-action",
-        "Raise this channel to the top of the channel stack"),
+        "Raise these channels to the top of the channel stack"),
     channels_raise_to_top_cmd_callback,
     GIMP_HELP_CHANNEL_RAISE_TO_TOP },
 
   { "channels-lower", GIMP_ICON_GO_DOWN,
-    NC_("channels-action", "_Lower Channel"), NULL,
-    NC_("channels-action", "Lower this channel one step in the channel stack"),
+    NC_("channels-action", "_Lower Channels"), NULL,
+    NC_("channels-action", "Lower these channels one step in the channel stack"),
     channels_lower_cmd_callback,
     GIMP_HELP_CHANNEL_LOWER },
 
   { "channels-lower-to-bottom", GIMP_ICON_GO_BOTTOM,
-    NC_("channels-action", "Lower Channel to _Bottom"), NULL,
+    NC_("channels-action", "Lower Channels to _Bottom"), NULL,
     NC_("channels-action",
-        "Lower this channel to the bottom of the channel stack"),
+        "Lower these channels to the bottom of the channel stack"),
     channels_lower_to_bottom_cmd_callback,
     GIMP_HELP_CHANNEL_LOWER_TO_BOTTOM }
 };
@@ -338,10 +338,10 @@ channels_actions_update (GimpActionGroup *group,
   SET_SENSITIVE ("channels-duplicate",       !fs && (n_selected_channels == 1 || component));
   SET_SENSITIVE ("channels-delete",          !fs && n_selected_channels > 0);
 
-  SET_SENSITIVE ("channels-raise",           !fs && n_selected_channels == 1 && have_prev);
-  SET_SENSITIVE ("channels-raise-to-top",    !fs && n_selected_channels == 1 && have_prev);
-  SET_SENSITIVE ("channels-lower",           !fs && n_selected_channels == 1 && have_next);
-  SET_SENSITIVE ("channels-lower-to-bottom", !fs && n_selected_channels == 1 && have_next);
+  SET_SENSITIVE ("channels-raise",           !fs && n_selected_channels > 0 && have_prev);
+  SET_SENSITIVE ("channels-raise-to-top",    !fs && n_selected_channels > 0 && have_prev);
+  SET_SENSITIVE ("channels-lower",           !fs && n_selected_channels > 0 && have_next);
+  SET_SENSITIVE ("channels-lower-to-bottom", !fs && n_selected_channels > 0 && have_next);
 
   SET_SENSITIVE ("channels-selection-replace",   !fs && (n_selected_channels == 1 || component));
   SET_SENSITIVE ("channels-selection-add",       !fs && (n_selected_channels == 1 || component));
diff --git a/app/actions/channels-commands.c b/app/actions/channels-commands.c
index 6833fca565..5515ee37f5 100644
--- a/app/actions/channels-commands.c
+++ b/app/actions/channels-commands.c
@@ -215,12 +215,34 @@ channels_raise_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;
+  GList     *raised_channels = NULL;
+  return_if_no_channels (image, channels, data);
+
+  for (iter = channels; iter; iter = iter->next)
+    {
+      gint index;
+
+      index = gimp_item_get_index (iter->data);
+      if (index > 0)
+        raised_channels = g_list_prepend (raised_channels, iter->data);
+    }
+
+  gimp_image_undo_group_start (image,
+                               GIMP_UNDO_GROUP_ITEM_DISPLACE,
+                               ngettext ("Raise Channel",
+                                         "Raise Channels",
+                                         g_list_length (raised_channels)));
+
+  for (iter = raised_channels; iter; iter = iter->next)
+    gimp_image_raise_item (image, iter->data, NULL);
 
-  gimp_image_raise_item (image, GIMP_ITEM (channel), NULL);
   gimp_image_flush (image);
+  gimp_image_undo_group_end (image);
+
+  g_list_free (raised_channels);
 }
 
 void
@@ -228,12 +250,34 @@ channels_raise_to_top_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;
+  GList     *raised_channels = NULL;
+  return_if_no_channels (image, channels, data);
+
+  for (iter = channels; iter; iter = iter->next)
+    {
+      gint index;
+
+      index = gimp_item_get_index (iter->data);
+      if (index > 0)
+        raised_channels = g_list_prepend (raised_channels, iter->data);
+    }
+
+  gimp_image_undo_group_start (image,
+                               GIMP_UNDO_GROUP_ITEM_DISPLACE,
+                               ngettext ("Raise Channel to Top",
+                                         "Raise Channels to Top",
+                                         g_list_length (raised_channels)));
+
+  for (iter = raised_channels; iter; iter = iter->next)
+    gimp_image_raise_item_to_top (image, iter->data);
 
-  gimp_image_raise_item_to_top (image, GIMP_ITEM (channel));
   gimp_image_flush (image);
+  gimp_image_undo_group_end (image);
+
+  g_list_free (raised_channels);
 }
 
 void
@@ -241,12 +285,36 @@ channels_lower_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;
+  GList     *lowered_channels = NULL;
+  return_if_no_channels (image, channels, data);
+
+  for (iter = channels; iter; iter = iter->next)
+    {
+      GList *layer_list;
+      gint   index;
+
+      layer_list = gimp_item_get_container_iter (GIMP_ITEM (iter->data));
+      index = gimp_item_get_index (iter->data);
+      if (index < g_list_length (layer_list) - 1)
+        lowered_channels = g_list_prepend (lowered_channels, iter->data);
+    }
+
+  gimp_image_undo_group_start (image,
+                               GIMP_UNDO_GROUP_ITEM_DISPLACE,
+                               ngettext ("Lower Channel",
+                                         "Lower Channels",
+                                         g_list_length (lowered_channels)));
+
+  for (iter = lowered_channels; iter; iter = iter->next)
+    gimp_image_lower_item (image, iter->data, NULL);
 
-  gimp_image_lower_item (image, GIMP_ITEM (channel), NULL);
   gimp_image_flush (image);
+  gimp_image_undo_group_end (image);
+
+  g_list_free (lowered_channels);
 }
 
 void
@@ -254,12 +322,36 @@ channels_lower_to_bottom_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;
+  GList     *lowered_channels = NULL;
+  return_if_no_channels (image, channels, data);
+
+  for (iter = channels; iter; iter = iter->next)
+    {
+      GList *layer_list;
+      gint   index;
+
+      layer_list = gimp_item_get_container_iter (GIMP_ITEM (iter->data));
+      index = gimp_item_get_index (iter->data);
+      if (index < g_list_length (layer_list) - 1)
+        lowered_channels = g_list_prepend (lowered_channels, iter->data);
+    }
+
+  gimp_image_undo_group_start (image,
+                               GIMP_UNDO_GROUP_ITEM_DISPLACE,
+                               ngettext ("Lower Channel to Bottom",
+                                         "Lower Channels to Bottom",
+                                         g_list_length (lowered_channels)));
+
+  for (iter = lowered_channels; iter; iter = iter->next)
+    gimp_image_lower_item_to_bottom (image, iter->data);
 
-  gimp_image_lower_item_to_bottom (image, GIMP_ITEM (channel));
   gimp_image_flush (image);
+  gimp_image_undo_group_end (image);
+
+  g_list_free (lowered_channels);
 }
 
 void


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