From 6cefba9d8790693bdedd233fb979a69fbe4208d6 Mon Sep 17 00:00:00 2001 From: johanengelen Date: Thu, 27 Mar 2008 08:21:53 +0000 Subject: [PATCH] add method to lookup path object id from Clipboard --- src/ui/clipboard.cpp | 25 +++++++++++++++++++++++++ src/ui/clipboard.h | 1 + 2 files changed, 26 insertions(+) diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 0f9223054..31a943365 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -95,6 +95,7 @@ public: virtual bool pasteSize(bool, bool, bool); virtual bool pastePathEffect(); virtual Glib::ustring getPathParameter(); + virtual Glib::ustring getPathObjectId(); ClipboardManagerImpl(); ~ClipboardManagerImpl(); @@ -437,6 +438,30 @@ Glib::ustring ClipboardManagerImpl::getPathParameter() } +/** + * @brief Get path object id from the clipboard + * @return The retrieved path id string (contents of the id attribute), or "" if no path was found + */ +Glib::ustring ClipboardManagerImpl::getPathObjectId() +{ + SPDocument *tempdoc = _retrieveClipboard(); // any target will do here + if ( tempdoc == NULL ) { + _userWarn(SP_ACTIVE_DESKTOP, _("Nothing on the clipboard.")); + return ""; + } + Inkscape::XML::Node + *root = sp_document_repr_root(tempdoc), + *path = sp_repr_lookup_name(root, "svg:path", -1); // unlimited search depth + if ( path == NULL ) { + _userWarn(SP_ACTIVE_DESKTOP, _("Clipboard does not contain a path.")); + sp_document_unref(tempdoc); + return ""; + } + gchar const *svgd = path->attribute("id"); + return svgd; +} + + /** * @brief Iterate over a list of items and copy them to the clipboard. */ diff --git a/src/ui/clipboard.h b/src/ui/clipboard.h index 6db6be715..bb214dbf7 100644 --- a/src/ui/clipboard.h +++ b/src/ui/clipboard.h @@ -46,6 +46,7 @@ public: virtual bool pasteSize(bool separately, bool apply_x, bool apply_y) = 0; virtual bool pastePathEffect() = 0; virtual Glib::ustring getPathParameter() = 0; + virtual Glib::ustring getPathObjectId() = 0; static ClipboardManager *get(); protected: -- 2.30.2