summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbulia byak <buliabyak@gmail.com>2008-12-29 05:25:23 +0000
committerbuliabyak <buliabyak@users.sourceforge.net>2008-12-29 05:25:23 +0000
commit88ae433d132f7f44ad0bb3264c6a00623eb9e676 (patch)
treed906ebf0d81acc733fb5ff7f481938a6f1660c3a /src
parentcoding style (diff)
downloadinkscape-88ae433d132f7f44ad0bb3264c6a00623eb9e676.tar.gz
inkscape-88ae433d132f7f44ad0bb3264c6a00623eb9e676.zip
add utility for recursively replacing groups with their members in a list of objects
(bzr r7035)
Diffstat (limited to 'src')
-rw-r--r--src/selection-chemistry.cpp30
-rw-r--r--src/selection-chemistry.h3
2 files changed, 32 insertions, 1 deletions
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,