From 6f87fc090e0de00b2b1fd2f825e95cf414a80fb1 Mon Sep 17 00:00:00 2001 From: Michael Fuchs Date: Sun, 20 Oct 2024 13:13:10 +0200 Subject: [PATCH] Switch back to default filename for exports after the active document changes. Fixes #16839 --- src/Gui/CommandDoc.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Gui/CommandDoc.cpp b/src/Gui/CommandDoc.cpp index 31ad37430d..50dac9f5f3 100644 --- a/src/Gui/CommandDoc.cpp +++ b/src/Gui/CommandDoc.cpp @@ -408,6 +408,7 @@ void StdCmdExport::activated(int iMsg) static QString lastExportFullPath = QString(); static bool lastExportUsedGeneratedFilename = true; static QString lastExportFilterUsed = QString(); + static Document* lastActiveDocument; auto selection = Gui::Selection().getObjectsOfType(App::DocumentObject::getClassTypeId()); if (selection.empty()) { @@ -434,15 +435,16 @@ void StdCmdExport::activated(int iMsg) // Create a default filename for the export // * If this is the first export this session default, generate a new default. - // * If this is a repeated export during the same session: + // * If this is a repeated export during the same session and file: // * If the user accepted the default filename last time, regenerate a new // default, potentially updating the object label. // * If not, default to their previously-set export filename. QString defaultFilename = lastExportFullPath; bool filenameWasGenerated = false; - // We want to generate a new default name in two cases: - if (defaultFilename.isEmpty() || lastExportUsedGeneratedFilename) { + bool didActiveDocumentChange = lastActiveDocument != getActiveGuiDocument(); + // We want to generate a new default name in three cases: + if (defaultFilename.isEmpty() || lastExportUsedGeneratedFilename || didActiveDocumentChange) { // First, get the name and path of the current .FCStd file, if there is one: QString docFilename = QString::fromUtf8( App::GetApplication().getActiveDocument()->getFileName()); @@ -461,7 +463,7 @@ void StdCmdExport::activated(int iMsg) defaultExportPath = Gui::FileDialog::getWorkingDirectory(); } - if (lastExportUsedGeneratedFilename /*<- static, true on first call*/ ) { + if (lastExportUsedGeneratedFilename || didActiveDocumentChange) { /*<- static, true on first call*/ defaultFilename = defaultExportPath + QLatin1Char('/') + createDefaultExportBasename(); // Append the last extension used, if there is one. @@ -499,6 +501,7 @@ void StdCmdExport::activated(int iMsg) else lastExportUsedGeneratedFilename = false; lastExportFullPath = fileName; + lastActiveDocument = getActiveGuiDocument(); } }