From 209b7267fe77a04874519b6ac247651102fa1b47 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Wed, 19 Aug 2015 00:56:36 +0200 Subject: Allows for copying clones between inkscape instances. This patch puts the original of clones as children of _clipnode (). Then, on paste, it checks for the presence of an element with the right id (so that it does not breaks copypaste clones in the same doc), then pastes all, and deletes the original if needed (which automagically unlinks the clone if needed). [an alternate solution is to put the original in the defs (which might cause edition problems) and not unlink. Depending on whether people would be more interested in this behavior there could be a preference item to choose] Fixed bugs: - https://launchpad.net/bugs/167907 (bzr r14309) --- src/ui/clipboard.cpp | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) (limited to 'src/ui/clipboard.cpp') diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index d6cf1f980..816daf2e5 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -154,6 +154,7 @@ private: Inkscape::XML::Node *_root; ///< Reference to the clipboard's root node Inkscape::XML::Node *_clipnode; ///< The node that holds extra information Inkscape::XML::Document *_doc; ///< Reference to the clipboard's Inkscape::XML::Document + std::set cloned_elements; // we need a way to copy plain text AND remember its style; // the standard _clipnode is only available in an SVG tree, hence this special storage @@ -239,7 +240,7 @@ void ClipboardManagerImpl::copy(SPDesktop *desktop) // Special case for when the color picker ("dropper") is active - copies color under cursor if (tools_isactive(desktop, TOOLS_DROPPER)) { //_setClipboardColor(sp_dropper_context_get_color(desktop->event_context)); - _setClipboardColor(SP_DROPPER_CONTEXT(desktop->event_context)->get_color()); + _setClipboardColor(SP_DROPPER_CONTEXT(desktop->event_context)->get_color()); _discardInternalClipboard(); return; } @@ -523,7 +524,7 @@ bool ClipboardManagerImpl::pasteSize(SPDesktop *desktop, bool separately, bool a // resize each object in the selection if (separately) { - std::vector itemlist=selection->itemList(); + std::vector itemlist=selection->itemList(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = *i; if (item) { @@ -630,7 +631,7 @@ Glib::ustring ClipboardManagerImpl::getShapeOrTextObjectId(SPDesktop *desktop) // at the first object to be or . // but that could then return the id of the object's // clip path or mask, not the original path! - + SPDocument *tempdoc = _retrieveClipboard(); // any target will do here if ( tempdoc == NULL ) { _userWarn(desktop, _("Nothing on the clipboard.")); @@ -662,7 +663,8 @@ Glib::ustring ClipboardManagerImpl::getShapeOrTextObjectId(SPDesktop *desktop) void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) { // copy the defs used by all items - std::vector itemlist=selection->itemList(); + std::vector itemlist=selection->itemList(); + cloned_elements.clear(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ SPItem *item = *i; if (item) { @@ -673,14 +675,33 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) } // copy the representation of the items - std::vector sorted_items(itemlist); + std::vector sorted_items; + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++) + sorted_items.push_back(*i); sort(sorted_items.begin(),sorted_items.end(),sp_object_compare_position_bool); - for(std::vector::const_iterator i=sorted_items.begin();i!=sorted_items.end();i++){ - SPItem *item = *i; + //remove already copied elements from cloned_elements + std::vectortr; + for(std::set::iterator it = cloned_elements.begin();it!=cloned_elements.end();it++){ + if(std::find(sorted_items.begin(),sorted_items.end(),*it)!=sorted_items.end()) + tr.push_back(*it); + } + for(std::vector::iterator it = tr.begin();it!=tr.end();it++){ + cloned_elements.erase(*it); + } + + sorted_items.insert(sorted_items.end(),cloned_elements.begin(),cloned_elements.end()); + + for(std::vector::const_iterator i=sorted_items.begin();i!=sorted_items.end();i++){ + SPItem *item = dynamic_cast(*i); if (item) { Inkscape::XML::Node *obj = item->getRepr(); - Inkscape::XML::Node *obj_copy = _copyNode(obj, _doc, _root); + Inkscape::XML::Node *obj_copy; + if(cloned_elements.find(item)==cloned_elements.end()) + obj_copy = _copyNode(obj, _doc, _root); + else + obj_copy = _copyNode(obj, _doc, _clipnode); + // copy complete inherited style SPCSSAttr *css = sp_repr_css_attr_inherited(obj, "style"); @@ -737,6 +758,12 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) */ void ClipboardManagerImpl::_copyUsedDefs(SPItem *item) { + SPUse *use=dynamic_cast(item); + if(use){ + if(cloned_elements.insert(use->get_original()).second) + _copyUsedDefs(use->get_original()); + } + // copy fill and stroke styles (patterns and gradients) SPStyle *style = item->style; -- cgit v1.2.3 From b76d7592902d9e27cb442e203ebffed4a915b8e6 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 12 Oct 2015 12:05:07 +0200 Subject: Fix from Johan to prevent referencing null C++ pointer. Found via Clang scan build. (bzr r14404) --- 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 816daf2e5..0792fb9c5 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -565,7 +565,7 @@ bool ClipboardManagerImpl::pastePathEffect(SPDesktop *desktop) } Inkscape::Selection *selection = desktop->getSelection(); - if (selection && selection->isEmpty()) { + if (!selection || selection->isEmpty()) { _userWarn(desktop, _("Select object(s) to paste live path effect to.")); return false; } -- cgit v1.2.3 From 23935ad410a79d6f82e0ce90e5efba32a55cda4c Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Thu, 5 Nov 2015 22:27:44 +0100 Subject: static code analysis (bzr r14446) --- src/ui/clipboard.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/ui/clipboard.cpp') diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 0792fb9c5..354fa45dc 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -525,7 +525,7 @@ bool ClipboardManagerImpl::pasteSize(SPDesktop *desktop, bool separately, bool a // resize each object in the selection if (separately) { std::vector itemlist=selection->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (item) { Geom::OptRect obj_size = item->desktopVisualBounds(); @@ -581,7 +581,7 @@ bool ClipboardManagerImpl::pastePathEffect(SPDesktop *desktop) // make sure all selected items are converted to paths first (i.e. rectangles) sp_selected_to_lpeitems(desktop); std::vector itemlist=selection->itemList(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; _applyPathEffect(item, effectstack); } @@ -665,7 +665,7 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) // copy the defs used by all items std::vector itemlist=selection->itemList(); cloned_elements.clear(); - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (item) { _copyUsedDefs(item); @@ -676,7 +676,7 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) // copy the representation of the items std::vector sorted_items; - for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();i++) + for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i) sorted_items.push_back(*i); sort(sorted_items.begin(),sorted_items.end(),sp_object_compare_position_bool); @@ -692,7 +692,7 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) sorted_items.insert(sorted_items.end(),cloned_elements.begin(),cloned_elements.end()); - for(std::vector::const_iterator i=sorted_items.begin();i!=sorted_items.end();i++){ + for(std::vector::const_iterator i=sorted_items.begin();i!=sorted_items.end();++i){ SPItem *item = dynamic_cast(*i); if (item) { Inkscape::XML::Node *obj = item->getRepr(); -- cgit v1.2.3 From 25fbd2cc032dd472c3f85468c957b52e2a10d446 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Mon, 7 Dec 2015 21:20:33 +0100 Subject: static code analysis (bzr r14510) --- src/ui/clipboard.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ui/clipboard.cpp') diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 354fa45dc..f04d8a591 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -682,11 +682,11 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) //remove already copied elements from cloned_elements std::vectortr; - for(std::set::iterator it = cloned_elements.begin();it!=cloned_elements.end();it++){ + for(std::set::iterator it = cloned_elements.begin();it!=cloned_elements.end();++it){ if(std::find(sorted_items.begin(),sorted_items.end(),*it)!=sorted_items.end()) tr.push_back(*it); } - for(std::vector::iterator it = tr.begin();it!=tr.end();it++){ + for(std::vector::iterator it = tr.begin();it!=tr.end();++it){ cloned_elements.erase(*it); } -- cgit v1.2.3