[gimp] app: make "drawable-lock-content|position" multi-drawable aware.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: make "drawable-lock-content|position" multi-drawable aware.
- Date: Tue, 18 Oct 2022 20:06:29 +0000 (UTC)
commit 85adfb46c8d101c51d3ca4581f6f4821e8d4fb6d
Author: Jehan <jehan girinstud io>
Date: Tue Oct 18 21:36:55 2022 +0200
app: make "drawable-lock-content|position" multi-drawable aware.
app/actions/drawable-actions.c | 41 ++++++++-----
app/actions/drawable-commands.c | 130 ++++++++++++++++++++++++++++++----------
2 files changed, 124 insertions(+), 47 deletions(-)
---
diff --git a/app/actions/drawable-actions.c b/app/actions/drawable-actions.c
index 8f1adbd097..0550d09ecd 100644
--- a/app/actions/drawable-actions.c
+++ b/app/actions/drawable-actions.c
@@ -57,23 +57,23 @@ static const GimpActionEntry drawable_actions[] =
static const GimpToggleActionEntry drawable_toggle_actions[] =
{
{ "drawable-visible", GIMP_ICON_VISIBLE,
- NC_("drawable-action", "Toggle Drawable _Visibility"), NULL, NULL,
+ NC_("drawable-action", "Toggle Drawables _Visibility"), NULL, NULL,
drawable_visible_cmd_callback,
FALSE,
GIMP_HELP_LAYER_VISIBLE },
{ "drawable-lock-content", GIMP_ICON_LOCK_CONTENT,
- NC_("drawable-action", "L_ock Pixels of Drawable"), NULL,
+ NC_("drawable-action", "L_ock Pixels of Drawables"), NULL,
NC_("drawable-action",
- "Keep the pixels on this drawable from being modified"),
+ "Keep the pixels on selected drawables from being modified"),
drawable_lock_content_cmd_callback,
FALSE,
GIMP_HELP_LAYER_LOCK_PIXELS },
{ "drawable-lock-position", GIMP_ICON_LOCK_POSITION,
- NC_("drawable-action", "L_ock Position of Drawable"), NULL,
+ NC_("drawable-action", "L_ock Position of Drawables"), NULL,
NC_("drawable-action",
- "Keep the position on this drawable from being modified"),
+ "Keep the position on selected drawables from being modified"),
drawable_lock_position_cmd_callback,
FALSE,
GIMP_HELP_LAYER_LOCK_POSITION },
@@ -152,13 +152,12 @@ drawable_actions_update (GimpActionGroup *group,
gpointer data)
{
GimpImage *image;
- GimpDrawable *drawable = NULL;
GList *drawables = NULL;
gboolean has_visible = FALSE;
gboolean is_rgb = FALSE;
- gboolean locked = FALSE;
+ gboolean locked = TRUE;
gboolean can_lock = FALSE;
- gboolean locked_pos = FALSE;
+ gboolean locked_pos = TRUE;
gboolean can_lock_pos = FALSE;
gboolean writable = FALSE;
gboolean movable = FALSE;
@@ -169,7 +168,6 @@ drawable_actions_update (GimpActionGroup *group,
if (image)
{
- drawable = gimp_image_get_active_drawable (image);
drawables = gimp_image_get_selected_drawables (image);
for (iter = drawables; iter; iter = iter->next)
@@ -177,13 +175,28 @@ drawable_actions_update (GimpActionGroup *group,
if (gimp_item_get_visible (iter->data))
has_visible = TRUE;
- if (has_visible)
+ if (gimp_item_can_lock_content (iter->data))
+ {
+ if (! gimp_item_get_lock_content (iter->data))
+ locked = FALSE;
+ can_lock = TRUE;
+ }
+
+ if (gimp_item_can_lock_position (iter->data))
+ {
+ if (! gimp_item_get_lock_position (iter->data))
+ locked_pos = FALSE;
+ can_lock_pos = TRUE;
+ }
+
+ if (has_visible && ! locked && ! locked_pos)
break;
}
- if (drawable)
+ if (g_list_length (drawables) == 1)
{
- GimpItem *item;
+ GimpDrawable *drawable = drawables->data;
+ GimpItem *item;
is_rgb = gimp_drawable_is_rgb (drawable);
@@ -192,11 +205,7 @@ drawable_actions_update (GimpActionGroup *group,
else
item = GIMP_ITEM (drawable);
- locked = gimp_item_get_lock_content (item);
- can_lock = gimp_item_can_lock_content (item);
writable = ! gimp_item_is_content_locked (item, NULL);
- locked_pos = gimp_item_get_lock_position (item);
- can_lock_pos = gimp_item_can_lock_position (item);
movable = ! gimp_item_is_position_locked (item, NULL);
if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable)))
diff --git a/app/actions/drawable-commands.c b/app/actions/drawable-commands.c
index 17c2b84175..628012bb81 100644
--- a/app/actions/drawable-commands.c
+++ b/app/actions/drawable-commands.c
@@ -154,6 +154,7 @@ drawable_visible_cmd_callback (GimpAction *action,
gimp_image_undo_group_end (image);
gimp_image_flush (image);
+ g_list_free (drawables);
}
void
@@ -161,35 +162,67 @@ drawable_lock_content_cmd_callback (GimpAction *action,
GVariant *value,
gpointer data)
{
- GimpImage *image;
- GimpDrawable *drawable;
- gboolean locked;
- return_if_no_drawable (image, drawable, data);
+ GimpImage *image;
+ GList *drawables;
+ GList *iter;
+ gboolean locked;
+ gboolean push_undo = TRUE;
+
+ return_if_no_drawables (image, drawables, data);
locked = 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);
+
+ g_list_free (drawables);
+ drawables = g_list_prepend (NULL, gimp_layer_mask_get_layer (mask));
+ }
+
+ for (iter = drawables; iter; iter = iter->next)
+ {
+ if (! locked && ! gimp_item_get_lock_content (iter->data))
+ {
+ /* If any of the drawables are already unlocked, we don't toggle the
+ * lock. This prevents the SET_ACTIVE() in drawables-actions.c to
+ * toggle locks unexpectedly.
+ */
+ g_list_free (drawables);
+ return;
+ }
+ }
+
+ for (iter = drawables; iter; iter = iter->next)
+ if (locked != gimp_item_get_lock_content (iter->data))
+ break;
- if (locked != gimp_item_get_lock_content (GIMP_ITEM (drawable)))
+ if (g_list_length (drawables) == 1)
{
-#if 0
GimpUndo *undo;
-#endif
- gboolean push_undo = TRUE;
-#if 0
undo = gimp_image_undo_can_compress (image, GIMP_TYPE_ITEM_UNDO,
- GIMP_UNDO_ITEM_VISIBILITY);
+ GIMP_UNDO_ITEM_LOCK_CONTENT);
- if (undo && GIMP_ITEM_UNDO (undo)->item == GIMP_ITEM (drawable))
+ if (undo && GIMP_ITEM_UNDO (undo)->item == GIMP_ITEM (drawables->data))
push_undo = FALSE;
-#endif
-
- gimp_item_set_lock_content (GIMP_ITEM (drawable), locked, push_undo);
- gimp_image_flush (image);
}
+ else
+ {
+ /* TODO: undo groups cannot be compressed so far. */
+ gimp_image_undo_group_start (image,
+ GIMP_UNDO_GROUP_ITEM_LOCK_CONTENTS,
+ _("Lock/Unlock content"));
+ }
+
+ for (; iter; iter = iter->next)
+ gimp_item_set_lock_content (iter->data, locked, push_undo);
+
+ if (g_list_length (drawables) != 1)
+ gimp_image_undo_group_end (image);
+
+ gimp_image_flush (image);
+ g_list_free (drawables);
}
void
@@ -197,31 +230,66 @@ drawable_lock_position_cmd_callback (GimpAction *action,
GVariant *value,
gpointer data)
{
- GimpImage *image;
- GimpDrawable *drawable;
- gboolean locked;
- return_if_no_drawable (image, drawable, data);
+ GimpImage *image;
+ GList *drawables;
+ GList *iter;
+ gboolean locked;
+ gboolean push_undo = TRUE;
+
+ return_if_no_drawables (image, drawables, data);
locked = 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);
+
+ g_list_free (drawables);
+ drawables = g_list_prepend (NULL, gimp_layer_mask_get_layer (mask));
+ }
- if (locked != gimp_item_get_lock_position (GIMP_ITEM (drawable)))
+ for (iter = drawables; iter; iter = iter->next)
+ {
+ if (! locked && ! gimp_item_get_lock_position (iter->data))
+ {
+ /* If any of the drawables are already unlocked, we don't toggle the
+ * lock. This prevents the SET_ACTIVE() in drawables-actions.c to
+ * toggle locks unexpectedly.
+ */
+ g_list_free (drawables);
+ return;
+ }
+ }
+
+ for (iter = drawables; iter; iter = iter->next)
+ if (locked != gimp_item_get_lock_position (iter->data))
+ break;
+
+ if (g_list_length (drawables) == 1)
{
GimpUndo *undo;
- gboolean push_undo = TRUE;
undo = gimp_image_undo_can_compress (image, GIMP_TYPE_ITEM_UNDO,
GIMP_UNDO_ITEM_LOCK_POSITION);
- if (undo && GIMP_ITEM_UNDO (undo)->item == GIMP_ITEM (drawable))
+ if (undo && GIMP_ITEM_UNDO (undo)->item == GIMP_ITEM (drawables->data))
push_undo = FALSE;
-
- gimp_item_set_lock_position (GIMP_ITEM (drawable), locked, push_undo);
- gimp_image_flush (image);
}
+ else
+ {
+ /* TODO: undo groups cannot be compressed so far. */
+ gimp_image_undo_group_start (image,
+ GIMP_UNDO_GROUP_ITEM_LOCK_POSITION,
+ _("Lock/Unlock position"));
+ }
+
+ for (; iter; iter = iter->next)
+ gimp_item_set_lock_position (iter->data, locked, 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]