[gimp/gimp-2-10] app: don't allow transforming invisible layers in flip/measure tools
- From: Ell <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gimp-2-10] app: don't allow transforming invisible layers in flip/measure tools
- Date: Sun, 10 Jun 2018 07:59:13 +0000 (UTC)
commit d670edb339d1f3b9be6283924d4afc6955d3c75a
Author: Ell <ell_se yahoo com>
Date: Sun Jun 10 03:48:30 2018 -0400
app: don't allow transforming invisible layers in flip/measure tools
Split gimp_transform_tool_get_active_item() into two functions:
gimp_transform_tool_get_active_item(), which returns the item
without checking for errors, and
gimp_transform_tool_check_active_item(), which returns the active
item while checking for errors. Adapt the rest of the code to the
change.
Remove the invisible_layer_ok parameter of
gimp_transform_tool_check_active_item(), and always return an error
when the active layer is invisible. This causes the flip and
measure tools to correctly reject invisible layers. Un-hide the
active item in GimpTransformGridTool before transforming, to avoid
rejecting layers that were hidden by the tool.
(cherry picked from commit 360b25b9a8f1a7a6063724e29b88a36463fc46c5)
app/tools/gimpfliptool.c | 2 +-
app/tools/gimptransformgridtool.c | 18 +++++++-----
app/tools/gimptransformtool.c | 61 ++++++++++++++++++++++++++++-----------
app/tools/gimptransformtool.h | 23 ++++++++-------
4 files changed, 67 insertions(+), 37 deletions(-)
---
diff --git a/app/tools/gimpfliptool.c b/app/tools/gimpfliptool.c
index db5e5820af..6ee48a0899 100644
--- a/app/tools/gimpfliptool.c
+++ b/app/tools/gimpfliptool.c
@@ -252,7 +252,7 @@ gimp_flip_tool_cursor_update (GimpTool *tool,
GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tool);
GimpFlipTool *flip = GIMP_FLIP_TOOL (tool);
- if (! gimp_transform_tool_get_active_item (tr_tool, display, TRUE, NULL))
+ if (! gimp_transform_tool_check_active_item (tr_tool, display, NULL))
{
gimp_tool_set_cursor (tool, display,
gimp_tool_control_get_cursor (tool->control),
diff --git a/app/tools/gimptransformgridtool.c b/app/tools/gimptransformgridtool.c
index 26bcd176bb..0f9d153f86 100644
--- a/app/tools/gimptransformgridtool.c
+++ b/app/tools/gimptransformgridtool.c
@@ -242,7 +242,7 @@ gimp_transform_grid_tool_initialize (GimpTool *tool,
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
GimpItem *item;
- item = gimp_transform_tool_get_active_item (tr_tool, display, FALSE, error);
+ item = gimp_transform_tool_check_active_item (tr_tool, display, error);
if (! item)
return FALSE;
@@ -445,7 +445,8 @@ gimp_transform_grid_tool_cursor_update (GimpTool *tool,
{
GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tool);
- if (! gimp_transform_tool_get_active_item (tr_tool, display, TRUE, NULL))
+ if (display != tool->display &&
+ ! gimp_transform_tool_check_active_item (tr_tool, display, NULL))
{
gimp_tool_set_cursor (tool, display,
gimp_tool_control_get_cursor (tool->control),
@@ -574,8 +575,7 @@ gimp_transform_grid_tool_options_notify (GimpTool *tool,
gimp_canvas_item_set_visible (tg_tool->preview, show_preview);
display = tool->display;
- item = gimp_transform_tool_get_active_item (tr_tool,
- display, TRUE, NULL);
+ item = gimp_transform_tool_get_active_item (tr_tool, display);
if (item)
{
if (show_preview)
@@ -905,6 +905,11 @@ gimp_transform_grid_tool_commit (GimpTransformGridTool *tg_tool)
/* undraw the tool before we muck around with the transform matrix */
gimp_draw_tool_stop (GIMP_DRAW_TOOL (tg_tool));
+ /* un-hide the active item before transforming, so that GimpTransformTool
+ * doesn't refuse to transform it.
+ */
+ gimp_transform_grid_tool_show_active_item (tg_tool);
+
gimp_transform_tool_transform (tr_tool, display);
}
@@ -971,10 +976,7 @@ gimp_transform_grid_tool_prepare (GimpTransformGridTool *tg_tool,
if (tg_tool->gui)
{
- GimpItem *item = gimp_transform_tool_get_active_item (tr_tool,
- display, TRUE, NULL);
-
- g_return_if_fail (item != NULL);
+ GimpItem *item = gimp_transform_tool_get_active_item (tr_tool, display);
gimp_tool_gui_set_shell (tg_tool->gui, gimp_display_get_shell (display));
gimp_tool_gui_set_viewable (tg_tool->gui, GIMP_VIEWABLE (item));
diff --git a/app/tools/gimptransformtool.c b/app/tools/gimptransformtool.c
index 2b50e4594e..f7f7ab10bd 100644
--- a/app/tools/gimptransformtool.c
+++ b/app/tools/gimptransformtool.c
@@ -265,19 +265,14 @@ gimp_transform_tool_recalc_matrix (GimpTransformTool *tr_tool,
GimpItem *
gimp_transform_tool_get_active_item (GimpTransformTool *tr_tool,
- GimpDisplay *display,
- gboolean invisible_layer_ok,
- GError **error)
+ GimpDisplay *display)
{
GimpTransformOptions *options;
GimpImage *image;
- GimpItem *item = NULL;
- const gchar *null_message = NULL;
- const gchar *locked_message = NULL;
+ GimpItem *item = NULL;
g_return_val_if_fail (GIMP_IS_TRANSFORM_TOOL (tr_tool), NULL);
g_return_val_if_fail (GIMP_IS_DISPLAY (display), NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tr_tool);
@@ -288,7 +283,45 @@ gimp_transform_tool_get_active_item (GimpTransformTool *tr_tool,
switch (options->type)
{
case GIMP_TRANSFORM_TYPE_LAYER:
- item = GIMP_ITEM (gimp_image_get_active_drawable (image));
+ item = GIMP_ITEM (gimp_image_get_active_drawable (image));
+ break;
+
+ case GIMP_TRANSFORM_TYPE_SELECTION:
+ item = GIMP_ITEM (gimp_image_get_mask (image));
+
+ if (gimp_channel_is_empty (GIMP_CHANNEL (item)))
+ item = NULL;
+ break;
+
+ case GIMP_TRANSFORM_TYPE_PATH:
+ item = GIMP_ITEM (gimp_image_get_active_vectors (image));
+ break;
+ }
+
+ return item;
+}
+
+GimpItem *
+gimp_transform_tool_check_active_item (GimpTransformTool *tr_tool,
+ GimpDisplay *display,
+ GError **error)
+{
+ GimpTransformOptions *options;
+ GimpItem *item;
+ const gchar *null_message = NULL;
+ const gchar *locked_message = NULL;
+
+ g_return_val_if_fail (GIMP_IS_TRANSFORM_TOOL (tr_tool), NULL);
+ g_return_val_if_fail (GIMP_IS_DISPLAY (display), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tr_tool);
+
+ item = gimp_transform_tool_get_active_item (tr_tool, display);
+
+ switch (options->type)
+ {
+ case GIMP_TRANSFORM_TYPE_LAYER:
null_message = _("There is no layer to transform.");
if (item)
@@ -298,8 +331,7 @@ gimp_transform_tool_get_active_item (GimpTransformTool *tr_tool,
else if (gimp_item_is_position_locked (item))
locked_message = _("The active layer's position and size are locked.");
- /* invisible_layer_ok is such a hack, see bug #759194 */
- if (! invisible_layer_ok && ! gimp_item_is_visible (item))
+ if (! gimp_item_is_visible (item))
{
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
_("The active layer is not visible."));
@@ -316,12 +348,8 @@ gimp_transform_tool_get_active_item (GimpTransformTool *tr_tool,
break;
case GIMP_TRANSFORM_TYPE_SELECTION:
- item = GIMP_ITEM (gimp_image_get_mask (image));
null_message = _("There is no selection to transform.");
- if (gimp_channel_is_empty (GIMP_CHANNEL (item)))
- item = NULL;
-
if (item)
{
/* cannot happen, so don't translate these messages */
@@ -333,7 +361,6 @@ gimp_transform_tool_get_active_item (GimpTransformTool *tr_tool,
break;
case GIMP_TRANSFORM_TYPE_PATH:
- item = GIMP_ITEM (gimp_image_get_active_vectors (image));
null_message = _("There is no path to transform.");
if (item)
@@ -393,8 +420,8 @@ gimp_transform_tool_transform (GimpTransformTool *tr_tool,
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
- active_item = gimp_transform_tool_get_active_item (tr_tool, display, TRUE,
- &error);
+ active_item = gimp_transform_tool_check_active_item (tr_tool, display,
+ &error);
if (! active_item)
{
diff --git a/app/tools/gimptransformtool.h b/app/tools/gimptransformtool.h
index 8d0b6d3874..3e9c1921b1 100644
--- a/app/tools/gimptransformtool.h
+++ b/app/tools/gimptransformtool.h
@@ -74,20 +74,21 @@ struct _GimpTransformToolClass
};
-GType gimp_transform_tool_get_type (void) G_GNUC_CONST;
+GType gimp_transform_tool_get_type (void) G_GNUC_CONST;
-GimpItem * gimp_transform_tool_get_active_item (GimpTransformTool *tr_tool,
- GimpDisplay *display,
- gboolean invisible_layer_ok,
- GError **error);
+GimpItem * gimp_transform_tool_get_active_item (GimpTransformTool *tr_tool,
+ GimpDisplay *display);
+GimpItem * gimp_transform_tool_check_active_item (GimpTransformTool *tr_tool,
+ GimpDisplay *display,
+ GError **error);
-gboolean gimp_transform_tool_bounds (GimpTransformTool *tr_tool,
- GimpDisplay *display);
-void gimp_transform_tool_recalc_matrix (GimpTransformTool *tr_tool,
- GimpDisplay *display);
+gboolean gimp_transform_tool_bounds (GimpTransformTool *tr_tool,
+ GimpDisplay *display);
+void gimp_transform_tool_recalc_matrix (GimpTransformTool *tr_tool,
+ GimpDisplay *display);
-gboolean gimp_transform_tool_transform (GimpTransformTool *tr_tool,
- GimpDisplay *display);
+gboolean gimp_transform_tool_transform (GimpTransformTool *tr_tool,
+ GimpDisplay *display);
#endif /* __GIMP_TRANSFORM_TOOL_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]