Merge pull request #17265 from wwmayer/issue_17250

Core: Add convenience class ModuleIO to open files
This commit is contained in:
Yorik van Havre
2024-10-21 17:40:10 +02:00
committed by GitHub
6 changed files with 164 additions and 40 deletions

View File

@@ -48,10 +48,8 @@
#include <Base/Tools.h>
#include <Gui/Application.h>
#include <Gui/Command.h>
#include <Gui/MainWindow.h>
#include <Gui/Document.h>
#include <Gui/Workbench.h>
#include <Gui/FileDialog.h>
#include <Gui/ModuleIO.h>
#include <Gui/View3DInventor.h>
#include <Gui/View3DInventorViewer.h>
#include <gsl/pointers>
@@ -435,25 +433,10 @@ void StartView::postStart(PostStartBehavior behavior) const
void StartView::fileCardSelected(const QModelIndex& index)
{
auto file = index.data(static_cast<int>(Start::DisplayedFilesModelRoles::path)).toString();
std::string escapedstr = Base::Tools::escapedUnicodeFromUtf8(file.toStdString().c_str());
escapedstr = Base::Tools::escapeEncodeFilename(escapedstr);
try {
QString filename = QString::fromStdString(escapedstr);
QFileInfo fi(filename);
if (!fi.exists() || !fi.isFile()) {
QMessageBox::critical(Gui::getMainWindow(),
tr("File not found"),
tr("The file '%1' cannot be opened.").arg(filename));
}
else {
// invokes appendFile()
Gui::SelectModule::Dict dict = Gui::SelectModule::importHandler(filename);
for (Gui::SelectModule::Dict::iterator it = dict.begin(); it != dict.end(); ++it) {
Gui::Application::Instance->open(it.key().toUtf8(), it.value().toLatin1());
break;
}
}
auto filename =
index.data(static_cast<int>(Start::DisplayedFilesModelRoles::path)).toString();
Gui::ModuleIO::verifyAndOpenFile(filename);
}
catch (Base::PyException& e) {
Base::Console().Error(e.getMessage().c_str());