Issue #10: Local filesystem origin implementation - Add openDocumentInteractive() method to FileOrigin interface for UI-based file opening (shows file dialog) - Add saveDocumentAsInteractive() method for UI-based save as - Implement LocalFileOrigin::openDocumentInteractive() with full file dialog support, filter list building, and module handler integration - Implement LocalFileOrigin::saveDocumentAsInteractive() delegating to Gui::Document::saveAs() Issue #12: Modify Std_* commands to delegate to current origin - StdCmdNew::activated() now delegates to origin->newDocument() and sets up view orientation for the new document - StdCmdOpen::activated() delegates to origin->openDocumentInteractive() with connection state checking for authenticated origins - StdCmdSave::activated() uses document's owning origin (via findOwningOrigin) for save, falling back to saveDocumentAsInteractive if no filename - StdCmdSaveAs::activated() delegates to origin->saveDocumentAsInteractive() - Updated isActive() methods to check for active document The Std_* commands now work seamlessly with both LocalFileOrigin and SiloOrigin. When Local origin is selected, standard file dialogs appear. When Silo origin is selected, Silo's search/creation dialogs appear. Import and Export commands are left unchanged as they operate on document content rather than document lifecycle. Closes #10, Closes #12
This commit is contained in:
@@ -22,15 +22,23 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/PropertyStandard.h>
|
||||
|
||||
#include "FileOrigin.h"
|
||||
#include "Application.h"
|
||||
#include "BitmapFactory.h"
|
||||
#include "Document.h"
|
||||
#include "Application.h"
|
||||
#include "FileDialog.h"
|
||||
#include "MainWindow.h"
|
||||
#include "SelectModule.h"
|
||||
|
||||
|
||||
namespace Gui {
|
||||
@@ -99,6 +107,86 @@ App::Document* LocalFileOrigin::openDocument(const std::string& identity)
|
||||
return App::GetApplication().openDocument(identity.c_str());
|
||||
}
|
||||
|
||||
App::Document* LocalFileOrigin::openDocumentInteractive()
|
||||
{
|
||||
// Build file filter list for Open dialog
|
||||
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::find(filetypes.begin(), filetypes.end(), "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();
|
||||
// Make sure the format name for FCStd is the very first in the list
|
||||
for (auto 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 (const auto& filter : FilterList) {
|
||||
formatList += QLatin1String(filter.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()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Load the files with the associated modules
|
||||
SelectModule::Dict dict = SelectModule::importHandler(fileList, selectedFilter);
|
||||
if (dict.isEmpty()) {
|
||||
QMessageBox::critical(
|
||||
getMainWindow(),
|
||||
qApp->translate("StdCmdOpen", "Cannot Open File"),
|
||||
qApp->translate("StdCmdOpen", "Loading the file %1 is not supported").arg(fileList.front())
|
||||
);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
App::Document* lastDoc = nullptr;
|
||||
for (SelectModule::Dict::iterator it = dict.begin(); it != dict.end(); ++it) {
|
||||
// Set flag indicating that this load/restore has been initiated by the user
|
||||
Application::Instance->setStatus(Gui::Application::UserInitiatedOpenDocument, true);
|
||||
|
||||
Application::Instance->open(it.key().toUtf8(), it.value().toLatin1());
|
||||
|
||||
Application::Instance->setStatus(Gui::Application::UserInitiatedOpenDocument, false);
|
||||
|
||||
lastDoc = App::GetApplication().getActiveDocument();
|
||||
|
||||
Application::Instance->checkPartialRestore(lastDoc);
|
||||
Application::Instance->checkRestoreError(lastDoc);
|
||||
}
|
||||
|
||||
return lastDoc;
|
||||
}
|
||||
|
||||
bool LocalFileOrigin::saveDocument(App::Document* doc)
|
||||
{
|
||||
if (!doc) {
|
||||
@@ -125,4 +213,20 @@ bool LocalFileOrigin::saveDocumentAs(App::Document* doc, const std::string& newI
|
||||
return doc->saveAs(newIdentity.c_str());
|
||||
}
|
||||
|
||||
bool LocalFileOrigin::saveDocumentAsInteractive(App::Document* doc)
|
||||
{
|
||||
if (!doc) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get Gui document for save dialog
|
||||
Gui::Document* guiDoc = Application::Instance->getDocument(doc);
|
||||
if (!guiDoc) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Use Gui::Document::saveAs() which handles the file dialog
|
||||
return guiDoc->saveAs();
|
||||
}
|
||||
|
||||
} // namespace Gui
|
||||
|
||||
Reference in New Issue
Block a user