[gimp] app: "drawable-linked" multi-drawable aware.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: "drawable-linked" multi-drawable aware.
- Date: Mon, 17 Aug 2020 16:29:10 +0000 (UTC)
commit e50f522d5bff841c9dcce32bffe3d52f62694dcd
Author: Jehan <jehan girinstud io>
Date: Mon Aug 17 18:28:26 2020 +0200
app: "drawable-linked" multi-drawable aware.
app/actions/drawable-actions.c | 12 ++++----
app/actions/drawable-commands.c | 66 +++++++++++++++++++++++++++++++++--------
2 files changed, 61 insertions(+), 17 deletions(-)
---
diff --git a/app/actions/drawable-actions.c b/app/actions/drawable-actions.c
index 23faac0722..99e1d222cc 100644
--- a/app/actions/drawable-actions.c
+++ b/app/actions/drawable-actions.c
@@ -161,8 +161,8 @@ drawable_actions_update (GimpActionGroup *group,
GimpDrawable *drawable = NULL;
GList *drawables = NULL;
gboolean has_visible = FALSE;
+ gboolean has_linked = FALSE;
gboolean is_rgb = FALSE;
- gboolean linked = FALSE;
gboolean locked = FALSE;
gboolean can_lock = FALSE;
gboolean locked_pos = FALSE;
@@ -184,7 +184,10 @@ drawable_actions_update (GimpActionGroup *group,
if (gimp_item_get_visible (iter->data))
has_visible = TRUE;
- if (has_visible)
+ if (gimp_item_get_linked (iter->data))
+ has_linked = TRUE;
+
+ if (has_visible && has_linked)
break;
}
@@ -199,7 +202,6 @@ drawable_actions_update (GimpActionGroup *group,
else
item = GIMP_ITEM (drawable);
- linked = gimp_item_get_linked (item);
locked = gimp_item_get_lock_content (item);
can_lock = gimp_item_can_lock_content (item);
writable = ! gimp_item_is_content_locked (item);
@@ -221,12 +223,12 @@ drawable_actions_update (GimpActionGroup *group,
SET_SENSITIVE ("drawable-levels-stretch", writable && !children && is_rgb);
SET_SENSITIVE ("drawable-visible", drawables);
- SET_SENSITIVE ("drawable-linked", drawable);
+ SET_SENSITIVE ("drawable-linked", drawables);
SET_SENSITIVE ("drawable-lock-content", can_lock);
SET_SENSITIVE ("drawable-lock-position", can_lock_pos);
SET_ACTIVE ("drawable-visible", has_visible);
- SET_ACTIVE ("drawable-linked", linked);
+ SET_ACTIVE ("drawable-linked", has_linked);
SET_ACTIVE ("drawable-lock-content", locked);
SET_ACTIVE ("drawable-lock-position", locked_pos);
diff --git a/app/actions/drawable-commands.c b/app/actions/drawable-commands.c
index 4e920562f7..720c40fb58 100644
--- a/app/actions/drawable-commands.c
+++ b/app/actions/drawable-commands.c
@@ -90,30 +90,72 @@ drawable_linked_cmd_callback (GimpAction *action,
gpointer data)
{
GimpImage *image;
- GimpDrawable *drawable;
+ GList *drawables;
+ GList *iter;
+ GimpUndo *undo = NULL;
+ gboolean push_undo = TRUE;
gboolean linked;
- return_if_no_drawable (image, drawable, data);
+
+ return_if_no_drawables (image, drawables, data);
linked = g_variant_get_boolean (value);
- if (GIMP_IS_LAYER_MASK (drawable))
- drawable =
- GIMP_DRAWABLE (gimp_layer_mask_get_layer (GIMP_LAYER_MASK (drawable)));
+ if (GIMP_IS_LAYER_MASK (drawables->data))
+ {
+ GimpLayerMask *mask = GIMP_LAYER_MASK (drawables->data);
- if (linked != gimp_item_get_linked (GIMP_ITEM (drawable)))
+ g_list_free (drawables);
+ drawables = g_list_prepend (NULL, gimp_layer_mask_get_layer (mask));
+ }
+
+ for (iter = drawables; iter; iter = iter->next)
{
- GimpUndo *undo;
- gboolean push_undo = TRUE;
+ if (linked && gimp_item_get_linked (iter->data))
+ {
+ /* If any of the drawables are already linked, we don't
+ * toggle the link. This prevents the SET_ACTIVE() in
+ * drawables-actions.c to toggle links unexpectedly.
+ */
+ g_list_free (drawables);
+ return;
+ }
+ }
+
+ for (iter = drawables; iter; iter = iter->next)
+ if (linked != gimp_item_get_linked (iter->data))
+ break;
+
+ if (! iter)
+ {
+ g_list_free (drawables);
+ return;
+ }
+ if (g_list_length (drawables) == 1)
+ {
undo = gimp_image_undo_can_compress (image, GIMP_TYPE_ITEM_UNDO,
GIMP_UNDO_ITEM_LINKED);
- if (undo && GIMP_ITEM_UNDO (undo)->item == GIMP_ITEM (drawable))
- push_undo = FALSE;
- gimp_item_set_linked (GIMP_ITEM (drawable), linked, push_undo);
- gimp_image_flush (image);
+ if (undo && GIMP_ITEM_UNDO (undo)->item == GIMP_ITEM (drawables->data))
+ push_undo = FALSE;
}
+ else
+ {
+ /* TODO: undo groups cannot be compressed so far. */
+ gimp_image_undo_group_start (image,
+ GIMP_UNDO_GROUP_ITEM_LINKED,
+ "Link/Unlink items");
+ }
+
+ for (; iter; iter = iter->next)
+ if (linked != gimp_item_get_linked (iter->data))
+ gimp_item_set_linked (iter->data, linked, push_undo);
+
+ if (g_list_length (drawables) != 1)
+ gimp_image_undo_group_end (image);
+
+ gimp_image_flush (image);
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]