Skip to content

Persist per-file view settings (codec, mode, zoom, canvas, offset, palette)#35

Closed
Greengoblin007 wants to merge 3 commits intotoruzz:masterfrom
Greengoblin007:feature/per-file-view-settings
Closed

Persist per-file view settings (codec, mode, zoom, canvas, offset, palette)#35
Greengoblin007 wants to merge 3 commits intotoruzz:masterfrom
Greengoblin007:feature/per-file-view-settings

Conversation

@Greengoblin007
Copy link
Copy Markdown

Summary

Tile Molester already persists bookmarks and palette folders per file in ./resources/<filename>.xml. This PR extends the same XML with a <viewsettings> element that captures the rest of the view state, so reopening a file restores the workspace exactly where you left it instead of reverting to the file-filter defaults.

Depends on #34 (the XML parser fix). Without it, the new <viewsettings> element loads correctly on Windows but is silently dropped on macOS/Linux. If #34 lands first, this PR's diff against master will shrink to just the feature.

What gets remembered

Setting Source
Codec View > Codec
Mode (1D/2D) View > Mode
Zoom View > Zoom
Canvas size (cols × rows) Image > Canvas Size...
Slider/byte offset any navigation: keyboard, slider, Goto, byte forward/back
Externally imported palette Palette > Import From > Another File... (path + offset + size + codec ID + endianness)

Behaviour

  • On open: if <viewsettings> exists, it is applied right after the view is created, overriding the file-filter defaults. Missing or unknown values (e.g. a codec ID that no longer exists, or an external palette file that was moved) are skipped silently — never an error dialog.
  • On close / on exit: the current view state is captured and written into the same XML as bookmarks/palettes, mirroring the existing saveResources flow. No new save action, no extra prompts.
  • Backward compatible: old XMLs without <viewsettings> open exactly as before.

Two extra UX commits (separable)

Kept as their own commits so they can be dropped on review:

  1. Open files maximisedaddViewToDesktop calls view.setMaximum(true) so a freshly opened file fills the MDI area.
  2. Default file dialog to All Files (*.*) — most files used with TM are ROM dumps with extensions the bundled filters don't match, so users tend to flip to "All Files" by hand on every open. The supported-formats filter is still listed and selectable.

If either of these is unwanted, drop the second commit (1bd57f1) — the core feature stands on its own.

Test plan

  • Build with mvn package (Java 17)
  • Open a fresh ROM (no XML yet) → file-filter defaults apply, no errors
  • Adjust codec / zoom / canvas / offset / external palette, close, reopen → all restored
  • Open an old XML with bookmarks but no <viewsettings> → bookmarks still load, defaults apply
  • Set external palette, then move/rename the palette source file, reopen → falls back to default palette without error
  • Set codec, downgrade Tile Molester (no <viewsettings> parsing) → no crash, just ignored

🤖 Generated with Claude Code

Three small fixes that surface together when opening files
on macOS / Linux:

1. XMLParser: set validating=false and install a no-op
   EntityResolver. The resources XML references a relative
   DTD path with a backslash ("resources\\tmres.dtd") which
   the JDK parser tries to resolve as a URI; on non-Windows
   systems this throws "no protocol" IOException, the
   per-file resources fail to load, and bookmarks/palettes
   silently disappear.

2. TMFileResources.toXML: stop emitting the DTD declaration
   line — without validation it serves no purpose, and
   keeping it propagates the broken reference to every newly
   written XML.

3. TMView componentResized listener: guard against null
   editorCanvas. The listener is registered before
   editorCanvas is initialised in the constructor, so any
   layout pass that fires a resize between those points
   NPEs. Cheap defensive check.

4. TMUI.openFile: if loading the per-file resources XML
   throws, the FileImage was left without a TMFileResources,
   so closing the file produced no XML at all (and any
   newly-added bookmarks were lost). Fall back to default
   resources after a failed load.
Add a ViewSettings holder serialised inside the existing
per-file ./resources/<filename>.xml. Captures and reapplies:

- View > Codec
- View > Mode (1D/2D)
- View > Zoom
- Image > Canvas Size (cols × rows)
- Slider/byte offset
- Palette > Import From > Another File
  (path + offset + size + codec ID + endianness)

The settings are loaded automatically when the file is
reopened (overriding the file-filter defaults) and captured
silently when the file is closed (or the application exits
through doCloseAll). Mirrors how bookmarks and palettes are
already persisted.

Each field is optional: an old XML without <viewsettings>
loads as before. Codec IDs and external palette files that no
longer exist are ignored without error.

Motivation: opening a ROM today forces re-selecting codec,
zoom, canvas size and the external palette every single time.
Two small UX tweaks that pair naturally with the per-file
view settings feature; kept as a separate commit so they can
be reverted independently.

- addViewToDesktop now calls view.setMaximum(true) after
  setSelected, so a freshly opened file fills the MDI area
  instead of starting in a small floating frame.

- The Open File dialog now defaults to the "All Files (*.*)"
  filter rather than "All Supported Formats". The supported-
  formats filter is still listed and selectable; this only
  changes the initial selection. Most files used with TM are
  ROM dumps with extensions the bundled filters do not match,
  so users had to switch to "All Files" by hand every open.
@Greengoblin007 Greengoblin007 deleted the feature/per-file-view-settings branch May 2, 2026 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant