From 75dff5d947f06dcfeb14b866b9cbdf206ef6ef04 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 12 Feb 2021 17:42:49 +0100 Subject: [PATCH] Gui: [skip ci] add option to automatically close task dialog if undo/redo was pressed --- src/Gui/TaskView/TaskDialog.cpp | 9 ++++++++- src/Gui/TaskView/TaskDialog.h | 13 +++++++++++++ src/Gui/TaskView/TaskView.cpp | 10 ++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/Gui/TaskView/TaskDialog.cpp b/src/Gui/TaskView/TaskDialog.cpp index e36279c843..a2358c161a 100644 --- a/src/Gui/TaskView/TaskDialog.cpp +++ b/src/Gui/TaskView/TaskDialog.cpp @@ -38,7 +38,9 @@ using namespace Gui::TaskView; //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ TaskDialog::TaskDialog() - : QObject(0), pos(North), escapeButton(true) + : QObject(nullptr), pos(North) + , escapeButton(true) + , autoCloseTransaction(false) { } @@ -84,6 +86,11 @@ void TaskDialog::closed() } +void TaskDialog::autoClosedOnTransactionChange() +{ + +} + void TaskDialog::clicked(int) { diff --git a/src/Gui/TaskView/TaskDialog.h b/src/Gui/TaskView/TaskDialog.h index 51c44ba359..08d7bdccaa 100644 --- a/src/Gui/TaskView/TaskDialog.h +++ b/src/Gui/TaskView/TaskDialog.h @@ -75,6 +75,15 @@ public: return escapeButton; } + /// Defines whether a task dialog must be closed if the document changed the + /// active transaction. + void setAutoCloseOnTransactionChange(bool on) { + autoCloseTransaction = on; + } + bool isAutoCloseOnTransactionChange() const { + return autoCloseTransaction; + } + const std::string& getDocumentName() const { return documentName; } void setDocumentName(const std::string& doc) @@ -105,6 +114,9 @@ public: virtual void open(); /// is called by the framework when the dialog is closed virtual void closed(); + /// is called by the framework when the dialog is automatically closed due to + /// changing the active transaction + virtual void autoClosedOnTransactionChange(); /// is called by the framework if a button is clicked which has no accept or reject role virtual void clicked(int); /// is called by the framework if the dialog is accepted (Ok) @@ -129,6 +141,7 @@ protected: private: std::string documentName; bool escapeButton; + bool autoCloseTransaction; }; } //namespace TaskView diff --git a/src/Gui/TaskView/TaskView.cpp b/src/Gui/TaskView/TaskView.cpp index 456c411905..8a6e61e14e 100644 --- a/src/Gui/TaskView/TaskView.cpp +++ b/src/Gui/TaskView/TaskView.cpp @@ -532,12 +532,22 @@ void TaskView::slotDeletedDocument() void TaskView::slotUndoDocument(const App::Document&) { + if (ActiveDialog && ActiveDialog->isAutoCloseOnTransactionChange()) { + ActiveDialog->autoClosedOnTransactionChange(); + removeDialog(); + } + if (!ActiveDialog) updateWatcher(); } void TaskView::slotRedoDocument(const App::Document&) { + if (ActiveDialog && ActiveDialog->isAutoCloseOnTransactionChange()) { + ActiveDialog->autoClosedOnTransactionChange(); + removeDialog(); + } + if (!ActiveDialog) updateWatcher(); }