Merge pull request #11840 from maxwxyz/precise-toggle-command-description
Change the description of the default 'Toggle active object' command
This commit is contained in:
@@ -69,19 +69,19 @@ void ViewProviderPart::onChanged(const App::Property* prop) {
|
||||
void ViewProviderPart::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
|
||||
{
|
||||
auto func = new Gui::ActionFunction(menu);
|
||||
QAction* act = menu->addAction(QObject::tr("Toggle active part"));
|
||||
|
||||
QAction* act = menu->addAction(QObject::tr("Active object"));
|
||||
act->setCheckable(true);
|
||||
act->setChecked(isActivePart());
|
||||
func->trigger(act, [this](){
|
||||
this->doubleClicked();
|
||||
this->toggleActivePart();
|
||||
});
|
||||
|
||||
ViewProviderDragger::setupContextMenu(menu, receiver, member);
|
||||
}
|
||||
|
||||
bool ViewProviderPart::doubleClicked()
|
||||
bool ViewProviderPart::isActivePart()
|
||||
{
|
||||
//make the part the active one
|
||||
|
||||
//first, check if the part is already active.
|
||||
App::DocumentObject* activePart = nullptr;
|
||||
auto activeDoc = Gui::Application::Instance->activeDocument();
|
||||
if(!activeDoc)
|
||||
@@ -93,6 +93,16 @@ bool ViewProviderPart::doubleClicked()
|
||||
activePart = activeView->getActiveObject<App::DocumentObject*> (PARTKEY);
|
||||
|
||||
if (activePart == this->getObject()){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void ViewProviderPart::toggleActivePart()
|
||||
{
|
||||
//make the part the active one
|
||||
if (isActivePart()){
|
||||
//active part double-clicked. Deactivate.
|
||||
Gui::Command::doCommand(Gui::Command::Gui,
|
||||
"Gui.ActiveDocument.ActiveView.setActiveObject('%s', None)",
|
||||
@@ -105,7 +115,11 @@ bool ViewProviderPart::doubleClicked()
|
||||
this->getObject()->getDocument()->getName(),
|
||||
this->getObject()->getNameInDocument());
|
||||
}
|
||||
}
|
||||
|
||||
bool ViewProviderPart::doubleClicked()
|
||||
{
|
||||
toggleActivePart();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,8 @@ public:
|
||||
|
||||
bool doubleClicked() override;
|
||||
void setupContextMenu(QMenu* menu, QObject* receiver, const char* member) override;
|
||||
bool isActivePart();
|
||||
void toggleActivePart();
|
||||
|
||||
/// deliver the icon shown in the tree view
|
||||
/// override from ViewProvider.h
|
||||
|
||||
@@ -132,17 +132,19 @@ void ViewProviderBody::setupContextMenu(QMenu* menu, QObject* receiver, const ch
|
||||
Q_UNUSED(receiver);
|
||||
Q_UNUSED(member);
|
||||
Gui::ActionFunction* func = new Gui::ActionFunction(menu);
|
||||
QAction* act = menu->addAction(tr("Toggle active body"));
|
||||
|
||||
QAction* act = menu->addAction(tr("Active body"));
|
||||
act->setCheckable(true);
|
||||
act->setChecked(isActiveBody());
|
||||
func->trigger(act, [this]() {
|
||||
this->doubleClicked();
|
||||
this->toggleActiveBody();
|
||||
});
|
||||
|
||||
Gui::ViewProviderGeometryObject::setupContextMenu(menu, receiver, member); // clazy:exclude=skipped-base-method
|
||||
}
|
||||
|
||||
bool ViewProviderBody::doubleClicked()
|
||||
bool ViewProviderBody::isActiveBody()
|
||||
{
|
||||
//first, check if the body is already active.
|
||||
auto activeDoc = Gui::Application::Instance->activeDocument();
|
||||
if(!activeDoc)
|
||||
activeDoc = getDocument();
|
||||
@@ -150,7 +152,16 @@ bool ViewProviderBody::doubleClicked()
|
||||
if(!activeView)
|
||||
return false;
|
||||
|
||||
if (activeView->isActiveObject(getObject(),PDBODYKEY)) {
|
||||
if (activeView->isActiveObject(getObject(),PDBODYKEY)){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void ViewProviderBody::toggleActiveBody()
|
||||
{
|
||||
if (isActiveBody()) {
|
||||
//active body double-clicked. Deactivate.
|
||||
Gui::Command::doCommand(Gui::Command::Gui,
|
||||
"Gui.ActiveDocument.ActiveView.setActiveObject('%s', None)", PDBODYKEY);
|
||||
@@ -162,7 +173,7 @@ bool ViewProviderBody::doubleClicked()
|
||||
|
||||
// and set correct active objects
|
||||
auto* part = App::Part::getPartOfObject ( getObject() );
|
||||
if ( part && part != activeView->getActiveObject<App::Part*> ( PARTKEY ) ) {
|
||||
if ( part && !isActiveBody() ) {
|
||||
Gui::Command::doCommand(Gui::Command::Gui,
|
||||
"Gui.ActiveDocument.ActiveView.setActiveObject('%s',%s)",
|
||||
PARTKEY, Gui::Command::getObjectCmd(part).c_str());
|
||||
@@ -172,7 +183,11 @@ bool ViewProviderBody::doubleClicked()
|
||||
"Gui.ActiveDocument.ActiveView.setActiveObject('%s',%s)",
|
||||
PDBODYKEY, Gui::Command::getObjectCmd(getObject()).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
bool ViewProviderBody::doubleClicked()
|
||||
{
|
||||
toggleActiveBody();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +58,8 @@ public:
|
||||
|
||||
bool doubleClicked() override;
|
||||
void setupContextMenu(QMenu* menu, QObject* receiver, const char* member) override;
|
||||
bool isActiveBody();
|
||||
void toggleActiveBody();
|
||||
|
||||
std::vector< std::string > getDisplayModes() const override;
|
||||
void setDisplayMode(const char* ModeName) override;
|
||||
|
||||
Reference in New Issue
Block a user