Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
6 changes: 6 additions & 0 deletions docs/manual/using-commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

<div class="new new-prev">Since Tiled 1.4</div>
Expand Down
10 changes: 8 additions & 2 deletions src/tiled/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include <QAction>
#include <QDir>
#include <QFileInfo>
#include <QMessageBox>
#include <QProcess>
#include <QStandardPaths>
Expand Down Expand Up @@ -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<MapDocument*>(document)) {
Expand Down
Loading