Fix corner cases and duplicate events, comments

This commit is contained in:
Christian Kaiser 2024-12-11 23:08:42 -03:00 committed by David Capello
parent 21ec694822
commit 747518173d
6 changed files with 15 additions and 17 deletions

View File

@ -266,6 +266,9 @@ void Context::onAddDocument(Doc* doc)
if (m_activeSiteHandler)
m_activeSiteHandler->addDoc(doc);
// Checking for an active site handler of UI not available avoids a consistency issue
// when opening a sprite from the first time, from the home screen, which would notify of an empty
// active site twice.
if (m_activeSiteHandler || !isUIAvailable())
notifyActiveSiteChanged();
}

View File

@ -269,9 +269,12 @@ void onAfterCommand(CommandExecutionEvent& ev)
// ContextObserver impl
void onActiveSiteChange(const Site& site) override
{
if (m_lastActiveSite.has_value() && *m_lastActiveSite == site)
return; // Avoid multiple events that can happen when closing since we're changing views at the
// same time we're removing documents
if (m_lastActiveSite.has_value() && *m_lastActiveSite == site) {
// Avoid multiple events that can happen when closing since
// we're changing views at the same time we're removing
// documents
return;
}
const bool fromUndo = (site.document() && site.document()->isUndoing());
call(SiteChange,

View File

@ -117,16 +117,8 @@ public:
inline bool operator==(const Site& other) const
{
if (document() != other.document())
return false;
if (frame() != other.frame())
return false;
if (cel() != other.cel())
return false;
return true;
return (document() == other.document() && sprite() == other.sprite() &&
layer() == other.layer() && frame() == other.frame() && cel() == other.cel());
}
private:

View File

@ -413,8 +413,7 @@ void MainWindow::onResize(ui::ResizeEvent& ev)
void MainWindow::onBeforeViewChange()
{
if (!getDocView())
UIContext::instance()->notifyBeforeActiveSiteChanged();
UIContext::instance()->notifyBeforeActiveSiteChanged();
}
// When the active view is changed from methods like

View File

@ -99,7 +99,9 @@ void Workspace::setActiveView(WorkspaceView* view)
if (!m_activePanel)
return;
BeforeViewChanged();
// Avoid duplicating the BeforeViewChanged event when we open for the first time
if (m_activePanel->activeView() != view)
BeforeViewChanged();
m_activePanel->setActiveView(view);

View File

@ -313,7 +313,6 @@ void UIContext::onAddDocument(Doc* doc)
// Add a tab with the new view for the document
App::instance()->workspace()->addView(view);
setActiveView(view);
view->editor()->setDefaultScroll();
}