Add gimp_image_item_list_filter()

New function takes a GList of items as returned by
gimp_image_item_list_get_list() and can filter out items that:

- have lock_content set to TRUE.
- are children of items that are also in the list (to avoid
  transforming group items *and* their children, because
  the group items already do that for us).
This commit is contained in:
Michael Natterer 2009-08-25 15:36:03 +02:00
parent 40cf6fa62a
commit cb1e3afba4
2 changed files with 73 additions and 0 deletions

View File

@ -216,3 +216,71 @@ gimp_image_item_list_get_list (const GimpImage *image,
return g_list_reverse (return_list); return g_list_reverse (return_list);
} }
static GList *
gimp_image_item_list_remove_children (GList *list,
const GimpItem *parent)
{
GList *l = list;
while (l)
{
GimpItem *item = l->data;
l = g_list_next (l);
if (gimp_viewable_is_ancestor (GIMP_VIEWABLE (parent),
GIMP_VIEWABLE (item)))
{
list = g_list_remove (list, item);
}
}
return list;
}
GList *
gimp_image_item_list_filter (const GimpItem *exclude,
GList *list,
gboolean remove_children,
gboolean remove_locked)
{
GList *l;
g_return_val_if_fail (exclude == NULL || GIMP_IS_ITEM (exclude), NULL);
if (! list)
return NULL;
if (exclude)
list = gimp_image_item_list_remove_children (list, exclude);
for (l = list; l; l = g_list_next (l))
{
GimpItem *item = l->data;
GList *next;
next = gimp_image_item_list_remove_children (g_list_next (l), item);
l->next = next;
if (next)
next->prev = l;
}
if (remove_locked)
{
l = list;
while (l)
{
GimpItem *item = l->data;
l = g_list_next (l);
if (gimp_item_get_lock_content (item))
list = g_list_remove (list, item);
}
}
return list;
}

View File

@ -52,5 +52,10 @@ GList * gimp_image_item_list_get_list (const GimpImage *image,
GimpItemTypeMask type, GimpItemTypeMask type,
GimpItemSet set); GimpItemSet set);
GList * gimp_image_item_list_filter (const GimpItem *exclude,
GList *list,
gboolean remove_children,
gboolean remove_locked);
#endif /* __GIMP_IMAGE_ITEM_LIST_H__ */ #endif /* __GIMP_IMAGE_ITEM_LIST_H__ */