[gimp] app: selection stroke and "Stroke Path" now multi-layer aware.



commit 2ba6ac62865ee7fb53c8aa885c6e68cb2eee17a8
Author: Jehan <jehan girinstud io>
Date:   Sat Aug 1 13:59:21 2020 +0200

    app: selection stroke and "Stroke Path" now multi-layer aware.
    
    This includes "select-stroke*" actions and "Stroke Path" feature of the
    Vector tool.

 app/actions/items-commands.c | 29 ++++++++++++++++-------------
 app/actions/select-actions.c |  6 +++---
 app/core/gimpitem.c          | 20 +++++++++++++++-----
 app/core/gimpitem.h          |  2 +-
 app/dialogs/stroke-dialog.c  | 11 ++++++-----
 app/dialogs/stroke-dialog.h  |  4 ++--
 app/tools/gimpvectortool.c   | 17 +++++++++--------
 pdb/groups/drawable_edit.pdb |  4 +++-
 8 files changed, 55 insertions(+), 38 deletions(-)
---
diff --git a/app/actions/items-commands.c b/app/actions/items-commands.c
index 2ae86417b1..8b65521965 100644
--- a/app/actions/items-commands.c
+++ b/app/actions/items-commands.c
@@ -53,7 +53,7 @@ static void   items_fill_callback   (GtkWidget         *dialog,
                                      gpointer           user_data);
 static void   items_stroke_callback (GtkWidget         *dialog,
                                      GimpItem          *item,
-                                     GimpDrawable      *drawable,
+                                     GList             *drawables,
                                      GimpContext       *context,
                                      GimpStrokeOptions *options,
                                      gpointer           user_data);
@@ -277,18 +277,18 @@ items_stroke_cmd_callback (GimpAction  *action,
                            const gchar *dialog_help_id,
                            gpointer     data)
 {
-  GimpDrawable *drawable;
+  GList        *drawables;
   GtkWidget    *dialog;
   GtkWidget    *widget;
   return_if_no_widget (widget, data);
 
-  drawable = gimp_image_get_active_drawable (image);
+  drawables = gimp_image_get_selected_drawables (image);
 
-  if (! drawable)
+  if (! drawables)
     {
       gimp_message_literal (image->gimp,
                             G_OBJECT (widget), GIMP_MESSAGE_WARNING,
-                            _("There is no active layer or channel to stroke to."));
+                            _("There are no selected layers or channels to stroke to."));
       return;
     }
 
@@ -299,7 +299,7 @@ items_stroke_cmd_callback (GimpAction  *action,
       GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
 
       dialog = stroke_dialog_new (item,
-                                  drawable,
+                                  drawables,
                                   action_data_get_context (data),
                                   dialog_title,
                                   dialog_icon_name,
@@ -313,6 +313,7 @@ items_stroke_cmd_callback (GimpAction  *action,
     }
 
   gtk_window_present (GTK_WINDOW (dialog));
+  g_list_free (drawables);
 }
 
 void
@@ -321,25 +322,25 @@ items_stroke_last_vals_cmd_callback (GimpAction *action,
                                      GimpItem   *item,
                                      gpointer    data)
 {
-  GimpDrawable     *drawable;
+  GList            *drawables;
   GimpDialogConfig *config;
   GtkWidget        *widget;
   GError           *error = NULL;
   return_if_no_widget (widget, data);
 
-  drawable = gimp_image_get_active_drawable (image);
+  drawables = gimp_image_get_selected_drawables (image);
 
-  if (! drawable)
+  if (! drawables)
     {
       gimp_message_literal (image->gimp,
                             G_OBJECT (widget), GIMP_MESSAGE_WARNING,
-                            _("There is no active layer or channel to stroke to."));
+                            _("There are no selected layers or channels to stroke to."));
       return;
     }
 
   config = GIMP_DIALOG_CONFIG (image->gimp->config);
 
-  if (! gimp_item_stroke (item, drawable,
+  if (! gimp_item_stroke (item, drawables,
                           action_data_get_context (data),
                           config->stroke_options, NULL,
                           TRUE, NULL, &error))
@@ -352,6 +353,8 @@ items_stroke_last_vals_cmd_callback (GimpAction *action,
     {
       gimp_image_flush (image);
     }
+
+  g_list_free (drawables);
 }
 
 
@@ -391,7 +394,7 @@ items_fill_callback (GtkWidget       *dialog,
 static void
 items_stroke_callback (GtkWidget         *dialog,
                        GimpItem          *item,
-                       GimpDrawable      *drawable,
+                       GList             *drawables,
                        GimpContext       *context,
                        GimpStrokeOptions *options,
                        gpointer           data)
@@ -403,7 +406,7 @@ items_stroke_callback (GtkWidget         *dialog,
   gimp_config_sync (G_OBJECT (options),
                     G_OBJECT (config->stroke_options), 0);
 
-  if (! gimp_item_stroke (item, drawable, context, options, NULL,
+  if (! gimp_item_stroke (item, drawables, context, options, NULL,
                           TRUE, NULL, &error))
     {
       gimp_message_literal (context->gimp,
diff --git a/app/actions/select-actions.c b/app/actions/select-actions.c
index 96c8c79ac9..67c64ad6c5 100644
--- a/app/actions/select-actions.c
+++ b/app/actions/select-actions.c
@@ -132,7 +132,7 @@ static const GimpActionEntry select_actions[] =
     GIMP_HELP_SELECTION_STROKE },
 
   { "select-stroke-last-values", GIMP_ICON_SELECTION_STROKE,
-    NC_("select-action", "_Stroke Selection"), NULL,
+    NC_("select-action", "_Stroke Selection with last values"), NULL,
     NC_("select-action", "Stroke the selection with last used values"),
     select_stroke_last_vals_cmd_callback,
     GIMP_HELP_SELECTION_STROKE }
@@ -210,8 +210,8 @@ select_actions_update (GimpActionGroup *group,
   SET_SENSITIVE ("select-save",               image && !fs);
   SET_SENSITIVE ("select-fill",               drawables && all_writable && no_groups && sel);
   SET_SENSITIVE ("select-fill-last-values",   drawables && all_writable && no_groups && sel);
-  SET_SENSITIVE ("select-stroke",             writable && !children && sel);
-  SET_SENSITIVE ("select-stroke-last-values", writable && !children && sel);
+  SET_SENSITIVE ("select-stroke",             drawables && all_writable && no_groups && sel);
+  SET_SENSITIVE ("select-stroke-last-values", drawables && all_writable && no_groups && sel);
 
 #undef SET_SENSITIVE
 
diff --git a/app/core/gimpitem.c b/app/core/gimpitem.c
index 5177c3741e..23f82e3f22 100644
--- a/app/core/gimpitem.c
+++ b/app/core/gimpitem.c
@@ -1824,7 +1824,7 @@ gimp_item_fill (GimpItem        *item,
 
 gboolean
 gimp_item_stroke (GimpItem          *item,
-                  GimpDrawable      *drawable,
+                  GList             *drawables,
                   GimpContext       *context,
                   GimpStrokeOptions *stroke_options,
                   GimpPaintOptions  *paint_options,
@@ -1833,12 +1833,11 @@ gimp_item_stroke (GimpItem          *item,
                   GError           **error)
 {
   GimpItemClass *item_class;
+  GList         *iter;
   gboolean       retval = FALSE;
 
   g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
   g_return_val_if_fail (gimp_item_is_attached (item), FALSE);
-  g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
-  g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), FALSE);
   g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE);
   g_return_val_if_fail (GIMP_IS_STROKE_OPTIONS (stroke_options), FALSE);
   g_return_val_if_fail (paint_options == NULL ||
@@ -1848,6 +1847,12 @@ gimp_item_stroke (GimpItem          *item,
 
   item_class = GIMP_ITEM_GET_CLASS (item);
 
+  for (iter = drawables; iter; iter = iter->next)
+    {
+      g_return_val_if_fail (GIMP_IS_DRAWABLE (iter->data), FALSE);
+      g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (iter->data)), FALSE);
+    }
+
   if (item_class->stroke)
     {
       GimpImage *image = gimp_item_get_image (item);
@@ -1858,8 +1863,13 @@ gimp_item_stroke (GimpItem          *item,
         gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_PAINT,
                                      item_class->stroke_desc);
 
-      retval = item_class->stroke (item, drawable, stroke_options, push_undo,
-                                   progress, error);
+      for (iter = drawables; iter; iter = iter->next)
+        {
+          retval = item_class->stroke (item, iter->data, stroke_options, push_undo,
+                                       progress, error);
+          if (! retval)
+            break;
+        }
 
       if (push_undo)
         gimp_image_undo_group_end (image);
diff --git a/app/core/gimpitem.h b/app/core/gimpitem.h
index f72beb8cfe..4ee842dcdc 100644
--- a/app/core/gimpitem.h
+++ b/app/core/gimpitem.h
@@ -302,7 +302,7 @@ gboolean        gimp_item_fill               (GimpItem           *item,
                                               GimpProgress       *progress,
                                               GError            **error);
 gboolean        gimp_item_stroke             (GimpItem           *item,
-                                              GimpDrawable       *drawable,
+                                              GList              *drawables,
                                               GimpContext        *context,
                                               GimpStrokeOptions  *stroke_options,
                                               GimpPaintOptions   *paint_options,
diff --git a/app/dialogs/stroke-dialog.c b/app/dialogs/stroke-dialog.c
index 32012c0068..eb5dc3781f 100644
--- a/app/dialogs/stroke-dialog.c
+++ b/app/dialogs/stroke-dialog.c
@@ -52,7 +52,7 @@ typedef struct _StrokeDialog StrokeDialog;
 struct _StrokeDialog
 {
   GimpItem           *item;
-  GimpDrawable       *drawable;
+  GList              *drawables;
   GimpContext        *context;
   GimpStrokeOptions  *options;
   GimpStrokeCallback  callback;
@@ -74,7 +74,7 @@ static void  stroke_dialog_response (GtkWidget    *dialog,
 
 GtkWidget *
 stroke_dialog_new (GimpItem           *item,
-                   GimpDrawable       *drawable,
+                   GList              *drawables,
                    GimpContext        *context,
                    const gchar        *title,
                    const gchar        *icon_name,
@@ -95,7 +95,7 @@ stroke_dialog_new (GimpItem           *item,
   GtkWidget    *frame;
 
   g_return_val_if_fail (GIMP_IS_ITEM (item), NULL);
-  g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
+  g_return_val_if_fail (drawables, NULL);
   g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
   g_return_val_if_fail (icon_name != NULL, NULL);
   g_return_val_if_fail (help_id != NULL, NULL);
@@ -107,7 +107,7 @@ stroke_dialog_new (GimpItem           *item,
   private = g_slice_new0 (StrokeDialog);
 
   private->item      = item;
-  private->drawable  = drawable;
+  private->drawables = g_list_copy (drawables);
   private->context   = context;
   private->options   = gimp_stroke_options_new (context->gimp, context, TRUE);
   private->callback  = callback;
@@ -255,6 +255,7 @@ static void
 stroke_dialog_free (StrokeDialog *private)
 {
   g_object_unref (private->options);
+  g_list_free (private->drawables);
 
   g_slice_free (StrokeDialog, private);
 }
@@ -281,7 +282,7 @@ stroke_dialog_response (GtkWidget    *dialog,
     case GTK_RESPONSE_OK:
       private->callback (dialog,
                          private->item,
-                         private->drawable,
+                         private->drawables,
                          private->context,
                          private->options,
                          private->user_data);
diff --git a/app/dialogs/stroke-dialog.h b/app/dialogs/stroke-dialog.h
index e8e02a1084..fd5fc72f3c 100644
--- a/app/dialogs/stroke-dialog.h
+++ b/app/dialogs/stroke-dialog.h
@@ -23,14 +23,14 @@
 
 typedef void (* GimpStrokeCallback) (GtkWidget         *dialog,
                                      GimpItem          *item,
-                                     GimpDrawable      *drawable,
+                                     GList             *drawables,
                                      GimpContext       *context,
                                      GimpStrokeOptions *options,
                                      gpointer           user_data);
 
 
 GtkWidget * stroke_dialog_new (GimpItem           *item,
-                               GimpDrawable       *drawable,
+                               GList              *drawables,
                                GimpContext        *context,
                                const gchar        *title,
                                const gchar        *icon_name,
diff --git a/app/tools/gimpvectortool.c b/app/tools/gimpvectortool.c
index 97b4c4a41d..baafd6e33d 100644
--- a/app/tools/gimpvectortool.c
+++ b/app/tools/gimpvectortool.c
@@ -142,7 +142,7 @@ static void     gimp_vector_tool_stroke_vectors  (GimpVectorTool        *vector_
                                                   GtkWidget             *button);
 static void     gimp_vector_tool_stroke_callback (GtkWidget             *dialog,
                                                   GimpItem              *item,
-                                                  GimpDrawable          *drawable,
+                                                  GList                 *drawables,
                                                   GimpContext           *context,
                                                   GimpStrokeOptions     *options,
                                                   gpointer               data);
@@ -792,7 +792,7 @@ gimp_vector_tool_stroke_vectors (GimpVectorTool *vector_tool,
 {
   GimpDialogConfig *config;
   GimpImage        *image;
-  GimpDrawable     *drawable;
+  GList            *drawables;
   GtkWidget        *dialog;
 
   if (! vector_tool->vectors)
@@ -802,18 +802,18 @@ gimp_vector_tool_stroke_vectors (GimpVectorTool *vector_tool,
 
   config = GIMP_DIALOG_CONFIG (image->gimp->config);
 
-  drawable = gimp_image_get_active_drawable (image);
+  drawables = gimp_image_get_selected_drawables (image);
 
-  if (! drawable)
+  if (! drawables)
     {
       gimp_tool_message (GIMP_TOOL (vector_tool),
                          GIMP_TOOL (vector_tool)->display,
-                         _("There is no active layer or channel to stroke to"));
+                         _("There are no selected layers or channels to stroke to."));
       return;
     }
 
   dialog = stroke_dialog_new (GIMP_ITEM (vector_tool->vectors),
-                              drawable,
+                              drawables,
                               GIMP_CONTEXT (GIMP_TOOL_GET_OPTIONS (vector_tool)),
                               _("Stroke Path"),
                               GIMP_ICON_PATH_STROKE,
@@ -823,12 +823,13 @@ gimp_vector_tool_stroke_vectors (GimpVectorTool *vector_tool,
                               gimp_vector_tool_stroke_callback,
                               vector_tool);
   gtk_widget_show (dialog);
+  g_list_free (drawables);
 }
 
 static void
 gimp_vector_tool_stroke_callback (GtkWidget         *dialog,
                                   GimpItem          *item,
-                                  GimpDrawable      *drawable,
+                                  GList             *drawables,
                                   GimpContext       *context,
                                   GimpStrokeOptions *options,
                                   gpointer           data)
@@ -840,7 +841,7 @@ gimp_vector_tool_stroke_callback (GtkWidget         *dialog,
   gimp_config_sync (G_OBJECT (options),
                     G_OBJECT (config->stroke_options), 0);
 
-  if (! gimp_item_stroke (item, drawable, context, options, NULL,
+  if (! gimp_item_stroke (item, drawables, context, options, NULL,
                           TRUE, NULL, &error))
     {
       gimp_message_literal (context->gimp,
diff --git a/pdb/groups/drawable_edit.pdb b/pdb/groups/drawable_edit.pdb
index 47f2372319..413d256ceb 100644
--- a/pdb/groups/drawable_edit.pdb
+++ b/pdb/groups/drawable_edit.pdb
@@ -339,6 +339,7 @@ HELP
       GimpImage         *image = gimp_item_get_image (GIMP_ITEM (drawable));
       GimpStrokeOptions *options;
       GimpPaintOptions  *paint_options;
+      GList             *drawables = g_list_prepend (NULL, drawable);
 
       options = gimp_pdb_context_get_stroke_options (GIMP_PDB_CONTEXT (context));
 
@@ -347,10 +348,11 @@ HELP
       paint_options = gimp_config_duplicate (GIMP_CONFIG (paint_options));
 
       success = gimp_item_stroke (GIMP_ITEM (gimp_image_get_mask (image)),
-                                  drawable, context, options, paint_options,
+                                  drawables, context, options, paint_options,
                                   TRUE, progress, error);
 
       g_object_unref (paint_options);
+      g_list_free (drawables);
     }
   else
     success = FALSE;


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