app: action "drawable-visible" now multi-layer aware.

This commit is contained in:
Jehan 2020-08-03 19:49:26 +02:00
parent 6d2b6b8ea0
commit c73ac8fdf4
2 changed files with 71 additions and 17 deletions

View File

@ -159,8 +159,9 @@ drawable_actions_update (GimpActionGroup *group,
{
GimpImage *image;
GimpDrawable *drawable = NULL;
GList *drawables = NULL;
gboolean has_visible = FALSE;
gboolean is_rgb = FALSE;
gboolean visible = FALSE;
gboolean linked = FALSE;
gboolean locked = FALSE;
gboolean can_lock = FALSE;
@ -169,12 +170,23 @@ drawable_actions_update (GimpActionGroup *group,
gboolean writable = FALSE;
gboolean movable = FALSE;
gboolean children = FALSE;
GList *iter;
image = action_data_get_image (data);
if (image)
{
drawable = gimp_image_get_active_drawable (image);
drawables = gimp_image_get_selected_drawables (image);
for (iter = drawables; iter; iter = iter->next)
{
if (gimp_item_get_visible (iter->data))
has_visible = TRUE;
if (has_visible)
break;
}
if (drawable)
{
@ -187,7 +199,6 @@ drawable_actions_update (GimpActionGroup *group,
else
item = GIMP_ITEM (drawable);
visible = gimp_item_get_visible (item);
linked = gimp_item_get_linked (item);
locked = gimp_item_get_lock_content (item);
can_lock = gimp_item_can_lock_content (item);
@ -209,12 +220,12 @@ drawable_actions_update (GimpActionGroup *group,
SET_SENSITIVE ("drawable-equalize", writable && !children);
SET_SENSITIVE ("drawable-levels-stretch", writable && !children && is_rgb);
SET_SENSITIVE ("drawable-visible", drawable);
SET_SENSITIVE ("drawable-visible", drawables);
SET_SENSITIVE ("drawable-linked", drawable);
SET_SENSITIVE ("drawable-lock-content", can_lock);
SET_SENSITIVE ("drawable-lock-position", can_lock_pos);
SET_ACTIVE ("drawable-visible", visible);
SET_ACTIVE ("drawable-visible", has_visible);
SET_ACTIVE ("drawable-linked", linked);
SET_ACTIVE ("drawable-lock-content", locked);
SET_ACTIVE ("drawable-lock-position", locked_pos);
@ -228,4 +239,6 @@ drawable_actions_update (GimpActionGroup *group,
#undef SET_SENSITIVE
#undef SET_ACTIVE
g_list_free (drawables);
}

View File

@ -122,30 +122,71 @@ drawable_visible_cmd_callback (GimpAction *action,
gpointer data)
{
GimpImage *image;
GimpDrawable *drawable;
GList *drawables;
GList *iter;
GimpUndo *undo;
gboolean push_undo = TRUE;
gboolean visible;
return_if_no_drawable (image, drawable, data);
return_if_no_drawables (image, drawables, data);
visible = g_variant_get_boolean (value);
if (GIMP_IS_LAYER_MASK (drawable))
drawable =
GIMP_DRAWABLE (gimp_layer_mask_get_layer (GIMP_LAYER_MASK (drawable)));
if (visible != gimp_item_get_visible (GIMP_ITEM (drawable)))
if (GIMP_IS_LAYER_MASK (drawables->data))
{
GimpUndo *undo;
gboolean push_undo = TRUE;
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 (visible && gimp_item_get_visible (iter->data))
{
/* If any of the drawables are already visible, we don't
* toggle the selection visibility. This prevents the
* SET_ACTIVE() in drawables-actions.c to toggle visibility
* unexpectedly.
*/
g_list_free (drawables);
return;
}
}
for (iter = drawables; iter; iter = iter->next)
if (visible != gimp_item_get_visible (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_VISIBILITY);
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_visible (GIMP_ITEM (drawable), visible, 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_VISIBILITY,
"Item visibility");
}
for (; iter; iter = iter->next)
gimp_item_set_visible (iter->data, visible, push_undo);
if (g_list_length (drawables) != 1)
gimp_image_undo_group_end (image);
gimp_image_flush (image);
}
void