cherry-pick #13: LocalFileOrigin and Std_* delegation (38358e431d)

This commit is contained in:
forbes
2026-02-13 14:07:46 -06:00
parent 9e031ef021
commit c26d064e3b

View File

@@ -49,7 +49,9 @@
#include "Control.h"
#include "DockWindowManager.h"
#include "FileDialog.h"
#include "FileOrigin.h"
#include "MainWindow.h"
#include "OriginManager.h"
#include "Selection.h"
#include "Dialogs/DlgObjectSelection.h"
#include "Dialogs/DlgProjectInformationImp.h"
@@ -95,81 +97,25 @@ void StdCmdOpen::activated(int iMsg)
{
Q_UNUSED(iMsg);
// fill the list of registered endings
QString formatList;
const char* supported = QT_TR_NOOP("Supported formats");
const char* allFiles = QT_TR_NOOP("All files (*.*)");
formatList = QObject::tr(supported);
formatList += QLatin1String(" (");
std::vector<std::string> filetypes = App::GetApplication().getImportTypes();
// Make sure FCStd is the very first fileformat
auto it = std::ranges::find(filetypes, "FCStd");
if (it != filetypes.end()) {
filetypes.erase(it);
filetypes.insert(filetypes.begin(), "FCStd");
}
for (it = filetypes.begin(); it != filetypes.end(); ++it) {
formatList += QLatin1String(" *.");
formatList += QLatin1String(it->c_str());
}
formatList += QLatin1String(");;");
std::map<std::string, std::string> FilterList = App::GetApplication().getImportFilters();
std::map<std::string, std::string>::iterator jt;
// Make sure the format name for FCStd is the very first in the list
for (jt = FilterList.begin(); jt != FilterList.end(); ++jt) {
if (jt->first.find("*.FCStd") != std::string::npos) {
formatList += QLatin1String(jt->first.c_str());
formatList += QLatin1String(";;");
FilterList.erase(jt);
break;
}
}
for (jt = FilterList.begin(); jt != FilterList.end(); ++jt) {
formatList += QLatin1String(jt->first.c_str());
formatList += QLatin1String(";;");
}
formatList += QObject::tr(allFiles);
QString selectedFilter;
QStringList fileList = FileDialog::getOpenFileNames(
getMainWindow(),
QObject::tr("Open Document"),
QString(),
formatList,
&selectedFilter
);
if (fileList.isEmpty()) {
// Delegate to current origin
FileOrigin* origin = OriginManager::instance()->currentOrigin();
if (!origin) {
return;
}
// load the files with the associated modules
SelectModule::Dict dict = SelectModule::importHandler(fileList, selectedFilter);
if (dict.isEmpty()) {
QMessageBox::critical(
// Check connection for origins that require authentication
if (origin->requiresAuthentication() &&
origin->connectionState() != ConnectionState::Connected) {
QMessageBox::warning(
getMainWindow(),
qApp->translate("StdCmdOpen", "Cannot Open File"),
qApp->translate("StdCmdOpen", "Loading the file %1 is not supported").arg(fileList.front())
qApp->translate("StdCmdOpen", "Not Connected"),
qApp->translate("StdCmdOpen", "Please connect to %1 before opening files.")
.arg(QString::fromStdString(origin->name()))
);
return;
}
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();
getGuiApplication()->checkPartialRestore(doc);
getGuiApplication()->checkRestoreError(doc);
}
}
origin->openDocumentInteractive();
}
//===========================================================================
@@ -715,10 +661,27 @@ StdCmdNew::StdCmdNew()
void StdCmdNew::activated(int iMsg)
{
Q_UNUSED(iMsg);
QString cmd;
cmd = QStringLiteral("App.newDocument()");
runCommand(Command::Doc, cmd.toUtf8());
doCommand(Command::Gui, "Gui.activeDocument().activeView().viewDefaultOrientation()");
// Delegate to current origin
FileOrigin* origin = OriginManager::instance()->currentOrigin();
if (!origin) {
return;
}
App::Document* doc = origin->newDocument();
if (!doc) {
return;
}
// Set default view orientation for the new document
Gui::Document* guiDoc = Application::Instance->getDocument(doc);
if (guiDoc) {
auto views = guiDoc->getMDIViewsOfType(View3DInventor::getClassTypeId());
for (auto* view : views) {
auto view3d = static_cast<View3DInventor*>(view);
view3d->getViewer()->viewDefaultOrientation();
}
}
ParameterGrp::handle hViewGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/View"
@@ -749,12 +712,33 @@ StdCmdSave::StdCmdSave()
void StdCmdSave::activated(int iMsg)
{
Q_UNUSED(iMsg);
doCommand(Command::Gui, "Gui.SendMsgToActiveView(\"Save\")");
App::Document* doc = App::GetApplication().getActiveDocument();
if (!doc) {
return;
}
// Use document's origin for save, not current origin
FileOrigin* origin = OriginManager::instance()->findOwningOrigin(doc);
if (!origin) {
// Document has no origin yet - use current origin for first save
origin = OriginManager::instance()->currentOrigin();
}
if (!origin) {
return;
}
// Try to save the document
if (!origin->saveDocument(doc)) {
// If save failed (e.g., no filename), try SaveAs
origin->saveDocumentAsInteractive(doc);
}
}
bool StdCmdSave::isActive()
{
return getGuiApplication()->sendHasMsgToActiveView("Save");
return App::GetApplication().getActiveDocument() != nullptr;
}
//===========================================================================
@@ -778,12 +762,24 @@ StdCmdSaveAs::StdCmdSaveAs()
void StdCmdSaveAs::activated(int iMsg)
{
Q_UNUSED(iMsg);
doCommand(Command::Gui, "Gui.SendMsgToActiveView(\"SaveAs\")");
App::Document* doc = App::GetApplication().getActiveDocument();
if (!doc) {
return;
}
// SaveAs uses current origin (allows saving to different origin)
FileOrigin* origin = OriginManager::instance()->currentOrigin();
if (!origin) {
return;
}
origin->saveDocumentAsInteractive(doc);
}
bool StdCmdSaveAs::isActive()
{
return getGuiApplication()->sendHasMsgToActiveView("SaveAs");
return App::GetApplication().getActiveDocument() != nullptr;
}
//===========================================================================