From 8935f7fbb980cfe264511c9f18c2d398f4ed7abe Mon Sep 17 00:00:00 2001 From: buliabyak Date: Mon, 29 Dec 2008 05:25:23 +0000 Subject: [PATCH] add utility for recursively replacing groups with their members in a list of objects --- src/selection-chemistry.cpp | 30 ++++++++++++++++++++++++++++++ src/selection-chemistry.h | 3 ++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index f1bb46167..de8662cc3 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -593,6 +593,36 @@ void sp_selection_ungroup(SPDesktop *desktop) _("Ungroup")); } +/** Replace all groups in the list with their member objects, recursively; returns a new list, frees old */ +GSList * +sp_degroup_list (GSList *items) +{ + GSList *out = NULL; + bool has_groups = false; + for (GSList *item = items; item; item = item->next) { + if (!SP_IS_GROUP(item->data)) { + out = g_slist_prepend(out, item->data); + } else { + has_groups = true; + GSList *members = sp_item_group_item_list (SP_GROUP(item->data)); + for (GSList *member = members; member; member = member->next) { + out = g_slist_prepend(out, member->data); + } + g_slist_free (members); + } + } + out = g_slist_reverse (out); + g_slist_free (items); + + if (has_groups) { // recurse if we unwrapped a group - it may have contained others + out = sp_degroup_list (out); + } + + return out; +} + + +/** If items in the list have a common parent, return it, otherwise return NULL */ static SPGroup * sp_item_list_common_parent_group(GSList const *items) { diff --git a/src/selection-chemistry.h b/src/selection-chemistry.h index 15b6f2057..770f36853 100644 --- a/src/selection-chemistry.h +++ b/src/selection-chemistry.h @@ -126,8 +126,9 @@ void unlock_all_in_all_layers(SPDesktop *dt); void unhide_all(SPDesktop *dt); void unhide_all_in_all_layers(SPDesktop *dt); -/* selection cycling */ +GSList *sp_degroup_list (GSList *items); +/* selection cycling */ typedef enum { SP_CYCLE_SIMPLE, -- 2.30.2