From e2aa23008d0103f2dc9f82d6a7ebd938d2450113 Mon Sep 17 00:00:00 2001 From: IoriBranford Date: Mon, 1 Jun 2026 04:52:23 -0700 Subject: [PATCH] Add command variables %exportfile and %exportpath (#4476) Exposing the last export location to commands. --- NEWS.md | 1 + docs/manual/using-commands.rst | 6 ++++++ src/tiled/command.cpp | 10 ++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 356b156bc4..e88b2ecd50 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ ### Unreleased * Added 'Collapse All' action and 'Only Expand to Current' mode to Project view (with rhythmcache, #4346) +* Added command variables %exportfile and %exportpath (#4476) ### Tiled 1.12.2 (27 May 2026) diff --git a/docs/manual/using-commands.rst b/docs/manual/using-commands.rst index 700902d8fd..3af36d0863 100644 --- a/docs/manual/using-commands.rst +++ b/docs/manual/using-commands.rst @@ -74,6 +74,12 @@ the following variables: ``%mappath`` the path in which the current file is located. +``%exportfile`` + the full path to which the current file was last exported, or an empty string if the file has not yet been exported. + +``%exportpath`` + the path in which the last export is located, or an empty string if the file has not yet been exported. + .. raw:: html
Since Tiled 1.4
diff --git a/src/tiled/command.cpp b/src/tiled/command.cpp index 8b148d76f1..625a6fe130 100644 --- a/src/tiled/command.cpp +++ b/src/tiled/command.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -72,12 +73,17 @@ static QString replaceVariables(const QString &string, bool quoteValues = true) // Perform variable replacement if (Document *document = DocumentManager::instance()->currentDocument()) { const QString &fileName = document->fileName(); - QFileInfo fileInfo(fileName); - const QString mapPath = fileInfo.absolutePath(); + const QString mapPath = QFileInfo(fileName).absolutePath(); + + const QString &exportFileName = document->lastExportFileName(); + const QString exportPath = QFileInfo(exportFileName).absolutePath(); + const QString projectPath = QFileInfo(ProjectManager::instance()->project().fileName()).absolutePath(); finalString.replace(QLatin1String("%mapfile"), replaceString.arg(fileName)); finalString.replace(QLatin1String("%mappath"), replaceString.arg(mapPath)); + finalString.replace(QLatin1String("%exportfile"), replaceString.arg(exportFileName)); + finalString.replace(QLatin1String("%exportpath"), replaceString.arg(exportPath)); finalString.replace(QLatin1String("%projectpath"), replaceString.arg(projectPath)); if (MapDocument *mapDocument = qobject_cast(document)) {