diff --git a/src/Gui/CommandDoc.cpp b/src/Gui/CommandDoc.cpp index 86d7c2abc..1c14ba62f 100644 --- a/src/Gui/CommandDoc.cpp +++ b/src/Gui/CommandDoc.cpp @@ -910,59 +910,36 @@ StdCmdDuplicateSelection::StdCmdDuplicateSelection() void StdCmdDuplicateSelection::activated(int iMsg) { - App::Document* act = App::GetApplication().getActiveDocument(); - if (!act) - return; // no active document found - Gui::Document* doc = Gui::Application::Instance->getDocument(act); - std::vector sel = Gui::Selection().getCompleteSelection(); + std::vector sel = Selection().getCompleteSelection(); + std::vector obj; + obj.reserve(sel.size()); for (std::vector::iterator it = sel.begin(); it != sel.end(); ++it) { - if (!it->pObject) - continue; // should actually not happen - // create a copy of the object - App::DocumentObject* copy = act->copyObject(it->pObject, false); - if (!copy) // continue if no copy could be created - continue; - // mark all properties of the copy as "touched" which are touched in the original object - std::map props; - it->pObject->getPropertyMap(props); - std::map copy_props; - copy->getPropertyMap(copy_props); - for (std::map::iterator jt = props.begin(); jt != props.end(); ++jt) { - if (jt->second->isTouched()) { - std::map::iterator kt; - kt = copy_props.find(jt->first); - if (kt != copy_props.end()) { - kt->second->touch(); - } - } - } - - Gui::Document* parent = Gui::Application::Instance->getDocument(it->pObject->getDocument()); - if (!parent || !doc) - continue; // should not happen - // copy the properties of the associated view providers - Gui::ViewProvider* view = parent->getViewProvider(it->pObject); - Gui::ViewProvider* copy_view = doc->getViewProvider(copy); - copy_view->addDynamicProperties(view); - if (!view || !copy_view) - continue; // should not happen - - // get the properties of the view provider - props.clear(); - view->getPropertyMap(props); - copy_props.clear(); - copy_view->getPropertyMap(copy_props); - for (std::map::iterator jt = props.begin(); jt != props.end(); ++jt) { - std::map::iterator kt; - kt = copy_props.find(jt->first); - if (kt != copy_props.end()) { - std::auto_ptr data(jt->second->Copy()); - if (data.get()) { - kt->second->Paste(*data); - } - } + if (it->pObject) { + obj.push_back(it->pObject); } } + + if (obj.empty()) + return; + + Base::FileInfo fi(Base::FileInfo::getTempFileName()); + { + // save stuff to file + Base::ofstream str(fi, std::ios::out | std::ios::binary); + App::Document* doc = obj.front()->getDocument(); + MergeDocuments mimeView(doc); + doc->exportObjects(obj, str); + str.close(); + } + App::Document* doc = App::GetApplication().getActiveDocument(); + if (doc) { + // restore objects from file and add to active document + Base::ifstream str(fi, std::ios::in | std::ios::binary); + MergeDocuments mimeView(doc); + mimeView.importObjects(str); + str.close(); + } + fi.deleteFile(); } bool StdCmdDuplicateSelection::isActive(void)