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:
Amar Takhar 2010-06-18 02:23:27 +00:00
parent 75bd20a6dd
commit 8ee9737b6f
10 changed files with 67 additions and 67 deletions

View file

@ -729,7 +729,7 @@ AssStyle *AssFile::GetStyle(wxString name) {
}
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) {

View file

@ -912,7 +912,7 @@ void AudioDisplay::SetFile(wxString file) {
// Add to recent
if (!is_dummy) {
AegisubApp::Get()->mru->Add("Audio", STD_STR(file));
config::mru->Add("Audio", STD_STR(file));
wxFileName fn(file);
StandardPaths::SetPathValue(_T("?audio"),fn.GetPath());
}

View file

@ -4,7 +4,7 @@
wxArrayString lagi_MRU_wxAS(const wxString &list) {
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) {
work.Add(wxString(i_lst->second.c_str(), wxConvUTF8));

View file

@ -234,7 +234,7 @@ void DialogSearchReplace::FindReplace(int mode) {
if (hasReplace) {
wxString ReplaceWith = ReplaceEdit->GetValue();
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;
if (mode == 1) Search.ReplaceNext();
else Search.ReplaceAll();
AegisubApp::Get()->mru->Add("Replace", STD_STR(ReplaceWith));
config::mru->Add("Replace", STD_STR(ReplaceWith));
}
// Add to history
AegisubApp::Get()->mru->Add("Find", STD_STR(LookFor));
config::mru->Add("Find", STD_STR(LookFor));
UpdateDropDowns();
}

View file

@ -520,28 +520,28 @@ int FrameMain::AddMacroMenuItems(wxMenu *menu, const std::vector<Automation4::Fe
/// @param event
void FrameMain::OnOpenRecentSubs(wxCommandEvent &event) {
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
/// @param event
void FrameMain::OnOpenRecentVideo(wxCommandEvent &event) {
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
/// @param event
void FrameMain::OnOpenRecentTimecodes(wxCommandEvent &event) {
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
/// @param event
void FrameMain::OnOpenRecentKeyframes(wxCommandEvent &event) {
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();
audioBox->audioDisplay->Update();
Refresh();
@ -551,7 +551,7 @@ void FrameMain::OnOpenRecentKeyframes(wxCommandEvent &event) {
/// @param event
void FrameMain::OnOpenRecentAudio(wxCommandEvent &event) {
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

View file

@ -76,7 +76,7 @@ void KeyFrameFile::Load(wxString filename) {
VideoContext::Get()->SetKeyFramesName(filename);
// Add to recent
AegisubApp::Get()->mru->Add("Keyframes", STD_STR(filename));
config::mru->Add("Keyframes", STD_STR(filename));
}
// Fail
catch (const wchar_t *error) {
@ -108,7 +108,7 @@ void KeyFrameFile::Save(wxString filename) {
}
// Add to recent
AegisubApp::Get()->mru->Add("Keyframes", STD_STR(filename));
config::mru->Add("Keyframes", STD_STR(filename));
}

View file

@ -77,6 +77,12 @@
#include <libaegisub/access.h>
#include <libaegisub/log.h>
namespace config {
agi::Options *opt;
agi::MRUManager *mru;
}
///////////////////
// wxWidgets macro
IMPLEMENT_APP(AegisubApp)
@ -137,8 +143,42 @@ void SetThreadName(DWORD dwThreadID, LPCSTR szThreadName) {
/// @return
///
bool AegisubApp::OnInit() {
agi::log::EmitSTDOUT *emit_stdout = new agi::log::EmitSTDOUT();
emit_stdout->Enable();
#ifdef _DEBUG
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__
SetThreadName((DWORD) -1,"AegiMain");
@ -154,49 +194,6 @@ emit_stdout->Enable();
SetAppName(_T("aegisub"));
#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
StartupLog(_T("Initialize random generator"));
@ -286,8 +283,8 @@ int AegisubApp::OnExit() {
SubtitleFormat::DestroyFormats();
VideoContext::Clear();
delete plugins;
delete opt;
delete mru;
delete config::opt;
delete config::mru;
#ifdef WITH_AUTOMATION
delete global_scripts;
#endif

View file

@ -52,14 +52,20 @@
class FrameMain;
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
namespace Automation4 { class AutoloadScriptManager; }
/// 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.
#define OPT_SET(x) AegisubApp::Get()->opt->Get(x)
#define OPT_SET(x) config::opt->Get(x)
/// DOCME
/// @class AegisubApp
@ -80,9 +86,6 @@ public:
/// DOCME
AegisubLocale locale;
agi::MRUManager *mru;
agi::Options *opt;
/// DOCME
FrameMain *frame;
#ifdef WITH_AUTOMATION

View file

@ -238,7 +238,7 @@ void FrameRate::Load(wxString filename) {
FrameRateType = VFR;
// Add to recent
AegisubApp::Get()->mru->Add("Timecodes", STD_STR(filename));
config::mru->Add("Timecodes", STD_STR(filename));
}

View file

@ -272,7 +272,7 @@ void VideoContext::SetVideo(const wxString &filename) {
// Set filename
videoName = filename;
AegisubApp::Get()->mru->Add("Video", STD_STR(filename));
config::mru->Add("Video", STD_STR(filename));
wxFileName fn(filename);
StandardPaths::SetPathValue(_T("?video"),fn.GetPath());