[gimp/gimp-2-10] app: error messages should happen on button press, not initialization.



commit f5225f22116e58baed4c72d1e8e7beb4280e6031
Author: Jehan <jehan girinstud io>
Date:   Sat Feb 9 22:26:46 2019 +0100

    app: error messages should happen on button press, not initialization.
    
    The initialization is sometimes done when switching tools (for instance
    when selecting the active tool by command), not always on button press.
    So the error output behavior was inconsistent, and worse, the tool was
    sometimes not forbidden to run when it should have been.
    Just run all the checks (layer groups, locks and whatnot) on button
    press.
    
    (cherry picked from commit 74cfd4fd950befdb3f4d6315f6b216920197186e)

 app/tools/gimpbucketfilltool.c | 87 +++++++++++++++---------------------------
 1 file changed, 31 insertions(+), 56 deletions(-)
---
diff --git a/app/tools/gimpbucketfilltool.c b/app/tools/gimpbucketfilltool.c
index f47694db82..611ee36553 100644
--- a/app/tools/gimpbucketfilltool.c
+++ b/app/tools/gimpbucketfilltool.c
@@ -86,9 +86,6 @@ struct _GimpBucketFillToolPrivate
 static void     gimp_bucket_fill_tool_constructed      (GObject               *object);
 static void     gimp_bucket_fill_tool_finalize         (GObject               *object);
 
-static gboolean gimp_bucket_fill_tool_initialize       (GimpTool              *tool,
-                                                        GimpDisplay           *display,
-                                                        GError               **error);
 static void     gimp_bucket_fill_tool_button_press     (GimpTool              *tool,
                                                         const GimpCoords      *coords,
                                                         guint32                time,
@@ -171,7 +168,6 @@ gimp_bucket_fill_tool_class_init (GimpBucketFillToolClass *klass)
   object_class->constructed  = gimp_bucket_fill_tool_constructed;
   object_class->finalize     = gimp_bucket_fill_tool_finalize;
 
-  tool_class->initialize     = gimp_bucket_fill_tool_initialize;
   tool_class->button_press   = gimp_bucket_fill_tool_button_press;
   tool_class->motion         = gimp_bucket_fill_tool_motion;
   tool_class->button_release = gimp_bucket_fill_tool_button_release;
@@ -268,57 +264,6 @@ gimp_bucket_fill_tool_finalize (GObject *object)
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
-static gboolean
-gimp_bucket_fill_tool_initialize (GimpTool     *tool,
-                                  GimpDisplay  *display,
-                                  GError      **error)
-{
-  GimpBucketFillOptions *options     = GIMP_BUCKET_FILL_TOOL_GET_OPTIONS (tool);
-  GimpBucketFillTool    *bucket_tool = GIMP_BUCKET_FILL_TOOL (tool);
-  GimpImage             *image       = gimp_display_get_image (display);
-  GimpDrawable          *drawable    = gimp_image_get_active_drawable (image);
-
-  if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error))
-    {
-      return FALSE;
-    }
-
-  if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable)))
-    {
-      g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
-                           _("Cannot modify the pixels of layer groups."));
-      return FALSE;
-    }
-
-  if (! gimp_item_is_visible (GIMP_ITEM (drawable)))
-    {
-      g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
-                           _("The active layer is not visible."));
-      return FALSE;
-    }
-
-  if (gimp_item_is_content_locked (GIMP_ITEM (drawable)))
-    {
-      g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
-                           _("The active layer's pixels are locked."));
-      if (error)
-        gimp_tools_blink_lock_box (display->gimp, GIMP_ITEM (drawable));
-      return FALSE;
-    }
-
-  if (options->fill_area == GIMP_BUCKET_FILL_LINE_ART &&
-      ! gimp_line_art_get_input (bucket_tool->priv->line_art))
-    {
-      g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
-                           _("No valid line art source selected."));
-      if (error)
-        gimp_tools_blink_lock_box (display->gimp, GIMP_ITEM (drawable));
-      return FALSE;
-    }
-
-  return TRUE;
-}
-
 static void
 gimp_bucket_fill_tool_start (GimpBucketFillTool *tool,
                              const GimpCoords   *coords,
@@ -517,6 +462,7 @@ gimp_bucket_fill_tool_button_press (GimpTool            *tool,
   GimpBucketFillTool    *bucket_tool = GIMP_BUCKET_FILL_TOOL (tool);
   GimpBucketFillOptions *options     = GIMP_BUCKET_FILL_TOOL_GET_OPTIONS (tool);
   GimpImage             *image       = gimp_display_get_image (display);
+  GimpDrawable          *drawable    = gimp_image_get_active_drawable (image);
   gboolean               sample_merged;
 
   if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
@@ -526,13 +472,42 @@ gimp_bucket_fill_tool_button_press (GimpTool            *tool,
       return;
     }
 
+  if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable)))
+    {
+      gimp_tool_message_literal (tool, display,
+                                 _("Cannot modify the pixels of layer groups."));
+      return;
+    }
+
+  if (! gimp_item_is_visible (GIMP_ITEM (drawable)))
+    {
+      gimp_tool_message_literal (tool, display,
+                                 _("The active layer is not visible."));
+      return;
+    }
+
+  if (gimp_item_is_content_locked (GIMP_ITEM (drawable)))
+    {
+      gimp_tool_message_literal (tool, display,
+                                 _("The active layer's pixels are locked."));
+      gimp_tools_blink_lock_box (display->gimp, GIMP_ITEM (drawable));
+      return;
+    }
+
+  if (options->fill_area == GIMP_BUCKET_FILL_LINE_ART &&
+      ! gimp_line_art_get_input (bucket_tool->priv->line_art))
+    {
+      gimp_tool_message_literal (tool, display,
+                                 _("No valid line art source selected."));
+      return;
+    }
+
   sample_merged = (options->fill_area == GIMP_BUCKET_FILL_LINE_ART ?
                    options->line_art_source == GIMP_LINE_ART_SOURCE_SAMPLE_MERGED :
                    options->sample_merged);
   if (press_type == GIMP_BUTTON_PRESS_NORMAL &&
       gimp_image_coords_in_active_pickable (image, coords, sample_merged, TRUE))
     {
-      GimpDrawable    *drawable = gimp_image_get_active_drawable (image);
       GimpContext     *context  = GIMP_CONTEXT (options);
       GimpFillOptions *fill_options;
       GError          *error = NULL;


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