mirror of https://github.com/odrling/Aegisub
Move mru,opt objects out of the main singleton and into a global config:: namespace. With exception of the log object these are initialised during startup to ensure they are initalised after the log object.
Originally committed to SVN as r4538.
This commit is contained in:
parent
75bd20a6dd
commit
8ee9737b6f
|
@ -729,7 +729,7 @@ AssStyle *AssFile::GetStyle(wxString name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssFile::AddToRecent(wxString file) {
|
void AssFile::AddToRecent(wxString file) {
|
||||||
AegisubApp::Get()->mru->Add("Subtitle", STD_STR(file));
|
config::mru->Add("Subtitle", STD_STR(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString AssFile::GetWildcardList(int mode) {
|
wxString AssFile::GetWildcardList(int mode) {
|
||||||
|
|
|
@ -912,7 +912,7 @@ void AudioDisplay::SetFile(wxString file) {
|
||||||
|
|
||||||
// Add to recent
|
// Add to recent
|
||||||
if (!is_dummy) {
|
if (!is_dummy) {
|
||||||
AegisubApp::Get()->mru->Add("Audio", STD_STR(file));
|
config::mru->Add("Audio", STD_STR(file));
|
||||||
wxFileName fn(file);
|
wxFileName fn(file);
|
||||||
StandardPaths::SetPathValue(_T("?audio"),fn.GetPath());
|
StandardPaths::SetPathValue(_T("?audio"),fn.GetPath());
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
wxArrayString lagi_MRU_wxAS(const wxString &list) {
|
wxArrayString lagi_MRU_wxAS(const wxString &list) {
|
||||||
wxArrayString work;
|
wxArrayString work;
|
||||||
|
|
||||||
const agi::MRUManager::MRUListMap *map_list = AegisubApp::Get()->mru->Get(STD_STR(list));
|
const agi::MRUManager::MRUListMap *map_list = config::mru->Get(STD_STR(list));
|
||||||
|
|
||||||
for (agi::MRUManager::MRUListMap::const_iterator i_lst = map_list->begin(); i_lst != map_list->end(); ++i_lst) {
|
for (agi::MRUManager::MRUListMap::const_iterator i_lst = map_list->begin(); i_lst != map_list->end(); ++i_lst) {
|
||||||
work.Add(wxString(i_lst->second.c_str(), wxConvUTF8));
|
work.Add(wxString(i_lst->second.c_str(), wxConvUTF8));
|
||||||
|
|
|
@ -234,7 +234,7 @@ void DialogSearchReplace::FindReplace(int mode) {
|
||||||
if (hasReplace) {
|
if (hasReplace) {
|
||||||
wxString ReplaceWith = ReplaceEdit->GetValue();
|
wxString ReplaceWith = ReplaceEdit->GetValue();
|
||||||
Search.ReplaceWith = ReplaceWith;
|
Search.ReplaceWith = ReplaceWith;
|
||||||
AegisubApp::Get()->mru->Add("Replace", STD_STR(ReplaceWith));
|
config::mru->Add("Replace", STD_STR(ReplaceWith));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,11 +244,11 @@ void DialogSearchReplace::FindReplace(int mode) {
|
||||||
Search.ReplaceWith = ReplaceWith;
|
Search.ReplaceWith = ReplaceWith;
|
||||||
if (mode == 1) Search.ReplaceNext();
|
if (mode == 1) Search.ReplaceNext();
|
||||||
else Search.ReplaceAll();
|
else Search.ReplaceAll();
|
||||||
AegisubApp::Get()->mru->Add("Replace", STD_STR(ReplaceWith));
|
config::mru->Add("Replace", STD_STR(ReplaceWith));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to history
|
// Add to history
|
||||||
AegisubApp::Get()->mru->Add("Find", STD_STR(LookFor));
|
config::mru->Add("Find", STD_STR(LookFor));
|
||||||
UpdateDropDowns();
|
UpdateDropDowns();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -520,28 +520,28 @@ int FrameMain::AddMacroMenuItems(wxMenu *menu, const std::vector<Automation4::Fe
|
||||||
/// @param event
|
/// @param event
|
||||||
void FrameMain::OnOpenRecentSubs(wxCommandEvent &event) {
|
void FrameMain::OnOpenRecentSubs(wxCommandEvent &event) {
|
||||||
int number = event.GetId()-Menu_File_Recent;
|
int number = event.GetId()-Menu_File_Recent;
|
||||||
LoadSubtitles(lagi_wxString(AegisubApp::Get()->mru->GetEntry("Subtitle", number)));
|
LoadSubtitles(lagi_wxString(config::mru->GetEntry("Subtitle", number)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Open recent video menu entry
|
/// @brief Open recent video menu entry
|
||||||
/// @param event
|
/// @param event
|
||||||
void FrameMain::OnOpenRecentVideo(wxCommandEvent &event) {
|
void FrameMain::OnOpenRecentVideo(wxCommandEvent &event) {
|
||||||
int number = event.GetId()-Menu_Video_Recent;
|
int number = event.GetId()-Menu_Video_Recent;
|
||||||
LoadVideo(lagi_wxString(AegisubApp::Get()->mru->GetEntry("Video", number)));
|
LoadVideo(lagi_wxString(config::mru->GetEntry("Video", number)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Open recent timecodes entry
|
/// @brief Open recent timecodes entry
|
||||||
/// @param event
|
/// @param event
|
||||||
void FrameMain::OnOpenRecentTimecodes(wxCommandEvent &event) {
|
void FrameMain::OnOpenRecentTimecodes(wxCommandEvent &event) {
|
||||||
int number = event.GetId()-Menu_Timecodes_Recent;
|
int number = event.GetId()-Menu_Timecodes_Recent;
|
||||||
LoadVFR(lagi_wxString(AegisubApp::Get()->mru->GetEntry("Timecodes", number)));
|
LoadVFR(lagi_wxString(config::mru->GetEntry("Timecodes", number)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Open recent Keyframes entry
|
/// @brief Open recent Keyframes entry
|
||||||
/// @param event
|
/// @param event
|
||||||
void FrameMain::OnOpenRecentKeyframes(wxCommandEvent &event) {
|
void FrameMain::OnOpenRecentKeyframes(wxCommandEvent &event) {
|
||||||
int number = event.GetId()-Menu_Keyframes_Recent;
|
int number = event.GetId()-Menu_Keyframes_Recent;
|
||||||
KeyFrameFile::Load(lagi_wxString(AegisubApp::Get()->mru->GetEntry("Keyframes", number)));
|
KeyFrameFile::Load(lagi_wxString(config::mru->GetEntry("Keyframes", number)));
|
||||||
videoBox->videoSlider->Refresh();
|
videoBox->videoSlider->Refresh();
|
||||||
audioBox->audioDisplay->Update();
|
audioBox->audioDisplay->Update();
|
||||||
Refresh();
|
Refresh();
|
||||||
|
@ -551,7 +551,7 @@ void FrameMain::OnOpenRecentKeyframes(wxCommandEvent &event) {
|
||||||
/// @param event
|
/// @param event
|
||||||
void FrameMain::OnOpenRecentAudio(wxCommandEvent &event) {
|
void FrameMain::OnOpenRecentAudio(wxCommandEvent &event) {
|
||||||
int number = event.GetId()-Menu_Audio_Recent;
|
int number = event.GetId()-Menu_Audio_Recent;
|
||||||
LoadAudio(lagi_wxString(AegisubApp::Get()->mru->GetEntry("Audio", number)));
|
LoadAudio(lagi_wxString(config::mru->GetEntry("Audio", number)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Open new Window
|
/// @brief Open new Window
|
||||||
|
|
|
@ -76,7 +76,7 @@ void KeyFrameFile::Load(wxString filename) {
|
||||||
VideoContext::Get()->SetKeyFramesName(filename);
|
VideoContext::Get()->SetKeyFramesName(filename);
|
||||||
|
|
||||||
// Add to recent
|
// Add to recent
|
||||||
AegisubApp::Get()->mru->Add("Keyframes", STD_STR(filename));
|
config::mru->Add("Keyframes", STD_STR(filename));
|
||||||
}
|
}
|
||||||
// Fail
|
// Fail
|
||||||
catch (const wchar_t *error) {
|
catch (const wchar_t *error) {
|
||||||
|
@ -108,7 +108,7 @@ void KeyFrameFile::Save(wxString filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to recent
|
// Add to recent
|
||||||
AegisubApp::Get()->mru->Add("Keyframes", STD_STR(filename));
|
config::mru->Add("Keyframes", STD_STR(filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,12 @@
|
||||||
#include <libaegisub/access.h>
|
#include <libaegisub/access.h>
|
||||||
#include <libaegisub/log.h>
|
#include <libaegisub/log.h>
|
||||||
|
|
||||||
|
namespace config {
|
||||||
|
agi::Options *opt;
|
||||||
|
agi::MRUManager *mru;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
// wxWidgets macro
|
// wxWidgets macro
|
||||||
IMPLEMENT_APP(AegisubApp)
|
IMPLEMENT_APP(AegisubApp)
|
||||||
|
@ -137,8 +143,42 @@ void SetThreadName(DWORD dwThreadID, LPCSTR szThreadName) {
|
||||||
/// @return
|
/// @return
|
||||||
///
|
///
|
||||||
bool AegisubApp::OnInit() {
|
bool AegisubApp::OnInit() {
|
||||||
agi::log::EmitSTDOUT *emit_stdout = new agi::log::EmitSTDOUT();
|
#ifdef _DEBUG
|
||||||
emit_stdout->Enable();
|
agi::log::EmitSTDOUT *emit_stdout = new agi::log::EmitSTDOUT();
|
||||||
|
emit_stdout->Enable();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const std::string conf_mru(StandardPaths::DecodePath(_T("?user/mru.json")));
|
||||||
|
config::mru = new agi::MRUManager(conf_mru, GET_DEFAULT_CONFIG(default_mru));
|
||||||
|
|
||||||
|
// Set config file
|
||||||
|
StartupLog(_T("Load configuration"));
|
||||||
|
try {
|
||||||
|
const std::string conf_user(StandardPaths::DecodePath(_T("?user/config.json")));
|
||||||
|
config::opt = new agi::Options(conf_user, GET_DEFAULT_CONFIG(default_config));
|
||||||
|
} catch (agi::Exception& e) {
|
||||||
|
wxPrintf("Caught agi::Exception: %s -> %s\n", e.GetName(), e.GetMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __WXMSW__
|
||||||
|
// Try loading configuration from the install dir if one exists there
|
||||||
|
try {
|
||||||
|
const std::string conf_local(StandardPaths::DecodePath(_T("?data/config.json")));
|
||||||
|
std::ifstream* localConfig = agi::io::Open(conf_local);
|
||||||
|
opt->ConfigNext(*localConfig);
|
||||||
|
delete localConfig;
|
||||||
|
|
||||||
|
if (OPT_GET("App/Local Config")->GetBool()) {
|
||||||
|
// Local config, make ?user mean ?data so all user settings are placed in install dir
|
||||||
|
StandardPaths::SetPathValue(_T("?user"), StandardPaths::DecodePath(_T("?data")));
|
||||||
|
}
|
||||||
|
} catch (agi::acs::AcsError const&) {
|
||||||
|
// File doesn't exist or we can't read it
|
||||||
|
// Might be worth displaying an error in the second case
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
config::opt->ConfigUser();
|
||||||
|
|
||||||
|
|
||||||
#ifdef __VISUALC__
|
#ifdef __VISUALC__
|
||||||
SetThreadName((DWORD) -1,"AegiMain");
|
SetThreadName((DWORD) -1,"AegiMain");
|
||||||
|
@ -154,49 +194,6 @@ emit_stdout->Enable();
|
||||||
SetAppName(_T("aegisub"));
|
SetAppName(_T("aegisub"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const std::string conf_mru(StandardPaths::DecodePath(_T("?user/mru.json")));
|
|
||||||
mru = new agi::MRUManager(conf_mru, GET_DEFAULT_CONFIG(default_mru));
|
|
||||||
|
|
||||||
// Set config file
|
|
||||||
StartupLog(_T("Load configuration"));
|
|
||||||
try {
|
|
||||||
const std::string conf_user(StandardPaths::DecodePath(_T("?user/config.json")));
|
|
||||||
opt = new agi::Options(conf_user, GET_DEFAULT_CONFIG(default_config));
|
|
||||||
|
|
||||||
#ifdef __WXMSW__
|
|
||||||
// Try loading configuration from the install dir if one exists there
|
|
||||||
try {
|
|
||||||
const std::string conf_local(StandardPaths::DecodePath(_T("?data/config.json")));
|
|
||||||
std::ifstream* localConfig = agi::io::Open(conf_local);
|
|
||||||
opt->ConfigNext(*localConfig);
|
|
||||||
delete localConfig;
|
|
||||||
|
|
||||||
if (OPT_GET("App/Local Config")->GetBool()) {
|
|
||||||
// Local config, make ?user mean ?data so all user settings are placed in install dir
|
|
||||||
StandardPaths::SetPathValue(_T("?user"), StandardPaths::DecodePath(_T("?data")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (agi::acs::AcsError const&) {
|
|
||||||
// File doesn't exist or we can't read it
|
|
||||||
// Might be worth displaying an error in the second case
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
opt->ConfigUser();
|
|
||||||
/*
|
|
||||||
#ifdef _DEBUG
|
|
||||||
const std::string conf_default("default_config.json");
|
|
||||||
std::istream *stream = agi::io::Open(conf_default);
|
|
||||||
opt->ConfigDefault(*stream);
|
|
||||||
delete stream;
|
|
||||||
#else
|
|
||||||
opt->ConfigDefault(GET_DEFAULT_CONFIG(default_config));
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
// opt->ConfigDefault(GET_DEFAULT_CONFIG(default_config));
|
|
||||||
|
|
||||||
} catch (agi::Exception& e) {
|
|
||||||
wxPrintf("Caught agi::Exception: %s -> %s\n", e.GetName(), e.GetMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize randomizer
|
// Initialize randomizer
|
||||||
StartupLog(_T("Initialize random generator"));
|
StartupLog(_T("Initialize random generator"));
|
||||||
|
@ -286,8 +283,8 @@ int AegisubApp::OnExit() {
|
||||||
SubtitleFormat::DestroyFormats();
|
SubtitleFormat::DestroyFormats();
|
||||||
VideoContext::Clear();
|
VideoContext::Clear();
|
||||||
delete plugins;
|
delete plugins;
|
||||||
delete opt;
|
delete config::opt;
|
||||||
delete mru;
|
delete config::mru;
|
||||||
#ifdef WITH_AUTOMATION
|
#ifdef WITH_AUTOMATION
|
||||||
delete global_scripts;
|
delete global_scripts;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -52,14 +52,20 @@
|
||||||
class FrameMain;
|
class FrameMain;
|
||||||
class PluginManager;
|
class PluginManager;
|
||||||
|
|
||||||
|
/// For holding all configuration-related objects and values.
|
||||||
|
namespace config {
|
||||||
|
extern agi::Options *opt; ///< Options
|
||||||
|
extern agi::MRUManager *mru; ///< Most Recently Used
|
||||||
|
}
|
||||||
|
|
||||||
/// DOCME
|
/// DOCME
|
||||||
namespace Automation4 { class AutoloadScriptManager; }
|
namespace Automation4 { class AutoloadScriptManager; }
|
||||||
|
|
||||||
/// Macro to get OptionValue object.
|
/// Macro to get OptionValue object.
|
||||||
#define OPT_GET(x) AegisubApp::Get()->opt->Get(x)
|
#define OPT_GET(x) config::opt->Get(x)
|
||||||
|
|
||||||
/// Macro to set OptionValue object.
|
/// Macro to set OptionValue object.
|
||||||
#define OPT_SET(x) AegisubApp::Get()->opt->Get(x)
|
#define OPT_SET(x) config::opt->Get(x)
|
||||||
|
|
||||||
/// DOCME
|
/// DOCME
|
||||||
/// @class AegisubApp
|
/// @class AegisubApp
|
||||||
|
@ -80,9 +86,6 @@ public:
|
||||||
/// DOCME
|
/// DOCME
|
||||||
AegisubLocale locale;
|
AegisubLocale locale;
|
||||||
|
|
||||||
agi::MRUManager *mru;
|
|
||||||
agi::Options *opt;
|
|
||||||
|
|
||||||
/// DOCME
|
/// DOCME
|
||||||
FrameMain *frame;
|
FrameMain *frame;
|
||||||
#ifdef WITH_AUTOMATION
|
#ifdef WITH_AUTOMATION
|
||||||
|
|
|
@ -238,7 +238,7 @@ void FrameRate::Load(wxString filename) {
|
||||||
FrameRateType = VFR;
|
FrameRateType = VFR;
|
||||||
|
|
||||||
// Add to recent
|
// Add to recent
|
||||||
AegisubApp::Get()->mru->Add("Timecodes", STD_STR(filename));
|
config::mru->Add("Timecodes", STD_STR(filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -272,7 +272,7 @@ void VideoContext::SetVideo(const wxString &filename) {
|
||||||
|
|
||||||
// Set filename
|
// Set filename
|
||||||
videoName = filename;
|
videoName = filename;
|
||||||
AegisubApp::Get()->mru->Add("Video", STD_STR(filename));
|
config::mru->Add("Video", STD_STR(filename));
|
||||||
wxFileName fn(filename);
|
wxFileName fn(filename);
|
||||||
StandardPaths::SetPathValue(_T("?video"),fn.GetPath());
|
StandardPaths::SetPathValue(_T("?video"),fn.GetPath());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue