diff --git a/src/Gui/FileHandler.cpp b/src/Gui/FileHandler.cpp index 8b50037fe4e0..f64113c700f4 100644 --- a/src/Gui/FileHandler.cpp +++ b/src/Gui/FileHandler.cpp @@ -37,6 +37,7 @@ #include "PythonEditor.h" #include "MainWindow.h" #include +#include using namespace Gui; @@ -162,23 +163,29 @@ bool FileHandler::openInternal() return false; } -void FileHandler::openInventor() +void FileHandler::openInternal(const char* type, const char* prop) { App::Document* doc = createDocumentIfNeeded(); QFileInfo fi; fi.setFile(filename); - Gui::cmdAppDocumentArgs(doc, "addObject('%s', '%s')", "App::InventorObject", fi.baseName().toStdString()); - Gui::cmdAppDocumentArgs(doc, "ActiveObject.FileName = '%s'", fi.absoluteFilePath().toStdString()); - Gui::cmdAppDocumentArgs(doc, "ActiveObject.Label = '%s'", fi.baseName().toStdString()); + QString encBase = Base::Tools::escapeEncodeString(fi.baseName()); + QString encPath = Base::Tools::escapeEncodeString(fi.absoluteFilePath()); + + Gui::cmdAppDocumentArgs(doc, "addObject('%s', '%s')", type, encBase.toStdString()); + Gui::cmdAppDocumentArgs(doc, "ActiveObject.%s = '%s'", prop, encPath.toStdString()); + Gui::cmdAppDocumentArgs(doc, "ActiveObject.Label = '%s'", encBase.toStdString()); Gui::cmdAppDocument(doc, "recompute()"); } -void FileHandler::openVRML() +void FileHandler::openInventor() { - App::Document* doc = createDocumentIfNeeded(); + openInternal("App::InventorObject", "FileName"); +} +void FileHandler::openVRML() +{ QFileInfo fi; fi.setFile(filename); @@ -186,25 +193,14 @@ void FileHandler::openVRML() QByteArray path = fi.absolutePath().toUtf8(); SoInput::addDirectoryFirst(path.constData()); - Gui::cmdAppDocumentArgs(doc, "addObject('%s', '%s')", "App::VRMLObject", fi.baseName().toStdString()); - Gui::cmdAppDocumentArgs(doc, "ActiveObject.VrmlFile = '%s'", fi.absoluteFilePath().toStdString()); - Gui::cmdAppDocumentArgs(doc, "ActiveObject.Label = '%s'", fi.baseName().toStdString()); - Gui::cmdAppDocument(doc, "recompute()"); + openInternal("App::VRMLObject", "VrmlFile"); SoInput::removeDirectory(path.constData()); } void FileHandler::openImage() { - App::Document* doc = createDocumentIfNeeded(); - - QFileInfo fi; - fi.setFile(filename); - - Gui::cmdAppDocumentArgs(doc, "addObject('%s', '%s')", "Image::ImagePlane", fi.baseName().toStdString()); - Gui::cmdAppDocumentArgs(doc, "ActiveObject.ImageFile = '%s'", fi.absoluteFilePath().toStdString()); - Gui::cmdAppDocumentArgs(doc, "ActiveObject.Label = '%s'", fi.baseName().toStdString()); - Gui::cmdAppDocument(doc, "recompute()"); + openInternal("Image::ImagePlane", "ImageFile"); } void FileHandler::openPython() diff --git a/src/Gui/FileHandler.h b/src/Gui/FileHandler.h index 8affbea1b9ce..d8a9a97db0e6 100644 --- a/src/Gui/FileHandler.h +++ b/src/Gui/FileHandler.h @@ -47,6 +47,7 @@ class FileHandler App::Document* getOrCreateDocument(); App::Document* getOrCreateDocument(const std::string& document); bool openInternal(); + void openInternal(const char* type, const char* prop); void openInventor(); void openVRML(); void openImage();