Skip to content

fix: auto-save project after layer and text operations#33

Open
JerryZ01 wants to merge 4 commits intoHKUDS:mainfrom
JerryZ01:main
Open

fix: auto-save project after layer and text operations#33
JerryZ01 wants to merge 4 commits intoHKUDS:mainfrom
JerryZ01:main

Conversation

@JerryZ01
Copy link

Description

This PR fixes a critical bug where project state was not being saved to disk after modification operations.

Bug Description

When using commands like layer new or draw text, the changes were only stored in memory (undo stack) but not persisted to the JSON project file. This caused data loss when running commands in one-shot mode.

Changes

  • Added auto-save logic to layer_new() function
  • Added auto-save logic to draw_text() function
  • Both functions now call sess.save_session() if sess.project_path is set

Testing

Tested with the following workflow:

python3 -m cli_anything.gimp.gimp_cli project new --width 1920 --height 1080 -o test.json
python3 -m cli_anything.gimp.gimp_cli --project test.json layer new --name "BG" --type solid --fill "#ff0000"
# Verified: layers array in test.json is no longer empty

Impact

  • Users can now use CLI commands in one-shot mode without data loss
  • No breaking changes to existing functionality

- Add auto-save logic to layer_new() function
- Add auto-save logic to draw_text() function
- Ensure project state is persisted to JSON file after modifications
- Fixes issue where layers and text were not saved to disk
@yuh-yang
Copy link
Collaborator

#29

seems the relevant issue is discussed also in another PR. The current design for auto-saving and project file maintaining is via the "-s" or "--save" flags. Do they work for layer and text operations?

@JerryZ01
Copy link
Author

JerryZ01 commented Mar 12, 2026

@yuh-yang Good catch! Let me clarify:

What PR #33 does

This PR implements unconditional auto-save: whenever sess.project_path exists (user specified a project via --project or created one with -o), all layer and text ops automatically persist to disk.

# Auto-save if project path is set
if sess.project_path:
    sess.save_session()

How it differs from PR #29

PR #29 added a -s/--save flag for Shotcut—that's opt-in auto-save. Two different philosophies:

Why I went with unconditional for GIMP CLI

For one-shot CLI usage, I think users expect "run command → changes saved". Having to remember -s every time feels error-prone. REPL mode stays manual-save (same as PR #29), so interactive users aren't affected.

We could always add --no-save later if someone needs to test without persisting.

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.

2 participants