diff options
| author | Jabier Arraiza <jabier.arraiza@marker.es> | 2017-11-03 00:10:02 +0000 |
|---|---|---|
| committer | Jabier Arraiza <jabier.arraiza@marker.es> | 2017-11-03 00:10:02 +0000 |
| commit | d2df0412f728dd5bb54537dfdfe7c35b34d40e0e (patch) | |
| tree | e2703384779e83312c456399999997fcc289c5cf /src/ui/clipboard.cpp | |
| parent | Merge branch 'master' into powerpencil (diff) | |
| parent | change assignment to equality (diff) | |
| download | inkscape-d2df0412f728dd5bb54537dfdfe7c35b34d40e0e.tar.gz inkscape-d2df0412f728dd5bb54537dfdfe7c35b34d40e0e.zip | |
Merge branch 'master' into powerpencil
Diffstat (limited to 'src/ui/clipboard.cpp')
| -rw-r--r-- | src/ui/clipboard.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 3cc8ac098..33ad4401c 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<Glib::ustring> getElementsOfType(SPDesktop *desktop, gchar const *type); virtual const gchar *getFirstObjectID(); ClipboardManagerImpl(); @@ -653,6 +654,54 @@ Glib::ustring ClipboardManagerImpl::getShapeOrTextObjectId(SPDesktop *desktop) } /** + * 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<Glib::ustring> ClipboardManagerImpl::getElementsOfType(SPDesktop *desktop, gchar const* type) +{ + std::vector<Glib::ustring> 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<Inkscape::XML::Node const *> reprs; + if (strcmp(type, "*") == 0){ + //TODO:Fill vector with all posible elements + std::vector<Glib::ustring> 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<Inkscape::XML::Node const *> 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. */ void ClipboardManagerImpl::_copySelection(ObjectSet *selection) |
