mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-29 03:32:48 +00:00
Move Strings initialization to App instance creation
This removes Strings::createInstance() and we can check with ASSERT() the singleton in the Strings class ctor/dtor.
This commit is contained in:
parent
9b82e1aac9
commit
60eee6e809
@ -129,21 +129,12 @@ public:
|
|||||||
app::UIContext m_context;
|
app::UIContext m_context;
|
||||||
};
|
};
|
||||||
|
|
||||||
class App::LoadLanguage {
|
|
||||||
public:
|
|
||||||
LoadLanguage(Preferences& pref,
|
|
||||||
Extensions& exts) {
|
|
||||||
Strings::createInstance(pref, exts);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class App::Modules {
|
class App::Modules {
|
||||||
public:
|
public:
|
||||||
LoggerModule m_loggerModule;
|
LoggerModule m_loggerModule;
|
||||||
FileSystemModule m_file_system_module;
|
FileSystemModule m_file_system_module;
|
||||||
Extensions m_extensions;
|
Extensions m_extensions;
|
||||||
// Load main language (after loading the extensions)
|
Strings m_strings; // Load main language (after loading the extensions)
|
||||||
LoadLanguage m_loadLanguage;
|
|
||||||
tools::ToolBox m_toolbox;
|
tools::ToolBox m_toolbox;
|
||||||
tools::ActiveToolManager m_activeToolManager;
|
tools::ActiveToolManager m_activeToolManager;
|
||||||
Commands m_commands;
|
Commands m_commands;
|
||||||
@ -160,7 +151,7 @@ public:
|
|||||||
Modules(const bool createLogInDesktop,
|
Modules(const bool createLogInDesktop,
|
||||||
Preferences& pref)
|
Preferences& pref)
|
||||||
: m_loggerModule(createLogInDesktop)
|
: m_loggerModule(createLogInDesktop)
|
||||||
, m_loadLanguage(pref, m_extensions)
|
, m_strings(pref, m_extensions)
|
||||||
, m_activeToolManager(&m_toolbox)
|
, m_activeToolManager(&m_toolbox)
|
||||||
, m_recent_files(pref.general.recentItems())
|
, m_recent_files(pref.general.recentItems())
|
||||||
#ifdef ENABLE_DATA_RECOVERY
|
#ifdef ENABLE_DATA_RECOVERY
|
||||||
|
@ -29,14 +29,6 @@ static Strings* singleton = nullptr;
|
|||||||
|
|
||||||
const char* Strings::kDefLanguage = "en";
|
const char* Strings::kDefLanguage = "en";
|
||||||
|
|
||||||
// static
|
|
||||||
void Strings::createInstance(Preferences& pref,
|
|
||||||
Extensions& exts)
|
|
||||||
{
|
|
||||||
ASSERT(!singleton);
|
|
||||||
singleton = new Strings(pref, exts);
|
|
||||||
}
|
|
||||||
|
|
||||||
// static
|
// static
|
||||||
Strings* Strings::instance()
|
Strings* Strings::instance()
|
||||||
{
|
{
|
||||||
@ -48,9 +40,18 @@ Strings::Strings(Preferences& pref,
|
|||||||
: m_pref(pref)
|
: m_pref(pref)
|
||||||
, m_exts(exts)
|
, m_exts(exts)
|
||||||
{
|
{
|
||||||
|
ASSERT(!singleton);
|
||||||
|
singleton = this;
|
||||||
|
|
||||||
loadLanguage(currentLanguage());
|
loadLanguage(currentLanguage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Strings::~Strings()
|
||||||
|
{
|
||||||
|
ASSERT(singleton == this);
|
||||||
|
singleton = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
std::set<LangInfo> Strings::availableLanguages() const
|
std::set<LangInfo> Strings::availableLanguages() const
|
||||||
{
|
{
|
||||||
std::set<LangInfo> result;
|
std::set<LangInfo> result;
|
||||||
|
@ -28,10 +28,12 @@ namespace app {
|
|||||||
public:
|
public:
|
||||||
static const char* kDefLanguage;
|
static const char* kDefLanguage;
|
||||||
|
|
||||||
static void createInstance(Preferences& pref,
|
|
||||||
Extensions& exts);
|
|
||||||
static Strings* instance();
|
static Strings* instance();
|
||||||
|
|
||||||
|
Strings(Preferences& pref,
|
||||||
|
Extensions& exts);
|
||||||
|
~Strings();
|
||||||
|
|
||||||
const std::string& translate(const char* id) const;
|
const std::string& translate(const char* id) const;
|
||||||
const std::string& defaultString(const char* id) const;
|
const std::string& defaultString(const char* id) const;
|
||||||
|
|
||||||
@ -60,9 +62,6 @@ namespace app {
|
|||||||
obs::signal<void()> LanguageChange;
|
obs::signal<void()> LanguageChange;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Strings(Preferences& pref,
|
|
||||||
Extensions& exts);
|
|
||||||
|
|
||||||
void loadLanguage(const std::string& langId);
|
void loadLanguage(const std::string& langId);
|
||||||
void loadStringsFromDataDir(const std::string& langId);
|
void loadStringsFromDataDir(const std::string& langId);
|
||||||
void loadStringsFromExtension(const std::string& langId);
|
void loadStringsFromExtension(const std::string& langId);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user