Commit ec6600a0 authored by Michael Natterer's avatar Michael Natterer 😴

Refuse to edit locked drawables

Check whether the drawable to edit is locked in GimpTool::initialize()
and bail out with an appropriate error if it is. This currently
prevents cloning from locked drawables, will fix that later.
parent ee5b8c65
......@@ -167,6 +167,13 @@ gimp_blend_tool_initialize (GimpTool *tool,
return FALSE;
}
if (gimp_item_get_lock_content (GIMP_ITEM (drawable)))
{
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
_("The active layer's pixels are locked."));
return FALSE;
}
return TRUE;
}
......
......@@ -188,9 +188,7 @@ gimp_brightness_contrast_tool_initialize (GimpTool *tool,
gimp_config_reset (GIMP_CONFIG (bc_tool->config));
GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
return TRUE;
return GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
}
static GeglNode *
......
......@@ -26,6 +26,7 @@
#include "core/gimp.h"
#include "core/gimpdrawable-bucket-fill.h"
#include "core/gimperror.h"
#include "core/gimpimage.h"
#include "core/gimpitem.h"
#include "core/gimppickable.h"
......@@ -43,6 +44,9 @@
/* local function prototypes */
static gboolean gimp_bucket_fill_tool_initialize (GimpTool *tool,
GimpDisplay *display,
GError **error);
static void gimp_bucket_fill_tool_button_release (GimpTool *tool,
const GimpCoords *coords,
guint32 time,
......@@ -91,6 +95,7 @@ gimp_bucket_fill_tool_class_init (GimpBucketFillToolClass *klass)
{
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
tool_class->initialize = gimp_bucket_fill_tool_initialize;
tool_class->button_release = gimp_bucket_fill_tool_button_release;
tool_class->modifier_key = gimp_bucket_fill_tool_modifier_key;
tool_class->cursor_update = gimp_bucket_fill_tool_cursor_update;
......@@ -111,6 +116,28 @@ gimp_bucket_fill_tool_init (GimpBucketFillTool *bucket_fill_tool)
"context/context-pattern-select-set");
}
static gboolean
gimp_bucket_fill_tool_initialize (GimpTool *tool,
GimpDisplay *display,
GError **error)
{
GimpDrawable *drawable = gimp_image_get_active_drawable (display->image);
if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error))
{
return FALSE;
}
if (gimp_item_get_lock_content (GIMP_ITEM (drawable)))
{
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
_("The active layer's pixels are locked."));
return FALSE;
}
return TRUE;
}
static void
gimp_bucket_fill_tool_button_release (GimpTool *tool,
const GimpCoords *coords,
......
......@@ -166,9 +166,7 @@ gimp_color_balance_tool_initialize (GimpTool *tool,
gimp_config_reset (GIMP_CONFIG (cb_tool->config));
GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
return TRUE;
return GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
}
static GeglNode *
......
......@@ -159,7 +159,10 @@ gimp_colorize_tool_initialize (GimpTool *tool,
gimp_config_reset (GIMP_CONFIG (col_tool->config));
GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error))
{
return FALSE;
}
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
......
......@@ -224,7 +224,10 @@ gimp_curves_tool_initialize (GimpTool *tool,
gimp_config_reset (GIMP_CONFIG (c_tool->config));
GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error))
{
return FALSE;
}
/* always pick colors */
gimp_color_tool_enable (GIMP_COLOR_TOOL (tool),
......
......@@ -128,7 +128,10 @@ gimp_desaturate_tool_initialize (GimpTool *tool,
gimp_config_reset (GIMP_CONFIG (desaturate_tool->config));
GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error))
{
return FALSE;
}
gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (desaturate_tool->button),
desaturate_tool->config->mode);
......
......@@ -162,9 +162,7 @@ gimp_gegl_tool_initialize (GimpTool *tool,
if (g_tool->config)
gimp_config_reset (GIMP_CONFIG (g_tool->config));
GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
return TRUE;
return GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
}
static GeglNode *
......
......@@ -174,9 +174,7 @@ gimp_hue_saturation_tool_initialize (GimpTool *tool,
gimp_config_reset (GIMP_CONFIG (hs_tool->config));
GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
return TRUE;
return GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
}
static GeglNode *
......
......@@ -33,6 +33,7 @@
#include "core/gimp.h"
#include "core/gimpdrawable.h"
#include "core/gimperror.h"
#include "core/gimpimage.h"
#include "core/gimpimage-pick-color.h"
#include "core/gimpimagemap.h"
......@@ -266,6 +267,15 @@ gimp_image_map_tool_initialize (GimpTool *tool,
GimpToolInfo *tool_info = tool->tool_info;
GimpDrawable *drawable;
drawable = gimp_image_get_active_drawable (display->image);
if (gimp_item_get_lock_content (GIMP_ITEM (drawable)))
{
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
_("The active layer's pixels are locked."));
return FALSE;
}
/* set display so the dialog can be hidden on display destruction */
tool->display = display;
......@@ -334,8 +344,6 @@ gimp_image_map_tool_initialize (GimpTool *tool,
image_map_tool, 0);
}
drawable = gimp_image_get_active_drawable (display->image);
gimp_viewable_dialog_set_viewable (GIMP_VIEWABLE_DIALOG (image_map_tool->shell),
GIMP_VIEWABLE (drawable),
GIMP_CONTEXT (tool_info->tool_options));
......
......@@ -235,7 +235,10 @@ gimp_levels_tool_initialize (GimpTool *tool,
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (l_tool->active_picker),
FALSE);
GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error))
{
return FALSE;
}
gimp_int_combo_box_set_sensitivity (GIMP_INT_COMBO_BOX (l_tool->channel_menu),
levels_menu_sensitivity, drawable, NULL);
......
......@@ -27,6 +27,7 @@
#include "core/gimp.h"
#include "core/gimp-utils.h"
#include "core/gimpdrawable.h"
#include "core/gimperror.h"
#include "core/gimpimage.h"
#include "core/gimppaintinfo.h"
#include "core/gimpprojection.h"
......@@ -58,6 +59,9 @@ static GObject * gimp_paint_tool_constructor (GType type,
GObjectConstructParam *params);
static void gimp_paint_tool_finalize (GObject *object);
static gboolean gimp_paint_tool_initialize (GimpTool *tool,
GimpDisplay *display,
GError **error);
static void gimp_paint_tool_control (GimpTool *tool,
GimpToolAction action,
GimpDisplay *display);
......@@ -111,6 +115,7 @@ gimp_paint_tool_class_init (GimpPaintToolClass *klass)
object_class->constructor = gimp_paint_tool_constructor;
object_class->finalize = gimp_paint_tool_finalize;
tool_class->initialize = gimp_paint_tool_initialize;
tool_class->control = gimp_paint_tool_control;
tool_class->button_press = gimp_paint_tool_button_press;
tool_class->button_release = gimp_paint_tool_button_release;
......@@ -216,6 +221,29 @@ gimp_paint_tool_enable_color_picker (GimpPaintTool *tool,
GIMP_COLOR_TOOL (tool)->pick_mode = mode;
}
static gboolean
gimp_paint_tool_initialize (GimpTool *tool,
GimpDisplay *display,
GError **error)
{
GimpDrawable *drawable = gimp_image_get_active_drawable (display->image);
if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error))
{
return FALSE;
}
if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)) &&
gimp_item_get_lock_content (GIMP_ITEM (drawable)))
{
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
_("The active layer's pixels are locked."));
return FALSE;
}
return TRUE;
}
static void
gimp_paint_tool_control (GimpTool *tool,
GimpToolAction action,
......
......@@ -216,6 +216,11 @@ gimp_perspective_clone_tool_initialize (GimpTool *tool,
{
GimpPerspectiveCloneTool *clone_tool = GIMP_PERSPECTIVE_CLONE_TOOL (tool);
if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error))
{
return FALSE;
}
if (display != tool->display)
{
gint i;
......
......@@ -154,7 +154,10 @@ gimp_posterize_tool_initialize (GimpTool *tool,
gimp_config_reset (GIMP_CONFIG (posterize_tool->config));
GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error))
{
return FALSE;
}
gtk_adjustment_set_value (posterize_tool->levels_data,
posterize_tool->config->levels);
......
......@@ -164,7 +164,10 @@ gimp_threshold_tool_initialize (GimpTool *tool,
gimp_config_reset (GIMP_CONFIG (t_tool->config));
GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error))
{
return FALSE;
}
gimp_drawable_calculate_histogram (drawable, t_tool->histogram);
gimp_histogram_view_set_histogram (t_tool->histogram_box->view,
......
......@@ -35,6 +35,7 @@
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpdrawable-transform.h"
#include "core/gimperror.h"
#include "core/gimpimage.h"
#include "core/gimpimage-undo.h"
#include "core/gimpimage-undo-push.h"
......@@ -333,6 +334,21 @@ gimp_transform_tool_initialize (GimpTool *tool,
GError **error)
{
GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tool);
GimpDrawable *drawable;
drawable = gimp_image_get_active_drawable (display->image);
if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error))
{
return FALSE;
}
if (gimp_item_get_lock_content (GIMP_ITEM (drawable)))
{
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
_("The active layer's pixels are locked."));
return FALSE;
}
if (display != tool->display)
{
......@@ -340,7 +356,7 @@ gimp_transform_tool_initialize (GimpTool *tool,
/* Set the pointer to the active display */
tool->display = display;
tool->drawable = gimp_image_get_active_drawable (display->image);
tool->drawable = drawable;
/* Initialize the transform tool dialog */
if (! tr_tool->dialog)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment