Preferences can be used in non-UI contexts

Fixed bug running app_preferences.lua from tests repository.
This commit is contained in:
David Capello 2019-12-10 19:10:47 -03:00
parent b7f41b811a
commit fa013f4b63
3 changed files with 4 additions and 5 deletions

View File

@ -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);
}

View File

@ -76,6 +76,7 @@ namespace app {
void removeDocument(Doc* doc);
protected:
// DocsObserver impl
void onRemoveDocument(Doc* doc) override;
private:

View File

@ -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.)