Skip to content

Settings file: CONFIGEXPORT and CONFIGIMPORT (portable TOML config) - #25

Merged
SkryxDev merged 3 commits into
mainfrom
feat/portable-config
Nov 18, 2026
Merged

SkryxDev merged 3 commits into
mainfrom
feat/portable-config

Conversation

@SkryxDev

Copy link
Copy Markdown
Member

Portable settings file (CONFIGEXPORT / CONFIGIMPORT)

Community request "Portable Config File": one flat text file that sets up the environment (lineweights, plot styles, aliases, theme, scale, grid, units), easier to carry around than a template.

What it does

  • CONFIGEXPORT writes one TOML file; CONFIGIMPORT reads it back. Ribbon: Manage › Customization › Import Settings / Export Settings (new icons drawn in icons.rs); menu: Tools › Import Settings… / Export Settings….
  • Sections, all optional:
    • [interface]: theme, colours, language, interface size, autosave (the OPTIONS JSON form's camel-case names; applied by the app);
    • [profile]: the Options profile variables (OSMODE, GRIDUNIT, SNAPUNIT, PICKBOX, MEASUREINIT…);
    • [drawing]: MEASUREMENT, INSUNITS, LUNITS/LUPREC/AUNITS/AUPREC, ANGBASE, LTSCALE, CELWEIGHT, LWDEFAULT, DIMSCALE, TEXTSIZE, CANNOSCALE (current drawing, one undo step);
    • [plot]: plotStyleTable, displayPlotStyles, plotTransparency, lineweights (every layout of the current drawing);
    • [aliases]: ALIAS = "command" (added like ALIASEDIT's).
  • Docs with an example: docs/config-file.md (a test imports that example and expects no issues). CHANGELOG line under Unreleased › New.

Why these names

AutoCAD has no single command for this: it keeps the profile in the registry (Options › Profiles exports .arg), aliases in a .pgp file and drawing settings in templates. The names follow AutoCAD's noun + IMPORT/EXPORT pattern (PDFIMPORT, …); CONFIG alone was an old configuration command, so the prefix doesn't clash with anything current.

Format

TOML: no settings code used TOML yet (the profile is JSON in eframe storage), but TOML is the flat, commented, hand-editable format the request asked for. The toml crate (MIT/Apache, already in Cargo.lock as a transitive dependency) parses it; values are converted to JSON and go through the existing checks (sysvars::set, options::parse_ui, alias_name/command_id, page setup fields), so nothing new decides what a valid value is.

Robustness (the file is hostile input)

  • Capped at 256 KB (capped_read, refuses devices/FIFOs); not UTF-8 or not TOML → refused as a whole with the line number, nothing changes.
  • Nesting is limited by the toml parser (depth 80): tests feed 100 000 nested arrays and inline tables.
  • Unknown sections/keys and invalid values are skipped and listed (issues), the rest is applied; at most 20 000 entries read and 100 issues listed.
  • SAVEFILEPATH is neither written nor read: a folder on one computer, and a file from someone else must not move the autosaves.
  • No unwrap/expect/panics in non-test code; works on wasm (export downloads the file, import takes text).

Behaviour notes

  • JSON forms never open a dialog: configexport {file?} → {text, settings, file?}, configimport {file? | text? | settings?} → {applied, issues, message}. Without the app (CLI, MCP alone) the [interface] section comes back as interface instead of being applied.
  • From the ribbon/menu/typed: file dialog; with FILEDIA=0 or no dialog the engine asks for the file name, and the app still writes/applies [interface] (Session::config_interface).
  • Profile and interface settings persist through the existing profile storage. Imported aliases last for the session, as ALIASEDIT's do today; [drawing]/[plot] change the open drawing (MEASUREINIT covers new drawings).

Tests

  • crates/engine/tests/config_file.rs: export→import round trip into a fresh session gives the same settings (and one undo step), plot settings on every layout, unknown/invalid entries reported with the rest applied, hostile files refused, no drawing open, interface section hand-back, typed command line, docs example.
  • config.rs unit tests: TOML⇄JSON, line numbers, size and nesting limits.
  • options.rs: interface round trip between two apps, bad interface entries.
  • Checked in the running app (isolated HOME and settings folder): ribbon buttons, export, import (theme, background, units, grid, alias), FILEDIA=0 path.

Possible follow-ups (not in this PR)

  • Remember imported aliases across restarts, and/or load <settings folder>/draftcraft.toml automatically at startup.
  • Apply [drawing] defaults to new drawings started without a template.

🤖 Generated with Claude Code

SkryxDev and others added 3 commits November 18, 2026 17:13
One flat TOML file carries the interface preferences, the Options profile,
the drawing settings (units, LTSCALE, CELWEIGHT, LWDEFAULT, DIMSCALE,
CANNOSCALE…), the layouts' plot settings and the command aliases.
Export writes it; import applies every entry the existing checks accept and
lists the rest. The file is untrusted: capped at 256 KB, parser nesting
limited, not-TOML refused whole, SAVEFILEPATH never read or written.

Ribbon: Manage › Customization › Import/Export Settings, new icons;
Tools menu entries; it/zh translations; docs/config-file.md; tests for the
round trip, hostile files and the docs example.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…CHANGELOG and translations

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@SkryxDev
SkryxDev merged commit 20162a6 into main Nov 18, 2026
4 checks passed
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