Skip to content

Commit

Permalink
Gui: depending on parameter settings open a transaction when changing…
Browse files Browse the repository at this point in the history
… visibility or selectability
  • Loading branch information
wwmayer committed Oct 7, 2022
1 parent 4a97258 commit bc9897c
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/Gui/CommandView.cpp
Expand Up @@ -86,6 +86,37 @@ using namespace Gui;
using Gui::Dialog::DlgSettingsImageImp;
namespace bp = boost::placeholders;

namespace {
// A helper class to open a transaction when changing properties of view providers.
// It uses the same parameter key as the PropertyView to control the behaviour.
class TransactionView {
Gui::Document* document;

public:
static bool getDefault() {
auto hGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/PropertyView");
return hGrp->GetBool("AutoTransactionView", false);
}
TransactionView(Gui::Document* doc, const char* name, bool enable = getDefault())
: document(doc)
{
if (document && enable) {
document->openCommand(name);
}
else {
document = nullptr;
}
}

~TransactionView() {
if (document) {
document->commitCommand();
}
}
};
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

DEF_STD_CMD_AC(StdOrthographicCamera)
Expand Down Expand Up @@ -832,6 +863,7 @@ StdCmdToggleVisibility::StdCmdToggleVisibility()
void StdCmdToggleVisibility::activated(int iMsg)
{
Q_UNUSED(iMsg);
TransactionView transaction(getActiveGuiDocument(), QT_TRANSLATE_NOOP("Command", "Toggle visibility"));
Selection().setVisible(SelectionSingleton::VisToggle);
}

Expand Down Expand Up @@ -867,6 +899,12 @@ void StdCmdToggleSelectability::activated(int iMsg)
std::vector<App::DocumentObject*> sel = Selection().getObjectsOfType
(App::DocumentObject::getClassTypeId(), doc->getName());

if (sel.empty()) {
continue;
}

TransactionView transaction(pcDoc, QT_TRANSLATE_NOOP("Command", "Toggle selectability"));

for (const auto & ft : sel) {
ViewProvider *pr = pcDoc->getViewProviderByName(ft->getNameInDocument());
if (pr && pr->isDerivedFrom(ViewProviderGeometryObject::getClassTypeId())){
Expand Down Expand Up @@ -3565,7 +3603,7 @@ class StdCmdTreeViewActions : public GroupCommand

addCommand(new StdTreeDrag(),!cmds.empty());
addCommand(new StdTreeSelection(),!cmds.empty());
};
}
const char* className() const override {return "StdCmdTreeViewActions";}
};

Expand Down

0 comments on commit bc9897c

Please sign in to comment.