From 30faf29165b1bcd936e9e0ca3ecc8b4bad4c94d2 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 9 Sep 2017 03:54:39 +0200 Subject: This commit is based on a coment on bug #1670644. And allow to fill the fill between many LPE widget that allow attach all paths on the clipboard instead only one Also added to this widget the option visible, to allow work with multiples paths wigout getting full cracy --- src/ui/clipboard.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/ui/clipboard.cpp') diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 3cc8ac098..202c8d922 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -105,6 +105,7 @@ public: virtual bool pastePathEffect(ObjectSet *set); virtual Glib::ustring getPathParameter(SPDesktop* desktop); virtual Glib::ustring getShapeOrTextObjectId(SPDesktop *desktop); + virtual std::vector getElementsOfType(SPDesktop *desktop, gchar const *type); virtual const gchar *getFirstObjectID(); ClipboardManagerImpl(); @@ -652,6 +653,54 @@ Glib::ustring ClipboardManagerImpl::getShapeOrTextObjectId(SPDesktop *desktop) return svgd; } +/** + * Get all objects id from the clipboard. + * @return A vector containing all IDs or empty if no shape or text item was found. + * type. Set to "*" to retrive all elements of the types vector inside, feel free to populate more + */ +std::vector ClipboardManagerImpl::getElementsOfType(SPDesktop *desktop, gchar const *type) +{ + std::vector result; + SPDocument *tempdoc = _retrieveClipboard(); // any target will do here + if ( tempdoc == NULL ) { + _userWarn(desktop, _("Nothing on the clipboard.")); + return result; + } + Inkscape::XML::Node *root = tempdoc->getReprRoot(); + + // 1293979: strip out the defs of the document + root->removeChild(tempdoc->getDefs()->getRepr()); + std::vector reprs; + if (strcmp(type, "*") == 0){ + //TODO:Fill vector with all posible elements + std::vector types; + types.push_back((Glib::ustring)"svg:path"); + types.push_back((Glib::ustring)"svg:circle"); + types.push_back((Glib::ustring)"svg:rect"); + types.push_back((Glib::ustring)"svg:ellipse"); + types.push_back((Glib::ustring)"svg:text"); + types.push_back((Glib::ustring)"svg:g"); + types.push_back((Glib::ustring)"svg:image"); + for (auto i=types.begin();i!=types.end();++i) { + Glib::ustring type_elem = *i; + std::vector reprs_found = sp_repr_lookup_name_many(root, type_elem.c_str(), -1); // unlimited search depth + reprs.insert(reprs.end(), reprs_found.begin(), reprs_found.end()); + } + } else { + reprs = sp_repr_lookup_name_many(root, type, -1); // unlimited search depth + } + for (auto i=reprs.begin();i!=reprs.end();++i) { + Inkscape::XML::Node const * node = *i; + result.push_back(node->attribute("id")); + } + if ( result.empty() ) { + _userWarn(desktop, ((Glib::ustring)_("Clipboard does not contain any.") + (Glib::ustring)type).c_str()); + tempdoc->doUnref(); + return result; + } + return result; +} + /** * Iterate over a list of items and copy them to the clipboard. */ -- cgit v1.2.3 From bf5a9dd8028a965e4f072ea45a802b4feb6f821a Mon Sep 17 00:00:00 2001 From: Jabiertxo Arraiza Cenoz Date: Thu, 14 Sep 2017 11:05:47 +0200 Subject: Added new LPE parameter to store Items array, also bugfixing in patharray parameter --- src/ui/clipboard.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ui/clipboard.cpp') diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 202c8d922..33ad4401c 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -658,7 +658,7 @@ Glib::ustring ClipboardManagerImpl::getShapeOrTextObjectId(SPDesktop *desktop) * @return A vector containing all IDs or empty if no shape or text item was found. * type. Set to "*" to retrive all elements of the types vector inside, feel free to populate more */ -std::vector ClipboardManagerImpl::getElementsOfType(SPDesktop *desktop, gchar const *type) +std::vector ClipboardManagerImpl::getElementsOfType(SPDesktop *desktop, gchar const* type) { std::vector result; SPDocument *tempdoc = _retrieveClipboard(); // any target will do here -- cgit v1.2.3