[gimp/wip/Jehan/layers-dockable-refresh: 83/126] app: implement multi-channel selection.




commit b716a22faa7c100cb1f97375ffde284ef2d80375
Author: Jehan <jehan girinstud io>
Date:   Sun Jun 20 00:00:53 2021 +0200

    app: implement multi-channel selection.
    
    Similar to commit 592cea6b870e257b1e03d4c7e4f9f2ccbf1a73b3, but this
    type for the Channels dockable.

 app/dialogs/dialogs-constructors.c |  2 +-
 app/xcf/xcf-load.c                 | 36 ++++++++++++++++++++++++++----------
 app/xcf/xcf-private.h              |  2 +-
 app/xcf/xcf-save.c                 |  2 +-
 4 files changed, 29 insertions(+), 13 deletions(-)
---
diff --git a/app/dialogs/dialogs-constructors.c b/app/dialogs/dialogs-constructors.c
index 55ebddd3e1..ff885950da 100644
--- a/app/dialogs/dialogs-constructors.c
+++ b/app/dialogs/dialogs-constructors.c
@@ -745,7 +745,7 @@ dialogs_channel_list_view_new (GimpDialogFactory *factory,
     view_size = context->gimp->config->layer_preview_size;
 
   return gimp_item_tree_view_new (GIMP_TYPE_CHANNEL_TREE_VIEW,
-                                  view_size, 1, FALSE,
+                                  view_size, 1, TRUE,
                                   gimp_context_get_image (context),
                                   gimp_dialog_factory_get_menu_factory (factory),
                                   "<Channels>",
diff --git a/app/xcf/xcf-load.c b/app/xcf/xcf-load.c
index 58fe18c6fb..ba88b31248 100644
--- a/app/xcf/xcf-load.c
+++ b/app/xcf/xcf-load.c
@@ -680,8 +680,8 @@ xcf_load_image (Gimp     *gimp,
       g_clear_pointer (&info->selected_layers, g_list_free);
     }
 
-  if (info->active_channel)
-    gimp_image_set_active_channel (image, info->active_channel);
+  if (info->selected_channels)
+    gimp_image_set_selected_channels (image, info->selected_channels);
 
   if (info->file)
     gimp_image_set_file (image, info->file);
@@ -1674,18 +1674,23 @@ xcf_load_channel_props (XcfInfo      *info,
           return TRUE;
 
         case PROP_ACTIVE_CHANNEL:
-          info->active_channel = *channel;
+          info->selected_channels = g_list_prepend (info->selected_channels, *channel);
           break;
 
         case PROP_SELECTION:
           {
             GimpChannel *mask;
+            GList       *iter;
 
             /* We're going to delete *channel, Don't leave its pointer
              * in @info. See bug #767873.
              */
-            if (*channel == info->active_channel)
-              info->active_channel = NULL;
+            for (iter = info->selected_channels; iter; iter = iter->next)
+              if (*channel == iter->data)
+                {
+                  info->selected_channels = g_list_delete_link (info->selected_channels, iter);
+                  break;
+                }
 
             mask =
               gimp_selection_new (image,
@@ -1698,7 +1703,7 @@ xcf_load_channel_props (XcfInfo      *info,
             g_object_unref (*channel);
             *channel = mask;
 
-            /* Don't restore info->active_channel because the
+            /* Don't restore info->selected_channels because the
              * selection can't be the active channel
              */
           }
@@ -2177,8 +2182,14 @@ xcf_load_channel (XcfInfo   *info,
   /* don't unref the selection of a partially loaded XCF */
   if (channel != gimp_image_get_mask (image))
     {
-      if (info->active_channel == channel)
-        info->active_channel = NULL;
+      GList *iter;
+
+      for (iter = info->selected_channels; iter; iter = iter->next)
+        if (channel == iter->data)
+          {
+            info->selected_channels = g_list_delete_link (info->selected_channels, iter);
+            break;
+          }
 
       if (info->floating_sel_drawable == GIMP_DRAWABLE (channel))
         info->floating_sel_drawable = NULL;
@@ -2195,6 +2206,7 @@ xcf_load_layer_mask (XcfInfo   *info,
 {
   GimpLayerMask *layer_mask;
   GimpChannel   *channel;
+  GList         *iter;
   goffset        hierarchy_offset;
   gint           width;
   gint           height;
@@ -2248,8 +2260,12 @@ xcf_load_layer_mask (XcfInfo   *info,
   return layer_mask;
 
  error:
-  if (info->active_channel == GIMP_CHANNEL (layer_mask))
-    info->active_channel = NULL;
+  for (iter = info->selected_channels; iter; iter = iter->next)
+    if (layer_mask == iter->data)
+      {
+        info->selected_channels = g_list_delete_link (info->selected_channels, iter);
+        break;
+      }
 
   if (info->floating_sel_drawable == GIMP_DRAWABLE (layer_mask))
     info->floating_sel_drawable = NULL;
diff --git a/app/xcf/xcf-private.h b/app/xcf/xcf-private.h
index 891ab072fd..c3a0938d2e 100644
--- a/app/xcf/xcf-private.h
+++ b/app/xcf/xcf-private.h
@@ -106,7 +106,7 @@ struct _XcfInfo
   GFile              *file;
   GimpTattoo          tattoo_state;
   GList              *selected_layers;
-  GimpChannel        *active_channel;
+  GList              *selected_channels;
   GimpDrawable       *floating_sel_drawable;
   GimpLayer          *floating_sel;
   goffset             floating_sel_offset;
diff --git a/app/xcf/xcf-save.c b/app/xcf/xcf-save.c
index 87f5372477..b325243687 100644
--- a/app/xcf/xcf-save.c
+++ b/app/xcf/xcf-save.c
@@ -625,7 +625,7 @@ xcf_save_channel_props (XcfInfo      *info,
 {
   GimpParasiteList *parasites;
 
-  if (channel == gimp_image_get_active_channel (image))
+  if (g_list_find (gimp_image_get_selected_channels (image), channel))
     xcf_check_error (xcf_save_prop (info, image, PROP_ACTIVE_CHANNEL, error));
 
   if (channel == gimp_image_get_mask (image))


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