diff --git a/src/attributes.cpp b/src/attributes.cpp index 5dd9dcfc477b8c1083fa85d42f1c56ae9a34fe7b..3187b1950d575d83d87a75b4b6c94f18da6183e4 100644 --- a/src/attributes.cpp +++ b/src/attributes.cpp @@ -42,6 +42,7 @@ static SPStyleProp const props[] = { {SPAttr::PRESERVEASPECTRATIO, "preserveAspectRatio"}, {SPAttr::ONLOAD, "onload"}, {SPAttr::SODIPODI_DOCNAME, "sodipodi:docname"}, + {SPAttr::INKSCAPE_SELECTIONDATA, "inkscape:selectiondata"}, /* SPItem */ {SPAttr::TRANSFORM, "transform"}, {SPAttr::SODIPODI_TYPE, "sodipodi:type"}, diff --git a/src/attributes.h b/src/attributes.h index d3c946799df9b79584884d8e5a8298bb8fc6a174..a81d9dfcd1a33f8cd0e00881a79eb47d450cf2a1 100644 --- a/src/attributes.h +++ b/src/attributes.h @@ -40,6 +40,7 @@ enum class SPAttr { PRESERVEASPECTRATIO, ONLOAD, SODIPODI_DOCNAME, + INKSCAPE_SELECTIONDATA, /* SPItem */ TRANSFORM, SODIPODI_TYPE, diff --git a/src/extension/execution-env.cpp b/src/extension/execution-env.cpp index 0875d132fa75937b78f7a4a1a1582e240d8428cf..08144b8f8457b57ecf0c5e3341565e323eeb780b 100644 --- a/src/extension/execution-env.cpp +++ b/src/extension/execution-env.cpp @@ -24,6 +24,7 @@ #include "document-undo.h" #include "desktop.h" #include "object/sp-namedview.h" +#include "object/sp-item.h" #include "ui/widget/canvas.h" // To get window (perverse!) @@ -207,7 +208,9 @@ ExecutionEnv::run () { _effect->get_imp()->effect(_effect, _doc, _docCache); desktop->clearWaitingCursor(); _state = ExecutionEnv::COMPLETE; - selection->restoreBackup(); + const gchar * selectiondata = desktop->getDocument()->getNamedView()->getAttribute("inkscape:selectiondata"); + selection->restoreBackup(selectiondata); + desktop->getDocument()->getNamedView()->setAttribute("inkscape:selectiondata", nullptr); // _runComplete.signal(); return; } diff --git a/src/extension/execution-env.h b/src/extension/execution-env.h index fb54ceb71d099c37cfad948c1d385370dd6a1294..70bc9a82569b5e06e3e330653605aa9935c48715 100644 --- a/src/extension/execution-env.h +++ b/src/extension/execution-env.h @@ -13,6 +13,7 @@ #include #include +#include "object/sp-object.h" #include @@ -98,6 +99,8 @@ public: private: void runComplete (); + void removeClass(SPObject *obj, const Glib::ustring &className, bool all); + void createWorkingDialog (); void workingCanceled (const int resp); void genDocCache (); diff --git a/src/selection.cpp b/src/selection.cpp index 2641dfd17d3f43e053cbc7170dfacad7f8225bec..3ab273cfc098d4e32ed302804ad15a8a8b3d2251 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -33,6 +33,7 @@ #include "ui/tool/multi-path-manipulator.h" #include "ui/tool/path-manipulator.h" #include "ui/tool/control-point-selection.h" +#include "svg/svg.h" #include "layer-manager.h" #include "page-manager.h" #include "object/sp-path.h" @@ -331,6 +332,48 @@ Selection::setBackup () }//end add selected nodes } +void +Selection::restoreBackup(const gchar * selectiondata) +{ + if (!selectiondata) { + restoreBackup(); + return; + } + _selected_ids.clear(); + _seldata.clear(); + gchar ** strarray = g_strsplit(selectiondata, "@", 0); + gchar ** iter = strarray; + Glib::ustring previter = ""; + while (*iter != nullptr) { + gchar ** strsubarray = g_strsplit(*iter, "," , 0); + gchar ** subiter = strsubarray; + size_t pos = 0; + while (*subiter != nullptr) { + if (!pos) { + _selected_ids.emplace_back(*subiter); + } else { + if (pos % 2 == 0) { + float spf; + sp_svg_number_read_f(previter.c_str(), &spf); + int sp = (unsigned int)spf; + float nlf; + sp_svg_number_read_f(g_strstrip(*subiter), &nlf); + int nl = (unsigned int)nlf; + _seldata.emplace_back(std::string(_selected_ids.back()),std::make_pair(sp,nl)); + } else { + previter = Glib::ustring(*subiter); + } + } + pos++; + subiter++; + } + g_strfreev (strsubarray); + iter++; + } + g_strfreev (strarray); + restoreBackup(); +} + void Selection::restoreBackup() { diff --git a/src/selection.h b/src/selection.h index 9dd6eda60338aef12214a3c26b435c58782491cc..07eb01976294aa912ae8dec71e8881593c961872 100644 --- a/src/selection.h +++ b/src/selection.h @@ -198,6 +198,10 @@ public: * Restore a selection from a existing backup */ void restoreBackup(); + /** + * Restore a selection from a string property in svg usualy set by extensions + */ + void restoreBackup(const gchar * selectiondata); /** * Here store a paramlist when set backup */ diff --git a/testfiles/src/attributes-test.cpp b/testfiles/src/attributes-test.cpp index 3b161f721e0c3d913c130f56c8c91ec0dab31e77..adf72a27658376e36675448171c15723addf549f 100644 --- a/testfiles/src/attributes-test.cpp +++ b/testfiles/src/attributes-test.cpp @@ -477,6 +477,7 @@ std::vector getKnownAttrs() AttributeInfo("inkscape:zoom", true), AttributeInfo("inkscape:svg-dpi", true), AttributeInfo("inkscape:swatch", true), + AttributeInfo("inkscape:selectiondata", true), AttributeInfo("sodipodi:arc-type", true), AttributeInfo("sodipodi:arg1", true), AttributeInfo("sodipodi:arg2", true),