From 793a70b0e2d4daaf7d8e59982cd8ec7e87f45311 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Mon, 19 Dec 2022 17:15:07 +0100 Subject: [PATCH] Gui: Set status bit when restoring is initiated by the user from the UI --- src/Gui/CommandDoc.cpp | 22 ++++++++++++++-------- src/Mod/Web/Gui/BrowserView.cpp | 3 +++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Gui/CommandDoc.cpp b/src/Gui/CommandDoc.cpp index c6b08169ca..403e3832bf 100644 --- a/src/Gui/CommandDoc.cpp +++ b/src/Gui/CommandDoc.cpp @@ -29,7 +29,7 @@ # include # include # include -# include +# include #endif #include @@ -150,8 +150,14 @@ void StdCmdOpen::activated(int iMsg) } else { for (SelectModule::Dict::iterator it = dict.begin(); it != dict.end(); ++it) { + + // Set flag indicating that this load/restore has been initiated by the user (not by a macro) + getGuiApplication()->setStatus(Gui::Application::UserInitiatedOpenDocument, true); + getGuiApplication()->open(it.key().toUtf8(), it.value().toLatin1()); + getGuiApplication()->setStatus(Gui::Application::UserInitiatedOpenDocument, false); + App::Document *doc = App::GetApplication().getActiveDocument(); if(doc && doc->testStatus(App::Document::PartialRestore)) { @@ -276,7 +282,7 @@ StdCmdExport::StdCmdExport() /** Create a default filename from a user-specified format string - + Format options are: %F - the basename of the .FCStd file (or the label, if it is not saved yet) %Lx - the label of the selected object(s), separated by character 'x' @@ -311,7 +317,7 @@ QString createDefaultExportBasename() QString docFilename = QString::fromUtf8(App::GetApplication().getActiveDocument()->getFileName()); QFileInfo fi(docFilename); QString fcstdBasename = fi.completeBaseName(); - if (fcstdBasename.isEmpty()) + if (fcstdBasename.isEmpty()) fcstdBasename = QString::fromStdString(App::GetApplication().getActiveDocument()->Label.getStrValue()); // %L - the label of the selected object(s) @@ -352,7 +358,7 @@ QString createDefaultExportBasename() auto formatChar = exportFormatString.at(i); QChar separatorChar = QLatin1Char('-'); // If this format type requires an additional char, read that now (or default to - // '-' if the format string ends) + // '-' if the format string ends) if (formatChar == QLatin1Char('L') || formatChar == QLatin1Char('P')) { if (i < exportFormatString.size() - 1) { @@ -378,8 +384,8 @@ QString createDefaultExportBasename() defaultFilename.append(localISO8601); } else { - FC_WARN("When parsing default export filename format string, %" - << QString(formatChar).toStdString() + FC_WARN("When parsing default export filename format string, %" + << QString(formatChar).toStdString() << " is not a known format string."); } } @@ -419,7 +425,7 @@ void StdCmdExport::activated(int iMsg) filterList << QString::fromStdString(filter.first); } QString formatList = filterList.join(QLatin1String(";;")); - Base::Reference hPath = + Base::Reference hPath = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("General"); QString selectedFilter = QString::fromStdString(hPath->GetASCII("FileExportFilter")); if (!lastExportFilterUsed.isEmpty()) @@ -486,7 +492,7 @@ void StdCmdExport::activated(int iMsg) // there is one. QFileInfo defaultExportFI(defaultFilename); QFileInfo thisExportFI(fileName); - if (filenameWasGenerated && + if (filenameWasGenerated && thisExportFI.completeBaseName() == defaultExportFI.completeBaseName()) lastExportUsedGeneratedFilename = true; else diff --git a/src/Mod/Web/Gui/BrowserView.cpp b/src/Mod/Web/Gui/BrowserView.cpp index 1bec2eb39b..e97a3ac18f 100644 --- a/src/Mod/Web/Gui/BrowserView.cpp +++ b/src/Mod/Web/Gui/BrowserView.cpp @@ -595,7 +595,10 @@ void BrowserView::urlFilter(const QUrl & url) } // Gui::Command::doCommand(Gui::Command::Gui,"execfile('%s')",(const char*) fi.absoluteFilePath(). toLocal8Bit()); QString filename = Base::Tools::escapeEncodeFilename(fi.absoluteFilePath()); + // Set flag indicating that this load/restore has been initiated by the user (not by a macro) + Gui::Application::Instance->setStatus(Gui::Application::UserInitiatedOpenDocument, true); Gui::Command::doCommand(Gui::Command::Gui,"with open('%s') as file:\n\texec(file.read())",(const char*) filename.toUtf8()); + Gui::Application::Instance->setStatus(Gui::Application::UserInitiatedOpenDocument, false); } catch (const Base::Exception& e) { QMessageBox::critical(this, tr("Error"), QString::fromUtf8(e.what()));