diff --git a/src/app/context.cpp b/src/app/context.cpp index 5008a3a0f..eb4922dea 100644 --- a/src/app/context.cpp +++ b/src/app/context.cpp @@ -17,6 +17,7 @@ #include "app/commands/commands.h" #include "app/console.h" #include "app/doc.h" +#include "app/pref/preferences.h" #include "app/site.h" #include "base/scoped_value.h" #include "doc/layer.h" @@ -32,10 +33,12 @@ Context::Context() , m_lastSelectedDoc(nullptr) { m_docs.add_observer(this); + m_docs.add_observer(&Preferences::instance()); } Context::~Context() { + m_docs.remove_observer(&Preferences::instance()); m_docs.remove_observer(this); } diff --git a/src/app/pref/preferences.h b/src/app/pref/preferences.h index 029dc65a9..8c22a30c7 100644 --- a/src/app/pref/preferences.h +++ b/src/app/pref/preferences.h @@ -76,6 +76,7 @@ namespace app { void removeDocument(Doc* doc); protected: + // DocsObserver impl void onRemoveDocument(Doc* doc) override; private: diff --git a/src/app/ui_context.cpp b/src/app/ui_context.cpp index a5d38649f..ca2f2003c 100644 --- a/src/app/ui_context.cpp +++ b/src/app/ui_context.cpp @@ -14,7 +14,6 @@ #include "app/app.h" #include "app/doc.h" #include "app/modules/editors.h" -#include "app/pref/preferences.h" #include "app/site.h" #include "app/ui/color_bar.h" #include "app/ui/doc_view.h" @@ -39,8 +38,6 @@ UIContext* UIContext::m_instance = nullptr; UIContext::UIContext() : m_lastSelectedView(nullptr) { - documents().add_observer(&Preferences::instance()); - ASSERT(m_instance == NULL); m_instance = this; } @@ -50,8 +47,6 @@ UIContext::~UIContext() ASSERT(m_instance == this); m_instance = NULL; - documents().remove_observer(&Preferences::instance()); - // The context must be empty at this point. (It's to check if the UI // is working correctly, i.e. closing all files when the user can // take any action about it.)