From 8ee9737b6fef372cd364f597e85dc6f1d4e74d6d Mon Sep 17 00:00:00 2001 From: Amar Takhar Date: Fri, 18 Jun 2010 02:23:27 +0000 Subject: [PATCH] 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. --- aegisub/src/ass_file.cpp | 2 +- aegisub/src/audio_display.cpp | 2 +- aegisub/src/compat.cpp | 2 +- aegisub/src/dialog_search_replace.cpp | 6 +- aegisub/src/frame_main_events.cpp | 10 +-- aegisub/src/keyframe.cpp | 4 +- aegisub/src/main.cpp | 91 +++++++++++++-------------- aegisub/src/main.h | 13 ++-- aegisub/src/vfr.cpp | 2 +- aegisub/src/video_context.cpp | 2 +- 10 files changed, 67 insertions(+), 67 deletions(-) diff --git a/aegisub/src/ass_file.cpp b/aegisub/src/ass_file.cpp index 061e72b4b..89d51c2d9 100644 --- a/aegisub/src/ass_file.cpp +++ b/aegisub/src/ass_file.cpp @@ -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) { diff --git a/aegisub/src/audio_display.cpp b/aegisub/src/audio_display.cpp index 058ef9e2d..01763aad2 100644 --- a/aegisub/src/audio_display.cpp +++ b/aegisub/src/audio_display.cpp @@ -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()); } diff --git a/aegisub/src/compat.cpp b/aegisub/src/compat.cpp index e12251513..d5ee1f356 100644 --- a/aegisub/src/compat.cpp +++ b/aegisub/src/compat.cpp @@ -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)); diff --git a/aegisub/src/dialog_search_replace.cpp b/aegisub/src/dialog_search_replace.cpp index a8df26029..14ee8342d 100644 --- a/aegisub/src/dialog_search_replace.cpp +++ b/aegisub/src/dialog_search_replace.cpp @@ -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(); } diff --git a/aegisub/src/frame_main_events.cpp b/aegisub/src/frame_main_events.cpp index 992274311..857845370 100644 --- a/aegisub/src/frame_main_events.cpp +++ b/aegisub/src/frame_main_events.cpp @@ -520,28 +520,28 @@ int FrameMain::AddMacroMenuItems(wxMenu *menu, const std::vectormru->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 diff --git a/aegisub/src/keyframe.cpp b/aegisub/src/keyframe.cpp index 300d81c12..4eb1b590d 100644 --- a/aegisub/src/keyframe.cpp +++ b/aegisub/src/keyframe.cpp @@ -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)); } diff --git a/aegisub/src/main.cpp b/aegisub/src/main.cpp index 91bb80dc9..3552e6b40 100644 --- a/aegisub/src/main.cpp +++ b/aegisub/src/main.cpp @@ -77,6 +77,12 @@ #include #include +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 diff --git a/aegisub/src/main.h b/aegisub/src/main.h index 496a82fe6..7577c70f3 100644 --- a/aegisub/src/main.h +++ b/aegisub/src/main.h @@ -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 diff --git a/aegisub/src/vfr.cpp b/aegisub/src/vfr.cpp index 56145db69..ba33d28f7 100644 --- a/aegisub/src/vfr.cpp +++ b/aegisub/src/vfr.cpp @@ -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)); } diff --git a/aegisub/src/video_context.cpp b/aegisub/src/video_context.cpp index a703bcd18..8a78c530d 100644 --- a/aegisub/src/video_context.cpp +++ b/aegisub/src/video_context.cpp @@ -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());