Add possibility to cancel the DrawingState with Undo/Redo/Cancel commands

To match the new MovingCelState behavior.
This commit is contained in:
David Capello 2021-03-26 12:05:28 -03:00
parent 768b69113a
commit a5c36d0b0f
2 changed files with 21 additions and 5 deletions

View File

@ -249,8 +249,11 @@ bool DrawingState::onKeyDown(Editor* editor, KeyMessage* msg)
Params params;
if (KeyboardShortcuts::instance()
->getCommandFromKeyMessage(msg, &command, &params)) {
// We accept zoom commands.
if (command->id() == CommandId::Zoom()) {
// We accept some commands...
if (command->id() == CommandId::Zoom() ||
command->id() == CommandId::Undo() ||
command->id() == CommandId::Redo() ||
command->id() == CommandId::Cancel()) {
UIContext::instance()->executeCommandFromMenuOrShortcut(command, params);
return true;
}
@ -330,9 +333,22 @@ bool DrawingState::canExecuteCommands()
!m_mousePressedReceived);
}
void DrawingState::onBeforeCommandExecution(CommandExecutionEvent& cmd)
void DrawingState::onBeforeCommandExecution(CommandExecutionEvent& ev)
{
if (canExecuteCommands() && m_toolLoop) {
if (!m_toolLoop)
return;
if (canExecuteCommands() ||
// Undo/Redo/Cancel will cancel the ToolLoop
ev.command()->id() == CommandId::Undo() ||
ev.command()->id() == CommandId::Redo() ||
ev.command()->id() == CommandId::Cancel()) {
if (!canExecuteCommands()) {
// Cancel the execution of Undo/Redo/Cancel because we've
// simulated it here
ev.cancel();
}
m_toolLoop->cancel();
destroyLoopIfCanceled(m_editor);
}

View File

@ -56,7 +56,7 @@ namespace app {
private:
void handleMouseMovement(const tools::Pointer& pointer);
bool canExecuteCommands();
void onBeforeCommandExecution(CommandExecutionEvent& cmd);
void onBeforeCommandExecution(CommandExecutionEvent& ev);
void destroyLoopIfCanceled(Editor* editor);
void destroyLoop(Editor* editor);