From e87459904e400f19af06da05e3a86f8875a00ebd Mon Sep 17 00:00:00 2001 From: Boots Date: Tue, 14 Jan 2025 18:20:09 -0400 Subject: [PATCH] =?UTF-8?q?File=20export:=20generate=20a=20default=20filen?= =?UTF-8?q?ame=20if=20the=20selected=20object=20chang=E2=80=A6=20(#18907)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * File export: generate a default filename if the selected object changed since the last export * Renamed variable to be more clear as per PR review feedback --- src/Gui/CommandDoc.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Gui/CommandDoc.cpp b/src/Gui/CommandDoc.cpp index 8e48c4b326..a61512d16c 100644 --- a/src/Gui/CommandDoc.cpp +++ b/src/Gui/CommandDoc.cpp @@ -421,6 +421,7 @@ void StdCmdExport::activated(int iMsg) Q_UNUSED(iMsg); static QString lastExportFullPath = QString(); + static App::DocumentObject* lastExportedObject = nullptr; static bool lastExportUsedGeneratedFilename = true; static QString lastExportFilterUsed = QString(); static Document* lastActiveDocument; @@ -454,12 +455,14 @@ void StdCmdExport::activated(int iMsg) // * 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. + // * If this is an export of a different object than last time QString defaultFilename = lastExportFullPath; bool filenameWasGenerated = false; bool didActiveDocumentChange = lastActiveDocument != getActiveGuiDocument(); - // We want to generate a new default name in three cases: - if (defaultFilename.isEmpty() || lastExportUsedGeneratedFilename || didActiveDocumentChange) { + bool didExportedObjectChange = lastExportedObject != selection.front(); + // We want to generate a new default name in four cases: + if (defaultFilename.isEmpty() || lastExportUsedGeneratedFilename || didActiveDocumentChange || didExportedObjectChange) { // First, get the name and path of the current .FCStd file, if there is one: QString docFilename = QString::fromUtf8( App::GetApplication().getActiveDocument()->getFileName()); @@ -478,7 +481,7 @@ void StdCmdExport::activated(int iMsg) defaultExportPath = Gui::FileDialog::getWorkingDirectory(); } - if (lastExportUsedGeneratedFilename || didActiveDocumentChange) { /*<- static, true on first call*/ + if (lastExportUsedGeneratedFilename || didActiveDocumentChange || didExportedObjectChange) { /*<- static, true on first call*/ defaultFilename = defaultExportPath + QLatin1Char('/') + createDefaultExportBasename(); // Append the last extension used, if there is one. @@ -515,8 +518,10 @@ void StdCmdExport::activated(int iMsg) lastExportUsedGeneratedFilename = true; else lastExportUsedGeneratedFilename = false; + lastExportFullPath = fileName; lastActiveDocument = getActiveGuiDocument(); + lastExportedObject = selection.front(); } }