[gimp/metadata-browser] app: let the drawable keep around a pointer to its floating selection
- From: Roman Joost <romanofski src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/metadata-browser] app: let the drawable keep around a pointer to its floating selection
- Date: Wed, 28 Sep 2011 10:50:36 +0000 (UTC)
commit 2ead39c7e9a1251eb0f251f5ac88a64b1ec7a941
Author: Michael Natterer <mitch gimp org>
Date: Fri Sep 23 19:31:50 2011 +0200
app: let the drawable keep around a pointer to its floating selection
Instead of getting the floating selection from the image. Change
gimp_drawable_has_floating_sel() to get_floating_sel() and remove the
"floating_sel" parameter from gimp_drawable_deatch_floating_sel().
This cleanup is one more step towards sanitizing floating selections,
and makes the crash fix in the next commit much much simpler.
app/core/gimpdrawable-private.h | 1 +
app/core/gimpdrawable.c | 55 +++++++++++++++++-------------------
app/core/gimpdrawable.h | 6 +---
app/core/gimpfloatingselundo.c | 4 +--
app/core/gimpimage.c | 13 +++++----
app/core/gimplayer-floating-sel.c | 4 +--
6 files changed, 38 insertions(+), 45 deletions(-)
---
diff --git a/app/core/gimpdrawable-private.h b/app/core/gimpdrawable-private.h
index 7a0edbb..3524bf1 100644
--- a/app/core/gimpdrawable-private.h
+++ b/app/core/gimpdrawable-private.h
@@ -28,6 +28,7 @@ struct _GimpDrawablePrivate
GeglNode *source_node;
GeglNode *tile_source_node;
+ GimpLayer *floating_selection;
GeglNode *fs_crop_node;
GeglNode *fs_opacity_node;
GeglNode *fs_offset_node;
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index 3d3842a..2bd684f 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -965,8 +965,7 @@ static void
gimp_drawable_sync_source_node (GimpDrawable *drawable,
gboolean detach_fs)
{
- GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
- GimpLayer *fs = gimp_image_get_floating_selection (image);
+ GimpLayer *fs = gimp_drawable_get_floating_sel (drawable);
GeglNode *output;
if (! drawable->private->source_node)
@@ -974,7 +973,7 @@ gimp_drawable_sync_source_node (GimpDrawable *drawable,
output = gegl_node_get_output_proxy (drawable->private->source_node, "output");
- if (gimp_drawable_has_floating_sel (drawable) && ! detach_fs)
+ if (fs && ! detach_fs)
{
gint off_x, off_y;
gint fs_off_x, fs_off_y;
@@ -1345,19 +1344,21 @@ gimp_drawable_init_src_region (GimpDrawable *drawable,
gint height,
TileManager **temp_tiles)
{
+ GimpLayer *fs;
+
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
g_return_if_fail (srcPR != NULL);
g_return_if_fail (temp_tiles != NULL);
- if (gimp_drawable_has_floating_sel (drawable))
+ fs = gimp_drawable_get_floating_sel (drawable);
+
+ if (fs)
{
- GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
- GimpLayer *fs = gimp_image_get_floating_selection (image);
- gint off_x, off_y;
- gint fs_off_x, fs_off_y;
- gint combine_x, combine_y;
- gint combine_width, combine_height;
+ gint off_x, off_y;
+ gint fs_off_x, fs_off_y;
+ gint combine_x, combine_y;
+ gint combine_width, combine_height;
gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
gimp_item_get_offset (GIMP_ITEM (fs), &fs_off_x, &fs_off_y);
@@ -1807,32 +1808,24 @@ gimp_drawable_bytes_without_alpha (const GimpDrawable *drawable)
return GIMP_IMAGE_TYPE_BYTES (type);
}
-gboolean
-gimp_drawable_has_floating_sel (const GimpDrawable *drawable)
+const guchar *
+gimp_drawable_get_colormap (const GimpDrawable *drawable)
{
GimpImage *image;
- GimpLayer *floating_sel;
- g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
+ g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
image = gimp_item_get_image (GIMP_ITEM (drawable));
- floating_sel = gimp_image_get_floating_selection (image);
-
- return (floating_sel &&
- gimp_layer_get_floating_sel_drawable (floating_sel) == drawable);
+ return image ? gimp_image_get_colormap (image) : NULL;
}
-const guchar *
-gimp_drawable_get_colormap (const GimpDrawable *drawable)
+GimpLayer *
+gimp_drawable_get_floating_sel (const GimpDrawable *drawable)
{
- GimpImage *image;
-
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
- image = gimp_item_get_image (GIMP_ITEM (drawable));
-
- return image ? gimp_image_get_colormap (image) : NULL;
+ return drawable->private->floating_selection;
}
void
@@ -1843,12 +1836,14 @@ gimp_drawable_attach_floating_sel (GimpDrawable *drawable,
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
+ g_return_if_fail (gimp_drawable_get_floating_sel (drawable) == NULL);
g_return_if_fail (GIMP_IS_LAYER (floating_sel));
GIMP_LOG (FLOATING_SELECTION, "%s", G_STRFUNC);
image = gimp_item_get_image (GIMP_ITEM (drawable));
+ drawable->private->floating_selection = floating_sel;
gimp_image_set_floating_selection (image, floating_sel);
/* clear the selection */
@@ -1868,17 +1863,18 @@ gimp_drawable_attach_floating_sel (GimpDrawable *drawable,
}
void
-gimp_drawable_detach_floating_sel (GimpDrawable *drawable,
- GimpLayer *floating_sel)
+gimp_drawable_detach_floating_sel (GimpDrawable *drawable)
{
GimpImage *image;
+ GimpLayer *floating_sel;
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
- g_return_if_fail (GIMP_IS_LAYER (floating_sel));
+ g_return_if_fail (gimp_drawable_get_floating_sel (drawable) != NULL);
GIMP_LOG (FLOATING_SELECTION, "%s", G_STRFUNC);
- image = gimp_item_get_image (GIMP_ITEM (drawable));
+ image = gimp_item_get_image (GIMP_ITEM (drawable));
+ floating_sel = drawable->private->floating_selection;
gimp_drawable_sync_source_node (drawable, TRUE);
@@ -1896,4 +1892,5 @@ gimp_drawable_detach_floating_sel (GimpDrawable *drawable,
gimp_drawable_invalidate_boundary (GIMP_DRAWABLE (floating_sel));
gimp_image_set_floating_selection (image, NULL);
+ drawable->private->floating_selection = NULL;
}
diff --git a/app/core/gimpdrawable.h b/app/core/gimpdrawable.h
index 5f3faec..3bb5d14 100644
--- a/app/core/gimpdrawable.h
+++ b/app/core/gimpdrawable.h
@@ -230,14 +230,12 @@ gint gimp_drawable_bytes (const GimpDrawable *drawable);
gint gimp_drawable_bytes_with_alpha (const GimpDrawable *drawable);
gint gimp_drawable_bytes_without_alpha(const GimpDrawable *drawable);
-gboolean gimp_drawable_has_floating_sel (const GimpDrawable *drawable);
-
const guchar * gimp_drawable_get_colormap (const GimpDrawable *drawable);
+GimpLayer * gimp_drawable_get_floating_sel (const GimpDrawable *drawable);
void gimp_drawable_attach_floating_sel (GimpDrawable *drawable,
GimpLayer *floating_sel);
-void gimp_drawable_detach_floating_sel (GimpDrawable *drawable,
- GimpLayer *floating_sel);
+void gimp_drawable_detach_floating_sel (GimpDrawable *drawable);
#endif /* __GIMP_DRAWABLE_H__ */
diff --git a/app/core/gimpfloatingselundo.c b/app/core/gimpfloatingselundo.c
index fb57731..aed2c3a 100644
--- a/app/core/gimpfloatingselundo.c
+++ b/app/core/gimpfloatingselundo.c
@@ -108,9 +108,7 @@ gimp_floating_sel_undo_pop (GimpUndo *undo,
}
else
{
- gimp_drawable_detach_floating_sel (gimp_layer_get_floating_sel_drawable (floating_layer),
- floating_layer);
-
+ gimp_drawable_detach_floating_sel (gimp_layer_get_floating_sel_drawable (floating_layer));
gimp_layer_set_floating_sel_drawable (floating_layer, NULL);
}
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index 9a4aac2..0c36071 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -3636,7 +3636,7 @@ gimp_image_remove_layer (GimpImage *image,
private = GIMP_IMAGE_GET_PRIVATE (image);
- if (gimp_drawable_has_floating_sel (GIMP_DRAWABLE (layer)))
+ if (gimp_drawable_get_floating_sel (GIMP_DRAWABLE (layer)))
{
if (! push_undo)
{
@@ -3650,7 +3650,8 @@ gimp_image_remove_layer (GimpImage *image,
C_("undo-type", "Remove Layer"));
undo_group = TRUE;
- gimp_image_remove_layer (image, gimp_image_get_floating_selection (image),
+ gimp_image_remove_layer (image,
+ gimp_drawable_get_floating_sel (GIMP_DRAWABLE (layer)),
TRUE, NULL);
}
@@ -3662,8 +3663,7 @@ gimp_image_remove_layer (GimpImage *image,
{
undo_desc = C_("undo-type", "Remove Floating Selection");
- gimp_drawable_detach_floating_sel (gimp_layer_get_floating_sel_drawable (layer),
- layer);
+ gimp_drawable_detach_floating_sel (gimp_layer_get_floating_sel_drawable (layer));
}
else
{
@@ -3856,7 +3856,7 @@ gimp_image_remove_channel (GimpImage *image,
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (channel)));
g_return_if_fail (gimp_item_get_image (GIMP_ITEM (channel)) == image);
- if (gimp_drawable_has_floating_sel (GIMP_DRAWABLE (channel)))
+ if (gimp_drawable_get_floating_sel (GIMP_DRAWABLE (channel)))
{
if (! push_undo)
{
@@ -3870,7 +3870,8 @@ gimp_image_remove_channel (GimpImage *image,
C_("undo-type", "Remove Channel"));
undo_group = TRUE;
- gimp_image_remove_layer (image, gimp_image_get_floating_selection (image),
+ gimp_image_remove_layer (image,
+ gimp_drawable_get_floating_sel (GIMP_DRAWABLE (channel)),
TRUE, NULL);
}
diff --git a/app/core/gimplayer-floating-sel.c b/app/core/gimplayer-floating-sel.c
index 0a9901e..bf607d1 100644
--- a/app/core/gimplayer-floating-sel.c
+++ b/app/core/gimplayer-floating-sel.c
@@ -134,9 +134,7 @@ floating_sel_to_layer (GimpLayer *layer,
gimp_image_undo_push_fs_to_layer (image, NULL, layer);
- gimp_drawable_detach_floating_sel (gimp_layer_get_floating_sel_drawable (layer),
- layer);
-
+ gimp_drawable_detach_floating_sel (gimp_layer_get_floating_sel_drawable (layer));
gimp_layer_set_floating_sel_drawable (layer, NULL);
gimp_item_set_visible (item, TRUE, TRUE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]