From 7f80e711f68a0bc09d0b6969725551c07f6064a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Tr=C3=B6ger?= Date: Fri, 5 Jun 2015 11:09:09 +0200 Subject: [PATCH] better active part and document tip handling --- src/App/Document.cpp | 12 ++++++++++++ src/Gui/ActiveObjectList.h | 1 + src/Gui/ViewProviderPart.cpp | 10 +++++++--- src/Mod/PartDesign/Gui/Command.cpp | 4 ++++ src/Mod/PartDesign/Gui/ViewProviderBody.cpp | 10 ++++++++-- 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 3f729d917..47054b8ea 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -2079,6 +2079,12 @@ void Document::remObject(const char* sName) // Before deleting we must nullify all dependant objects breakDependency(pos->second, true); + + //and remove the tip if needed + if(Tip.getValue() && strcmp(Tip.getValue()->getNameInDocument(), sName)==0) { + Tip.setValue(nullptr); + TipName.setValue(""); + } // do no transactions if we do a rollback! if(!d->rollback){ @@ -2122,6 +2128,12 @@ void Document::_remObject(DocumentObject* pcObject) d->activeObject = 0; signalDeletedObject(*pcObject); + + //remove the tip if needed + if(Tip.getValue() == pcObject) { + Tip.setValue(nullptr); + TipName.setValue(""); + } // do no transactions if we do a rollback! if(!d->rollback){ diff --git a/src/Gui/ActiveObjectList.h b/src/Gui/ActiveObjectList.h index fc53a5f73..43669e5b0 100644 --- a/src/Gui/ActiveObjectList.h +++ b/src/Gui/ActiveObjectList.h @@ -69,5 +69,6 @@ namespace Gui } //namespace Gui static const char PDBODYKEY[] = "pdbody"; +static const char PARTKEY[] = "part"; #endif diff --git a/src/Gui/ViewProviderPart.cpp b/src/Gui/ViewProviderPart.cpp index 15223d532..3fad526ac 100644 --- a/src/Gui/ViewProviderPart.cpp +++ b/src/Gui/ViewProviderPart.cpp @@ -170,17 +170,21 @@ void ViewProviderPart::onObjectChanged(const App::DocumentObject& obj, const App bool ViewProviderPart::doubleClicked(void) { if(Workbench.getValue() != "") - // assure the PartDesign workbench + // assure the given workbench Gui::Command::assureWorkbench( Workbench.getValue() ); + //make the part the active one + Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", PARTKEY, this->getObject()->getNameInDocument()); + return true; } bool ViewProviderPart::onDelete(const std::vector &) { - //Gui::Command::doCommand(Gui::Command::Doc,"App.getDocument(\"%s\").getObject(\"%s\").removeObjectsFromDocument()" - // ,getObject()->getDocument()->getName(), getObject()->getNameInDocument()); + if(getActiveView()->getActiveObject(PARTKEY) == getObject()) + Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', None)", PARTKEY); + return true; } diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 0995ea107..f0dd405ab 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -109,6 +109,7 @@ void CmdPartDesignPart::activated(int iMsg) doCommand(Doc,"App.activeDocument().Tip = App.activeDocument().addObject('App::Part','%s')",PartName.c_str()); doCommand(Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr(PartName.c_str()).toStdString().c_str()); PartDesignGui::Workbench::setUpPart(dynamic_cast(getDocument()->getObject(PartName.c_str()))); + doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", PARTKEY, PartName.c_str()); updateActive(); } @@ -151,6 +152,8 @@ void CmdPartDesignBody::activated(int iMsg) doCommand(Doc,"App.activeDocument().Tip = App.activeDocument().addObject('App::Part','%s')",PartName.c_str()); doCommand(Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr(PartName.c_str()).toStdString().c_str()); PartDesignGui::Workbench::setUpPart(dynamic_cast(getDocument()->getObject(PartName.c_str()))); + doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", PARTKEY, PartName.c_str()); + } else { PartName = actPart->getNameInDocument(); // add the Body feature itself, and make it active @@ -159,6 +162,7 @@ void CmdPartDesignBody::activated(int iMsg) //doCommand(Doc,"App.activeDocument().%s.Tip = None",FeatName.c_str()); addModule(Gui,"PartDesignGui"); // import the Gui module only once a session doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", PDBODYKEY, FeatName.c_str()); + // Make the "Create sketch" prompt appear in the task panel doCommand(Gui,"Gui.Selection.clearSelection()"); doCommand(Gui,"Gui.Selection.addSelection(App.ActiveDocument.%s)", FeatName.c_str()); diff --git a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp index de5ae55eb..a6b904a1c 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp @@ -41,6 +41,7 @@ #include #include "Base/Console.h" +#include using namespace PartDesignGui; @@ -105,8 +106,13 @@ bool ViewProviderBody::doubleClicked(void) { // assure the PartDesign workbench Gui::Command::assureWorkbench("PartDesignWorkbench"); - //Gui::Command::doCommand(Gui::Command::Gui,"PartDesignGui.setActiveBody(App.activeDocument().%s)",this->getObject()->getNameInDocument()); - Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", PDBODYKEY, this->getObject()->getNameInDocument()); + + //and set correct active objects + auto* part = PartDesignGui::getPartFor(getObject(), false); + if(part!=Gui::Application::Instance->activeView()->getActiveObject(PARTKEY)) + Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", PARTKEY, part->getNameInDocument()); + + Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", PDBODYKEY, this->getObject()->getNameInDocument()); return true; }