diff --git a/src/Gui/CommandDoc.cpp b/src/Gui/CommandDoc.cpp index e7482f1c88..be21d4b2db 100644 --- a/src/Gui/CommandDoc.cpp +++ b/src/Gui/CommandDoc.cpp @@ -1110,19 +1110,14 @@ void StdCmdDelete::activated(int iMsg) if (!links.empty()) { // check if the referenced objects are groups or are selected too for (std::vector::iterator lt = links.begin(); lt != links.end(); ++lt) { - if ( - (!(*lt)->hasExtension(App::GroupExtension::getExtensionClassTypeId())) && - (!(*lt)->isDerivedFrom(App::Origin::getClassTypeId())) && - (!rSel.isSelected(*lt)) - ){ - autoDeletion = false; - affectedLabels.insert(QString::fromUtf8((*lt)->Label.getValue())); + if (!rSel.isSelected(*lt)) { + ViewProvider* vp = pGuiDoc->getViewProvider(*lt); + if (!vp->canDelete(obj)) { + autoDeletion = false; + affectedLabels.insert(QString::fromUtf8((*lt)->Label.getValue())); + } } } - - if (!autoDeletion) { - break; - } } } @@ -1148,12 +1143,14 @@ void StdCmdDelete::activated(int iMsg) Gui::ViewProvider* vp = pGuiDoc->getViewProvider(ft->getObject()); if (vp) { // ask the ViewProvider if it wants to do some clean up - if (vp->onDelete(ft->getSubNames())) + if (vp->onDelete(ft->getSubNames())) { doCommand(Doc,"App.getDocument(\"%s\").removeObject(\"%s\")" ,(*it)->getName(), ft->getFeatName()); + } } } (*it)->commitTransaction(); + Gui::getMainWindow()->setUpdatesEnabled(true); Gui::getMainWindow()->update(); } diff --git a/src/Gui/ViewProvider.cpp b/src/Gui/ViewProvider.cpp index 0859caaafb..54059b962a 100644 --- a/src/Gui/ViewProvider.cpp +++ b/src/Gui/ViewProvider.cpp @@ -614,6 +614,11 @@ bool ViewProvider::onDelete(const vector< string >& subNames) { return del; } +bool ViewProvider::canDelete(App::DocumentObject*) const +{ + return false; +} + bool ViewProvider::canDragObject(App::DocumentObject* obj) const { auto vector = getExtensionsDerivedFromType(); diff --git a/src/Gui/ViewProvider.h b/src/Gui/ViewProvider.h index 3fe344a059..ff960dde26 100644 --- a/src/Gui/ViewProvider.h +++ b/src/Gui/ViewProvider.h @@ -137,9 +137,16 @@ public: * Get called if the object is about to get deleted. * Here you can delete other objects, switch their visibility or prevent the deletion of the object. * @param subNames list of selected subelements - * @return true if the deletion is approoved by the view provider. + * @return true if the deletion is approved by the view provider. */ virtual bool onDelete(const std::vector &subNames); + /** + * @brief Asks the view provider if the given object that is part of its + * outlist can be removed from there without breaking it. + * @param obj is part of the outlist of the object associated to the view provider + * @return true if the removal is approved by the view provider. + */ + virtual bool canDelete(App::DocumentObject* obj) const; //@} diff --git a/src/Gui/ViewProviderDocumentObject.cpp b/src/Gui/ViewProviderDocumentObject.cpp index 6f15379c64..64e0c0759b 100644 --- a/src/Gui/ViewProviderDocumentObject.cpp +++ b/src/Gui/ViewProviderDocumentObject.cpp @@ -35,7 +35,8 @@ /// Here the FreeCAD includes sorted by Base,App,Gui...... #include #include -#include +#include +#include #include "Application.h" #include "Document.h" #include "Selection.h" @@ -286,6 +287,16 @@ void ViewProviderDocumentObject::setActiveMode() ViewProvider::hide(); } +bool ViewProviderDocumentObject::canDelete(App::DocumentObject* obj) const +{ + Q_UNUSED(obj) + if (getObject()->hasExtension(App::GroupExtension::getExtensionClassTypeId())) + return true; + if (getObject()->isDerivedFrom(App::Origin::getClassTypeId())) + return true; + return false; +} + PyObject* ViewProviderDocumentObject::getPyObject() { if (!pyViewObject) diff --git a/src/Gui/ViewProviderDocumentObject.h b/src/Gui/ViewProviderDocumentObject.h index 2a263248ac..1e41293e6a 100644 --- a/src/Gui/ViewProviderDocumentObject.h +++ b/src/Gui/ViewProviderDocumentObject.h @@ -77,6 +77,8 @@ public: void updateView(); /// Get the object of this ViewProvider object App::DocumentObject *getObject(void) const {return pcObject;} + /// Asks the view provider if the given object can be deleted. + virtual bool canDelete(App::DocumentObject* obj) const; /// Get the GUI document to this ViewProvider object Gui::Document* getDocument() const; /// Get the python wrapper for that ViewProvider