Skip to content

Commit

Permalink
File export: generate a default filename if the selected object chang… (
Browse files Browse the repository at this point in the history
FreeCAD#18907)

* 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
  • Loading branch information
BootsSiR authored Jan 14, 2025
1 parent 115cd05 commit 4cb0175
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Gui/CommandDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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.
Expand Down Expand Up @@ -515,8 +518,10 @@ void StdCmdExport::activated(int iMsg)
lastExportUsedGeneratedFilename = true;
else
lastExportUsedGeneratedFilename = false;

lastExportFullPath = fileName;
lastActiveDocument = getActiveGuiDocument();
lastExportedObject = selection.front();
}
}

Expand Down

0 comments on commit 4cb0175

Please sign in to comment.