From 747518173db12e96d2ec4c0b50e2c1db2b40a695 Mon Sep 17 00:00:00 2001 From: Christian Kaiser Date: Wed, 11 Dec 2024 23:08:42 -0300 Subject: [PATCH] Fix corner cases and duplicate events, comments --- src/app/context.cpp | 3 +++ src/app/script/events_class.cpp | 9 ++++++--- src/app/site.h | 12 ++---------- src/app/ui/main_window.cpp | 3 +-- src/app/ui/workspace.cpp | 4 +++- src/app/ui_context.cpp | 1 - 6 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/app/context.cpp b/src/app/context.cpp index 26f8d1de8..046e1bad9 100644 --- a/src/app/context.cpp +++ b/src/app/context.cpp @@ -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(); } diff --git a/src/app/script/events_class.cpp b/src/app/script/events_class.cpp index a447df129..4e801a046 100644 --- a/src/app/script/events_class.cpp +++ b/src/app/script/events_class.cpp @@ -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, diff --git a/src/app/site.h b/src/app/site.h index c66a3e434..b4a993898 100644 --- a/src/app/site.h +++ b/src/app/site.h @@ -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: diff --git a/src/app/ui/main_window.cpp b/src/app/ui/main_window.cpp index 629776b1f..87c81c8d5 100644 --- a/src/app/ui/main_window.cpp +++ b/src/app/ui/main_window.cpp @@ -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 diff --git a/src/app/ui/workspace.cpp b/src/app/ui/workspace.cpp index 8c09be103..5f2a1b0db 100644 --- a/src/app/ui/workspace.cpp +++ b/src/app/ui/workspace.cpp @@ -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); diff --git a/src/app/ui_context.cpp b/src/app/ui_context.cpp index 056dedc43..eb739b2de 100644 --- a/src/app/ui_context.cpp +++ b/src/app/ui_context.cpp @@ -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(); }