Disconnect from BeforeCommandExecution signal onBeforePopState to avoid double backToPreviousState() calls

In some special cases (several key press enqueued?) we can receive a
BeforeCommandExecution signal when we are not part of the Editor state
stack anymore.

Related to 5ba8cecddebb789bf2266a1600ea4c7f56fc34b7
This commit is contained in:
David Capello 2021-03-26 11:40:10 -03:00
parent 5ba8cecdde
commit 768b69113a
7 changed files with 26 additions and 17 deletions

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2020 Igara Studio S.A.
// Copyright (C) 2018-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -103,6 +103,12 @@ void DrawingState::notifyToolLoopModifiersChange(Editor* editor)
m_toolLoopManager->notifyToolLoopModifiersChange();
}
void DrawingState::onBeforePopState(Editor* editor)
{
m_beforeCmdConn.disconnect();
StandbyState::onBeforePopState(editor);
}
bool DrawingState::onMouseDown(Editor* editor, MouseMessage* msg)
{
// Drawing loop

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A.
// Copyright (C) 2019-2021 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
@ -29,6 +29,7 @@ namespace app {
tools::ToolLoop* loop,
const DrawingType type);
virtual ~DrawingState();
virtual void onBeforePopState(Editor* editor) override;
virtual bool onMouseDown(Editor* editor, ui::MouseMessage* msg) override;
virtual bool onMouseUp(Editor* editor, ui::MouseMessage* msg) override;
virtual bool onMouseMove(Editor* editor, ui::MouseMessage* msg) override;

View File

@ -112,13 +112,13 @@ MovingCelState::MovingCelState(Editor* editor,
else
m_celStarts.push_back(cel->bounds());
}
// Hook BeforeCommandExecution signal so we know if the user wants
// to execute other command, so we can drop pixels.
m_ctxConn = UIContext::instance()->BeforeCommandExecution.connect(
&MovingCelState::onBeforeCommandExecution, this);
}
// Hook BeforeCommandExecution signal so we know if the user wants
// to execute other command, so we can drop pixels.
m_ctxConn = UIContext::instance()->BeforeCommandExecution.connect(
&MovingCelState::onBeforeCommandExecution, this);
m_cursorStart = editor->screenToEditorF(msg->position());
editor->captureMouse();
@ -130,14 +130,10 @@ MovingCelState::MovingCelState(Editor* editor,
}
}
MovingCelState::~MovingCelState()
{
m_ctxConn.disconnect();
}
void MovingCelState::onBeforePopState(Editor* editor)
{
m_ctxConn.disconnect();
StandbyState::onBeforePopState(editor);
}
bool MovingCelState::onMouseUp(Editor* editor, MouseMessage* msg)

View File

@ -44,7 +44,6 @@ namespace app {
ui::MouseMessage* msg,
const HandleType handle,
const MovingCelCollect& collect);
~MovingCelState();
virtual void onBeforePopState(Editor* editor) override;
virtual bool onMouseUp(Editor* editor, ui::MouseMessage* msg) override;
@ -74,7 +73,7 @@ namespace app {
HandleType m_handle;
Editor* m_editor;
obs::connection m_ctxConn;
obs::scoped_connection m_ctxConn;
};
} // namespace app

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2020 Igara Studio S.A.
// Copyright (C) 2020-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -109,6 +109,12 @@ EditorState::LeaveAction PlayState::onLeaveState(Editor* editor, EditorState* ne
return KeepState;
}
void PlayState::onBeforePopState(Editor* editor)
{
m_ctxConn.disconnect();
StateWithWheelBehavior::onBeforePopState(editor);
}
bool PlayState::onMouseDown(Editor* editor, MouseMessage* msg)
{
if (editor->hasCapture())

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2020 Igara Studio S.A.
// Copyright (C) 2020-2021 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
@ -32,6 +32,7 @@ namespace app {
void onEnterState(Editor* editor) override;
LeaveAction onLeaveState(Editor* editor, EditorState* newState) override;
void onBeforePopState(Editor* editor) override;
bool onMouseDown(Editor* editor, ui::MouseMessage* msg) override;
bool onMouseUp(Editor* editor, ui::MouseMessage* msg) override;
bool onMouseMove(Editor* editor, ui::MouseMessage* msg) override;

@ -1 +1 @@
Subproject commit af94c4a2317839ce629eb26ce47b80e810cbdaec
Subproject commit bddbeed8b94d2639fa945bdf14a90d7afbd58506