+ fixes #0001332: Allow copy-paste on elements in Project tree
This commit is contained in:
parent
3ea41ff0c9
commit
4fe3348e46
|
@ -42,6 +42,7 @@
|
|||
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/DocumentObjectGroup.h>
|
||||
|
||||
#include "Application.h"
|
||||
#include "MainWindow.h"
|
||||
|
@ -889,6 +890,33 @@ void Document::importObjects(const std::vector<App::DocumentObject*>& obj, Base:
|
|||
xmlReader.readEndElement("Document");
|
||||
}
|
||||
|
||||
void Document::addRootObjectsToGroup(const std::vector<App::DocumentObject*>& obj, App::DocumentObjectGroup* grp)
|
||||
{
|
||||
std::map<App::DocumentObject*, bool> rootMap;
|
||||
for (std::vector<App::DocumentObject*>::const_iterator it = obj.begin(); it != obj.end(); ++it) {
|
||||
rootMap[*it] = true;
|
||||
}
|
||||
// get the view providers and check which objects are children
|
||||
for (std::vector<App::DocumentObject*>::const_iterator it = obj.begin(); it != obj.end(); ++it) {
|
||||
Gui::ViewProvider* vp = getViewProvider(*it);
|
||||
if (vp) {
|
||||
std::vector<App::DocumentObject*> child = vp->claimChildren();
|
||||
for (std::vector<App::DocumentObject*>::iterator jt = child.begin(); jt != child.end(); ++jt) {
|
||||
std::map<App::DocumentObject*, bool>::iterator kt = rootMap.find(*jt);
|
||||
if (kt != rootMap.end()) {
|
||||
kt->second = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// all objects that are not children of other objects can be added to the group
|
||||
for (std::map<App::DocumentObject*, bool>::iterator it = rootMap.begin(); it != rootMap.end(); ++it) {
|
||||
if (it->second)
|
||||
grp->addObject(it->first);
|
||||
}
|
||||
}
|
||||
|
||||
void Document::createView(const char* sType)
|
||||
{
|
||||
View3DInventor* view3D = new View3DInventor(this, getMainWindow());
|
||||
|
|
|
@ -37,11 +37,14 @@
|
|||
|
||||
class SoPath;
|
||||
|
||||
namespace Base
|
||||
{
|
||||
namespace Base {
|
||||
class Matrix4D;
|
||||
}
|
||||
|
||||
namespace App {
|
||||
class DocumentObjectGroup;
|
||||
}
|
||||
|
||||
namespace Gui {
|
||||
|
||||
class ViewProvider;
|
||||
|
@ -122,6 +125,8 @@ public:
|
|||
virtual void RestoreDocFile(Base::Reader &reader);
|
||||
void exportObjects(const std::vector<App::DocumentObject*>&, Base::Writer&);
|
||||
void importObjects(const std::vector<App::DocumentObject*>&, Base::Reader&);
|
||||
/// Add all root objects of the given array to a group
|
||||
void addRootObjectsToGroup(const std::vector<App::DocumentObject*>&, App::DocumentObjectGroup*);
|
||||
//@}
|
||||
|
||||
/// Observer message from the App doc
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
#include <Base/Writer.h>
|
||||
#include <App/Application.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/DocumentObjectGroup.h>
|
||||
|
||||
#include "MainWindow.h"
|
||||
#include "Application.h"
|
||||
|
@ -1521,7 +1522,13 @@ void MainWindow::insertFromMimeData (const QMimeData * mimeData)
|
|||
std::istream in(0);
|
||||
in.rdbuf(&buf);
|
||||
MergeDocuments mimeView(doc);
|
||||
mimeView.importObjects(in);
|
||||
std::vector<App::DocumentObject*> newObj = mimeView.importObjects(in);
|
||||
std::vector<App::DocumentObjectGroup*> grp = Gui::Selection().getObjectsOfType<App::DocumentObjectGroup>();
|
||||
if (grp.size() == 1) {
|
||||
Gui::Document* gui = Application::Instance->getDocument(doc);
|
||||
if (gui)
|
||||
gui->addRootObjectsToGroup(newObj, grp.front());
|
||||
}
|
||||
}
|
||||
else if (mimeData->hasFormat(QLatin1String("application/x-documentobject-file"))) {
|
||||
QByteArray res = mimeData->data(QLatin1String("application/x-documentobject-file"));
|
||||
|
@ -1531,8 +1538,14 @@ void MainWindow::insertFromMimeData (const QMimeData * mimeData)
|
|||
Base::FileInfo fi((const char*)res);
|
||||
Base::ifstream str(fi, std::ios::in | std::ios::binary);
|
||||
MergeDocuments mimeView(doc);
|
||||
mimeView.importObjects(str);
|
||||
std::vector<App::DocumentObject*> newObj = mimeView.importObjects(str);
|
||||
str.close();
|
||||
std::vector<App::DocumentObjectGroup*> grp = Gui::Selection().getObjectsOfType<App::DocumentObjectGroup>();
|
||||
if (grp.size() == 1) {
|
||||
Gui::Document* gui = Application::Instance->getDocument(doc);
|
||||
if (gui)
|
||||
gui->addRootObjectsToGroup(newObj, grp.front());
|
||||
}
|
||||
}
|
||||
else if (mimeData->hasUrls()) {
|
||||
// load the files into the active document if there is one, otherwise let create one
|
||||
|
|
|
@ -406,17 +406,20 @@ void StdWorkbench::setupContextMenu(const char* recipient, MenuItem* item) const
|
|||
*item << "Std_ViewFitAll" << "Std_ViewFitSelection" << "Std_DrawStyle" << StdViews << measure
|
||||
<< "Separator" << "Std_ViewDockUndockFullscreen";
|
||||
|
||||
if (Gui::Selection().countObjectsOfType(App::DocumentObject::getClassTypeId()) > 0 )
|
||||
if (Gui::Selection().countObjectsOfType(App::DocumentObject::getClassTypeId()) > 0) {
|
||||
*item << "Separator" << "Std_SetAppearance" << "Std_ToggleVisibility"
|
||||
<< "Std_ToggleSelectability" << "Std_TreeSelection"
|
||||
<< "Std_RandomColor" << "Separator" << "Std_Delete";
|
||||
}
|
||||
}
|
||||
else if (strcmp(recipient,"Tree") == 0)
|
||||
{
|
||||
if (Gui::Selection().countObjectsOfType(App::DocumentObject::getClassTypeId()) > 0 )
|
||||
if (Gui::Selection().countObjectsOfType(App::DocumentObject::getClassTypeId()) > 0) {
|
||||
*item << "Std_ToggleVisibility" << "Std_ShowSelection" << "Std_HideSelection"
|
||||
<< "Std_ToggleSelectability" << "Separator" << "Std_SetAppearance"
|
||||
<< "Std_RandomColor" << "Separator" << "Std_Delete";
|
||||
<< "Std_RandomColor" << "Std_Cut" << "Std_Copy" << "Std_Paste"
|
||||
<< "Separator" << "Std_Delete";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user