Skip to content

Commit

Permalink
Allow --project to be used alongside the --evaluate CLI parameter
Browse files Browse the repository at this point in the history
It is useful to be able to load a project and its extensions when using
the --evaluate parameter to execute a particular script.

Also fixed a crash in Document constructor when using the --project
parameter, since it would generally cause a project to get loaded without
there being a DocumentManager.
  • Loading branch information
bjorn committed Jun 27, 2024
1 parent 4405ccb commit 55cba6a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/tiled/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ Document::Document(DocumentType type, const QString &fileName,
mCanonicalFilePath = fileInfo.canonicalFilePath();
mReadOnly = fileInfo.exists() && !fileInfo.isWritable();

DocumentManager::instance()->registerDocument(this);
if (auto manager = DocumentManager::maybeInstance())
manager->registerDocument(this);

connect(mUndoStack, &QUndoStack::indexChanged, this, &Document::updateIsModified);
connect(mUndoStack, &QUndoStack::cleanChanged, this, &Document::updateIsModified);
Expand Down
7 changes: 2 additions & 5 deletions src/tiledapp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,23 +389,20 @@ void CommandLineHandler::evaluateScript()
for (QString argument = nextArgument(); !argument.isNull(); argument = nextArgument())
arguments.append(argument);

ScriptManager &scriptManager = ScriptManager::instance();

static bool initialized = false;
if (!initialized) {
initialized = true;

PluginManager::instance()->loadPlugins();

// Output messages to command-line
auto& logger = LoggingInterface::instance();
QObject::connect(&logger, &LoggingInterface::info, [] (const QString &message) { stdOut() << message << Qt::endl; });
QObject::connect(&logger, &LoggingInterface::warning, [] (const QString &message) { qWarning() << message; });
QObject::connect(&logger, &LoggingInterface::error, [] (const QString &message) { qWarning() << message; });

scriptManager.ensureInitialized();
initializePluginsAndExtensions();
}

ScriptManager &scriptManager = ScriptManager::instance();
scriptManager.setScriptArguments(arguments);
scriptManager.evaluateFileOrLoadModule(scriptFile);
}
Expand Down

0 comments on commit 55cba6a

Please sign in to comment.