Core: Support of import options

This commit is contained in:
wmayer
2024-06-18 08:25:19 +02:00
committed by Chris Hennes
parent 5f8398278f
commit c1e125194a

View File

@@ -601,8 +601,16 @@ void Application::open(const char* FileName, const char* Module)
// issue module loading
Command::doCommand(Command::App, "import %s", Module);
// load the file with the module
Command::doCommand(Command::App, "%s.open(u\"%s\")", Module, unicodepath.c_str());
// check for additional import options
std::stringstream str;
str << "if hasattr(" << Module << ", \"importOptions\"):\n"
<< " options = " << Module << ".importOptions(u\"" << unicodepath << "\")\n"
<< " " << Module << ".open(u\"" << unicodepath << "\", options = options)\n"
<< "else:\n"
<< " " << Module << ".open(u\"" << unicodepath << "\")\n";
std::string code = str.str();
Gui::Command::runCommand(Gui::Command::App, code.c_str());
// ViewFit
if (sendHasMsgToActiveView("ViewFit")) {
@@ -663,15 +671,26 @@ void Application::importFrom(const char* FileName, const char* DocName, const ch
doc->openCommand(QT_TRANSLATE_NOOP("Command", "Import"));
}
// check for additional import options
std::stringstream str;
if (DocName) {
Command::doCommand(Command::App, "%s.insert(u\"%s\",\"%s\")"
, Module, unicodepath.c_str(), DocName);
str << "if hasattr(" << Module << ", \"importOptions\"):\n"
<< " options = " << Module << ".importOptions(u\"" << unicodepath << "\")\n"
<< " " << Module << ".insert(u\"" << unicodepath << "\", \"" << DocName << "\", options = options)\n"
<< "else:\n"
<< " " << Module << ".insert(u\"" << unicodepath << "\", \"" << DocName << "\")\n";
}
else {
Command::doCommand(Command::App, "%s.insert(u\"%s\")"
, Module, unicodepath.c_str());
str << "if hasattr(" << Module << ", \"importOptions\"):\n"
<< " options = " << Module << ".importOptions(u\"" << unicodepath << "\")\n"
<< " " << Module << ".insert(u\"" << unicodepath << "\", options = options)\n"
<< "else:\n"
<< " " << Module << ".insert(u\"" << unicodepath << "\")\n";
}
std::string code = str.str();
Gui::Command::runCommand(Gui::Command::App, code.c_str());
// Commit the transaction
if (doc && !pendingCommand) {
doc->commitCommand();