Gui: depending on parameter settings open a transaction when changing visibility or selectability

This commit is contained in:
wmayer
2022-10-07 22:06:01 +02:00
parent 4a9725854f
commit bc9897caf8

View File

@@ -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)
@@ -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);
}
@@ -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())){
@@ -3565,7 +3603,7 @@ public:
addCommand(new StdTreeDrag(),!cmds.empty());
addCommand(new StdTreeSelection(),!cmds.empty());
};
}
const char* className() const override {return "StdCmdTreeViewActions";}
};