From cbee07d53a122b96a8be23dffe0873896a1e0c1d Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 14 Mar 2020 14:45:21 +0100 Subject: [PATCH] PartDesign: fix issues of PR #3108 * in the undo/redo list use an object's label and not the internal name * check by the transaction ID instead of name to open a transaction to make the workbenches independent of implementation details of the core system * when rejecting a task do not call undo() because this is not the same as aborting a pending transaction * this also fixes the warning: Document.cpp(1182): Cannot commit transaction while transacting --- .../PartDesign/Gui/TaskDressUpParameters.cpp | 20 ++++++++----------- .../PartDesign/Gui/TaskDressUpParameters.h | 2 +- .../Gui/TaskTransformedParameters.cpp | 20 ++++++++----------- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp b/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp index 3db5735f4b..ee2409da77 100644 --- a/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp @@ -81,19 +81,20 @@ TaskDressUpParameters::~TaskDressUpParameters() Gui::Selection().rmvSelectionGate(); } -void TaskDressUpParameters::setupTransaction() { - if(!DressUpView) +void TaskDressUpParameters::setupTransaction() +{ + if (!DressUpView) return; int tid = 0; - const char *name = App::GetApplication().getActiveTransaction(&tid); - if(tid && tid == transactionID) + App::GetApplication().getActiveTransaction(&tid); + if (tid && tid == transactionID) return; + // open a transaction if none is active std::string n("Edit "); - n += DressUpView->getObject()->getNameInDocument(); - if(!name || n != name) - App::GetApplication().setActiveTransaction(n.c_str()); + n += DressUpView->getObject()->Label.getValue(); + transactionID = App::GetApplication().setActiveTransaction(n.c_str()); } bool TaskDressUpParameters::referenceSelected(const Gui::SelectionChanges& msg) @@ -361,11 +362,6 @@ bool TaskDlgDressUpParameters::accept() bool TaskDlgDressUpParameters::reject() { getDressUpView()->highlightReferences(false); - - auto editDoc = Gui::Application::Instance->editDocument(); - if(editDoc && parameter->getTransactionID()) - editDoc->getDocument()->undo(parameter->getTransactionID()); - return TaskDlgFeatureParameters::reject(); } diff --git a/src/Mod/PartDesign/Gui/TaskDressUpParameters.h b/src/Mod/PartDesign/Gui/TaskDressUpParameters.h index dbc8977b6f..72ce578404 100644 --- a/src/Mod/PartDesign/Gui/TaskDressUpParameters.h +++ b/src/Mod/PartDesign/Gui/TaskDressUpParameters.h @@ -57,7 +57,7 @@ public: void setupTransaction(); /// Apply the changes made to the object to it - virtual void apply() {}; + virtual void apply() {} int getTransactionID() const { return transactionID; diff --git a/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp b/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp index 45763ecec3..13fcc3417e 100644 --- a/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp @@ -170,20 +170,21 @@ bool TaskTransformedParameters::originalSelected(const Gui::SelectionChanges& ms return false; } -void TaskTransformedParameters::setupTransaction() { +void TaskTransformedParameters::setupTransaction() +{ auto obj = getObject(); - if(!obj) + if (!obj) return; int tid = 0; - const char *name = App::GetApplication().getActiveTransaction(&tid); - if(tid && tid == transactionID) + App::GetApplication().getActiveTransaction(&tid); + if (tid && tid == transactionID) return; + // open a transaction if none is active std::string n("Edit "); - n += obj->getNameInDocument(); - if(!name || n != name) - App::GetApplication().setActiveTransaction(n.c_str()); + n += obj->Label.getValue(); + transactionID = App::GetApplication().setActiveTransaction(n.c_str()); } void TaskTransformedParameters::onButtonAddFeature(bool checked) @@ -427,11 +428,6 @@ bool TaskDlgTransformedParameters::reject() { // ensure that we are not in selection mode parameter->exitSelectionMode(); - - auto editDoc = Gui::Application::Instance->editDocument(); - if(editDoc && parameter->getTransactionID()) - editDoc->getDocument()->undo(parameter->getTransactionID()); - return TaskDlgFeatureParameters::reject (); }