Skip to content

Command refresh and refactor, ui availability consistency (fix #3025)#5303

Merged
dacap merged 1 commit into
aseprite:betafrom
ckaiser:command-refresh
Aug 6, 2025
Merged

Command refresh and refactor, ui availability consistency (fix #3025)#5303
dacap merged 1 commit into
aseprite:betafrom
ckaiser:command-refresh

Conversation

@ckaiser

@ckaiser ckaiser commented Jul 27, 2025

Copy link
Copy Markdown
Member

Fixes #3025. Companion PR to api/#124

I've gone through all of the commands testing them in batch and UI mode and this PR is the resulting cleanup which:

  • Makes them behave consistently and return false in onEnabled when they will not work in batch mode, instead of failing silently or crashing.
  • Adds ui parameters to LoadMask, LoadPalette, ModifySelection, PaletteSize, SaveMask and SavePalette.
  • Modified other commands to respond better to not having the UI available.
  • Removes the CmdUIOnlyFlag and CmdRecordableFlag flags, which did nothing.

Now that Command::onEnabled is more consistent, I think we should consider adding a way for scripts to know that the command they attempted to execute was disabled by something, and ideally also for a way for commands to report errors. Right now, the command return value doesn't really do much.

One way to do this would be adding something like app.getLastCommandError() or something like that, that we could populate after every execution? Maybe with some common error codes or strings, that way scripts could communicate in their own way what errors they stumble into.

@ckaiser ckaiser changed the base branch from main to beta July 27, 2025 19:59

@aseprite-bot aseprite-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment thread src/app/commands/cmd_close_file.cpp
Comment thread src/app/commands/cmd_copy_cel.cpp
Comment thread src/app/commands/cmd_remove_slice.cpp
Comment thread src/app/commands/cmd_set_ink_type.cpp
@dacap dacap assigned dacap and unassigned dacap Jul 29, 2025

@dacap dacap left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't make a full review, but just some comments so far in some changes I was able to see.

Comment thread src/app/commands/cmd_frame_properties.cpp Outdated
Comment thread src/app/commands/cmd_launch.cpp Outdated
Comment thread src/app/commands/cmd_load_mask.cpp
@dacap

dacap commented Jul 29, 2025

Copy link
Copy Markdown
Member

One way to do this would be adding something like app.getLastCommandError() or something like that, that we could populate after every execution? Maybe with some common error codes or strings, that way scripts could communicate in their own way what errors they stumble into.

Actually Command_call should return false if the command fails (an exception is thrown).

Anyway there is not too much information about the error, and for regular errors (non-exceptional, like the UI is not available) we could try to create a new method to return command results (probably related to #3952).

I'd leave this error handling for the future (not in this PR).

@ckaiser ckaiser force-pushed the command-refresh branch 2 times, most recently from 5108762 to b9c8838 Compare July 29, 2025 17:13
@ckaiser

ckaiser commented Jul 29, 2025

Copy link
Copy Markdown
Member Author

Did the changes, I'm also gonna see about documenting the fact that we reuse instances because it can definitely be a gotcha for script authors as well.

Actually Command_call should return false if the command fails (an exception is thrown).

An exception yes, but the command being disabled still returns true when the command hasn't been run, which I think we should change especially now that it's more consistently indicating stuff.

Edit: Added CommandResult::kDisabled and in testing it seems to work well for this kind of thing, let me know what you think!

@dacap

dacap commented Jul 29, 2025

Copy link
Copy Markdown
Member

I'm also gonna see about documenting the fact that we reuse instances because it can definitely be a gotcha for script authors as well.

I think this internal detail shouldn't be documented in the API. Shouldn't affect the behavior of scripts, at least commands should behave like an action in itself that doesn't depend on previous calls of the same command.

An exception yes, but the command being disabled still returns true when the command hasn't been run, which I think we should change especially now that it's more consistently indicating stuff.

Edit: Added CommandResult::kDisabled and in testing it seems to work well for this kind of thing, let me know what you think!

Yeah, we can add a new kind of result code 👍 Anyway we might need some way to check if the command is enabled before executing it, e.g.:

if app.command.SaveFile.enabled then
  ...
end

@ckaiser

ckaiser commented Jul 29, 2025

Copy link
Copy Markdown
Member Author

Added the .enabled property and added some more isUIEnabled checks.

Edit: Looking into the test failures.

@dacap dacap left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fully review the PR now, some extra changes 🔍

Comment thread src/app/commands/cmd_goto_layer.cpp Outdated
Comment thread src/app/commands/cmd_goto_layer.cpp Outdated
Comment thread src/app/commands/cmd_rotate.cpp Outdated
Comment thread src/app/commands/cmd_frame_properties.cpp Outdated
Comment thread src/app/commands/cmd_frame_properties.cpp Outdated
Comment thread src/app/commands/cmd_save_mask.cpp Outdated
Comment thread src/app/commands/cmd_save_mask.cpp Outdated
Comment thread src/app/commands/cmd_save_palette.cpp

@aseprite-bot aseprite-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment thread src/app/commands/cmd_remove_slice.cpp
Comment thread src/app/commands/cmd_save_palette.cpp Outdated
@ckaiser

ckaiser commented Aug 1, 2025

Copy link
Copy Markdown
Member Author

Added parameters for PasteTextCommand, this involved basically writing a different version that didn't use Editor::pasteImage, so an extra set of eyes on the implementation is appreciated since pixel pushing is not my forte (yet?)

@aseprite-bot aseprite-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment thread src/app/commands/cmd_paste_text.cpp
Comment thread src/app/commands/cmd_paste_text.cpp

@aseprite-bot aseprite-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment thread src/app/commands/cmd_paste_text.cpp
Comment thread src/app/commands/cmd_paste_text.cpp
@ckaiser ckaiser changed the title [WIP] Command refresh Command refresh and refactor, ui availability consistency (fix #3025) Aug 5, 2025
@ckaiser ckaiser marked this pull request as ready for review August 5, 2025 20:34
@ckaiser ckaiser assigned dacap and unassigned ckaiser Aug 5, 2025
@ckaiser ckaiser requested a review from dacap August 5, 2025 20:35
@dacap dacap merged commit 366751d into aseprite:beta Aug 6, 2025
12 checks passed
@ckaiser ckaiser deleted the command-refresh branch September 10, 2025 05:17
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.

Add ui parameter to all commands to disable dialog/user interaction on each command

3 participants