Change the description of the default 'Toggle active object' command in the right click menu based on the current state of the selected object.

This commit is contained in:
Max Wilfinger
2023-12-27 09:10:30 +01:00
parent 1c7b35ff29
commit 72821eb513
2 changed files with 31 additions and 3 deletions

View File

@@ -68,11 +68,26 @@ void ViewProviderPart::onChanged(const App::Property* prop) {
void ViewProviderPart::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
{
App::DocumentObject* activePart = nullptr;
auto activeDoc = Gui::Application::Instance->activeDocument();
if(!activeDoc)
activeDoc = getDocument();
auto activeView = activeDoc->setActiveView(this);
activePart = activeView->getActiveObject<App::DocumentObject*> (PARTKEY);
auto func = new Gui::ActionFunction(menu);
QAction* act = menu->addAction(QObject::tr("Toggle active part"));
func->trigger(act, [this](){
if (activePart == this->getObject()){
QAction* act = menu->addAction(QObject::tr("Unset active object"));
func->trigger(act, [this](){
this->doubleClicked();
});
} else {
QAction* act = menu->addAction(QObject::tr("Set active object"));
func->trigger(act, [this](){
this->doubleClicked();
});
}
ViewProviderDragger::setupContextMenu(menu, receiver, member);
}