app: make GimpItemList fully work on all item types

This commit is contained in:
Michael Natterer 2025-05-31 17:22:55 +02:00
parent 76e82d5572
commit f21aaf3416

View file

@ -187,8 +187,8 @@ gimp_item_list_constructed (GObject *object)
gimp_assert (GIMP_IS_IMAGE (set->p->image)); gimp_assert (GIMP_IS_IMAGE (set->p->image));
gimp_assert (set->p->item_type == GIMP_TYPE_LAYER || gimp_assert (set->p->item_type == GIMP_TYPE_LAYER ||
set->p->item_type == GIMP_TYPE_PATH || set->p->item_type == GIMP_TYPE_CHANNEL ||
set->p->item_type == GIMP_TYPE_CHANNEL); set->p->item_type == GIMP_TYPE_PATH);
if (! set->p->is_pattern) if (! set->p->is_pattern)
{ {
@ -196,10 +196,11 @@ gimp_item_list_constructed (GObject *object)
if (set->p->item_type == GIMP_TYPE_LAYER) if (set->p->item_type == GIMP_TYPE_LAYER)
container = gimp_image_get_layers (set->p->image); container = gimp_image_get_layers (set->p->image);
else if (set->p->item_type == GIMP_TYPE_PATH) else if (set->p->item_type == GIMP_TYPE_CHANNEL)
container = gimp_image_get_paths (set->p->image);
else
container = gimp_image_get_channels (set->p->image); container = gimp_image_get_channels (set->p->image);
else
container = gimp_image_get_paths (set->p->image);
g_signal_connect (container, "remove", g_signal_connect (container, "remove",
G_CALLBACK (gimp_item_list_item_remove), G_CALLBACK (gimp_item_list_item_remove),
set); set);
@ -220,10 +221,11 @@ gimp_item_list_dispose (GObject *object)
if (set->p->item_type == GIMP_TYPE_LAYER) if (set->p->item_type == GIMP_TYPE_LAYER)
container = gimp_image_get_layers (set->p->image); container = gimp_image_get_layers (set->p->image);
else if (set->p->item_type == GIMP_TYPE_PATH) else if (set->p->item_type == GIMP_TYPE_CHANNEL)
container = gimp_image_get_paths (set->p->image);
else
container = gimp_image_get_channels (set->p->image); container = gimp_image_get_channels (set->p->image);
else
container = gimp_image_get_paths (set->p->image);
g_signal_handlers_disconnect_by_func (container, g_signal_handlers_disconnect_by_func (container,
G_CALLBACK (gimp_item_list_item_remove), G_CALLBACK (gimp_item_list_item_remove),
set); set);
@ -349,10 +351,10 @@ gimp_item_list_named_new (GimpImage *image,
{ {
if (item_type == GIMP_TYPE_LAYER) if (item_type == GIMP_TYPE_LAYER)
items = gimp_image_get_selected_layers (image); items = gimp_image_get_selected_layers (image);
else if (item_type == GIMP_TYPE_PATH)
items = gimp_image_get_selected_paths (image);
else if (item_type == GIMP_TYPE_CHANNEL) else if (item_type == GIMP_TYPE_CHANNEL)
items = gimp_image_get_selected_channels (image); items = gimp_image_get_selected_channels (image);
else if (item_type == GIMP_TYPE_PATH)
items = gimp_image_get_selected_paths (image);
if (! items) if (! items)
return NULL; return NULL;
@ -555,7 +557,7 @@ gimp_item_list_get_items_by_substr (GimpItemList *set,
const gchar *pattern, const gchar *pattern,
GError **error) GError **error)
{ {
GList *items; GList *items = NULL;
GList *match = NULL; GList *match = NULL;
GList *iter; GList *iter;
@ -566,15 +568,11 @@ gimp_item_list_get_items_by_substr (GimpItemList *set,
return NULL; return NULL;
if (set->p->item_type == GIMP_TYPE_LAYER) if (set->p->item_type == GIMP_TYPE_LAYER)
{ items = gimp_image_get_layer_list (set->p->image);
items = gimp_image_get_layer_list (set->p->image); else if (set->p->item_type == GIMP_TYPE_CHANNEL)
} items = gimp_image_get_channel_list (set->p->image);
else else if (set->p->item_type == GIMP_TYPE_PATH)
{ items = gimp_image_get_path_list (set->p->image);
g_critical ("%s: only list of GimpLayer supported for now.",
G_STRFUNC);
return NULL;
}
for (iter = items; iter; iter = iter->next) for (iter = items; iter; iter = iter->next)
{ {
@ -604,7 +602,7 @@ gimp_item_list_get_items_by_glob (GimpItemList *set,
const gchar *pattern, const gchar *pattern,
GError **error) GError **error)
{ {
GList *items; GList *items = NULL;
GList *match = NULL; GList *match = NULL;
GList *iter; GList *iter;
GPatternSpec *spec; GPatternSpec *spec;
@ -616,15 +614,11 @@ gimp_item_list_get_items_by_glob (GimpItemList *set,
return NULL; return NULL;
if (set->p->item_type == GIMP_TYPE_LAYER) if (set->p->item_type == GIMP_TYPE_LAYER)
{ items = gimp_image_get_layer_list (set->p->image);
items = gimp_image_get_layer_list (set->p->image); else if (set->p->item_type == GIMP_TYPE_CHANNEL)
} items = gimp_image_get_channel_list (set->p->image);
else else if (set->p->item_type == GIMP_TYPE_PATH)
{ items = gimp_image_get_path_list (set->p->image);
g_critical ("%s: only list of GimpLayer supported for now.",
G_STRFUNC);
return NULL;
}
spec = g_pattern_spec_new (pattern); spec = g_pattern_spec_new (pattern);
for (iter = items; iter; iter = iter->next) for (iter = items; iter; iter = iter->next)
@ -656,7 +650,7 @@ gimp_item_list_get_items_by_regexp (GimpItemList *set,
const gchar *pattern, const gchar *pattern,
GError **error) GError **error)
{ {
GList *items; GList *items = NULL;
GList *match = NULL; GList *match = NULL;
GList *iter; GList *iter;
GRegex *regex; GRegex *regex;
@ -671,15 +665,11 @@ gimp_item_list_get_items_by_regexp (GimpItemList *set,
return NULL; return NULL;
if (set->p->item_type == GIMP_TYPE_LAYER) if (set->p->item_type == GIMP_TYPE_LAYER)
{ items = gimp_image_get_layer_list (set->p->image);
items = gimp_image_get_layer_list (set->p->image); else if (set->p->item_type == GIMP_TYPE_CHANNEL)
} items = gimp_image_get_channel_list (set->p->image);
else else if (set->p->item_type == GIMP_TYPE_PATH)
{ items = gimp_image_get_path_list (set->p->image);
g_critical ("%s: only list of GimpLayer supported for now.",
G_STRFUNC);
return NULL;
}
for (iter = items; iter; iter = iter->next) for (iter = items; iter; iter = iter->next)
{ {