Fix "Detach templates" not working when export target is the same file#4466
Open
Hijanhv wants to merge 1 commit intomapeditor:masterfrom
Open
Fix "Detach templates" not working when export target is the same file#4466Hijanhv wants to merge 1 commit intomapeditor:masterfrom
Hijanhv wants to merge 1 commit intomapeditor:masterfrom
Conversation
When exporting to the same file as the map/tileset, two issues caused the "Detach template instances" export option to stop working after the first export: 1. ExportHelper::prepareExportMap would clear exportFileName and exportFormat from the exported clone, causing the file on disk to lose the export settings. On the next reload (triggered by the file watcher), those settings would be gone and export-on-save would silently skip the export step. 2. The export write would update the file's timestamp but not mLastSaved, causing the file watcher to treat the export as an external change and auto-reload the document (which cleared the in-memory export settings). Fix both by: - Preserving exportFileName/exportFormat in the exported file when the export target and the map file are the same (canonically equal paths). - Calling refreshLastSaved() after a successful export to the same file so the file watcher ignores the export write and no unnecessary reload is triggered. Fixes mapeditor#4456
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #4456 — when Detach template instances and Repeat last export on save are both enabled and the export target is set to the same file as the map itself, templates were not being detached on subsequent saves.
Root cause (two interacting bugs):
ExportHelper::prepareExportMapalways clearsexportFileName/exportFormatfrom the exported clone — so the file on disk loses the export settings. On the next reload triggered by the file watcher, those settings are gone, causingexportDocumentto early-exit with an empty export filename.The export write updates the file's on-disk timestamp, but
mLastSavedis only updated during the regular save. The file watcher therefore treats the export write as an external change and auto-reloads the document, which replaces the in-memory map (including its export settings) with the freshly-loaded one that has no export settings.Fix:
ExportHelper::prepareExportMap, preserveexportFileNameandexportFormatin the exported file when the export target and the map file resolve to the same canonical path. This restores persistence across reloads and Tiled restarts.Document::refreshLastSaved(fileName)and call it after a successful export to the same file (inexportDocument,exportMapAs, andexportTilesetAs). This prevents the file watcher from treating the export write as an external change and triggering an unnecessary auto-reload.Test plan
.tmxfiletemplate=attribute)