app: Toggle Layers/Channels/Vectors visibility action multi-item aware.

This commit is contained in:
Jehan 2023-01-10 18:41:31 +01:00
parent 955dd922a7
commit 7c7c62a1df
5 changed files with 60 additions and 22 deletions

View File

@ -489,11 +489,11 @@ channels_visible_cmd_callback (GimpAction *action,
GVariant *value,
gpointer data)
{
GimpImage *image;
GimpChannel *channel;
return_if_no_channel (image, channel, data);
GimpImage *image;
GList *channels;
return_if_no_channels (image, channels, data);
items_visible_cmd_callback (action, value, image, GIMP_ITEM (channel));
items_visible_cmd_callback (action, value, image, channels);
}
void

View File

@ -65,24 +65,62 @@ void
items_visible_cmd_callback (GimpAction *action,
GVariant *value,
GimpImage *image,
GimpItem *item)
GList *items)
{
gboolean visible = g_variant_get_boolean (value);
GimpUndo *undo;
gboolean push_undo = TRUE;
GList *start = NULL;
GList *iter;
gboolean visible = g_variant_get_boolean (value);
gint n_items = 0;
if (visible != gimp_item_get_visible (item))
for (iter = items; iter; iter = iter->next)
{
GimpUndo *undo;
gboolean push_undo = TRUE;
if (visible && gimp_item_get_visible (iter->data))
{
/* If any of the items are already visible, we don't
* toggle the selection visibility.
*/
return;
}
}
for (iter = items; iter; iter = iter->next)
if (visible != gimp_item_get_visible (iter->data))
{
if (start == NULL)
start = iter;
n_items++;
}
if (n_items == 0)
{
return;
}
else if (n_items == 1)
{
undo = gimp_image_undo_can_compress (image, GIMP_TYPE_ITEM_UNDO,
GIMP_UNDO_ITEM_VISIBILITY);
if (undo && GIMP_ITEM_UNDO (undo)->item == item)
if (undo && GIMP_ITEM_UNDO (undo)->item == GIMP_ITEM (start->data))
push_undo = FALSE;
gimp_item_set_visible (item, 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 = start; iter; iter = iter->next)
if (visible != gimp_item_get_visible (iter->data))
gimp_item_set_visible (iter->data, visible, push_undo);
if (n_items != 1)
gimp_image_undo_group_end (image);
gimp_image_flush (image);
}
void

View File

@ -22,7 +22,7 @@
void items_visible_cmd_callback (GimpAction *action,
GVariant *value,
GimpImage *image,
GimpItem *item);
GList *items);
void items_lock_content_cmd_callback (GimpAction *action,
GVariant *value,
GimpImage *image,

View File

@ -2017,13 +2017,13 @@ layers_composite_mode_cmd_callback (GimpAction *action,
void
layers_visible_cmd_callback (GimpAction *action,
GVariant *value,
gpointer data)
gpointer data)
{
GimpImage *image;
GimpLayer *layer;
return_if_no_layer (image, layer, data);
GList *layers;
return_if_no_layers (image, layers, data);
items_visible_cmd_callback (action, value, image, GIMP_ITEM (layer));
items_visible_cmd_callback (action, value, image, layers);
}
void

View File

@ -721,11 +721,11 @@ vectors_visible_cmd_callback (GimpAction *action,
GVariant *value,
gpointer data)
{
GimpImage *image;
GimpVectors *vectors;
return_if_no_vectors (image, vectors, data);
GimpImage *image;
GList *vectors;
return_if_no_vectors_list (image, vectors, data);
items_visible_cmd_callback (action, value, image, GIMP_ITEM (vectors));
items_visible_cmd_callback (action, value, image, vectors);
}
void