Pull some global init logic out of FrameMain's constructor

This commit is contained in:
Thomas Goyne 2014-03-26 11:33:33 -07:00
parent 35301df5f7
commit 2ba88537a8
3 changed files with 35 additions and 41 deletions

View file

@ -49,7 +49,6 @@
#include "command/command.h"
#include "dialog_detached_video.h"
#include "dialog_manager.h"
#include "dialog_version_check.h"
#include "help_button.h"
#include "libresrc/libresrc.h"
#include "main.h"
@ -191,15 +190,6 @@ FrameMain::FrameMain()
// However LC_NUMERIC must be "C", otherwise some parsing fails.
setlocale(LC_NUMERIC, "C");
#endif
#ifdef __APPLE__
// When run from an app bundle, LC_CTYPE defaults to "C", which breaks on
// anything involving unicode and in some cases number formatting.
// The right thing to do here would be to query CoreFoundation for the user's
// locale and add .UTF-8 to that, but :effort:
LOG_D("locale") << setlocale(LC_ALL, nullptr);
setlocale(LC_CTYPE, "en_US.UTF-8");
LOG_D("locale") << setlocale(LC_ALL, nullptr);
#endif
StartupLog("Initializing context controls");
context->ass->AddCommitListener(&FrameMain::UpdateTitle, this);
@ -213,9 +203,6 @@ FrameMain::FrameMain()
context->parent = this;
context->frame = this;
StartupLog("Install PNG handler");
wxImage::AddHandler(new wxPNGHandler);
StartupLog("Apply saved Maximized state");
if (OPT_GET("App/Maximized")->GetBool()) Maximize(true);
@ -243,6 +230,9 @@ FrameMain::FrameMain()
StartupLog("Set up drag/drop target");
SetDropTarget(new AegisubFileDropTarget(this));
Bind(FILE_LIST_DROPPED, [=](wxThreadEvent &evt) {
LoadList(evt.GetPayload<wxArrayString>());
});
StartupLog("Load default file");
context->subsController->Close();
@ -252,28 +242,6 @@ FrameMain::FrameMain()
Show();
SetDisplayMode(1, 1);
// Version checker
StartupLog("Possibly perform automatic updates check");
if (OPT_GET("App/First Start")->GetBool()) {
OPT_SET("App/First Start")->SetBool(false);
#ifdef WITH_UPDATE_CHECKER
int result = wxMessageBox(_("Do you want Aegisub to check for updates whenever it starts? You can still do it manually via the Help menu."),_("Check for updates?"), wxYES_NO | wxCENTER);
OPT_SET("App/Auto/Check For Updates")->SetBool(result == wxYES);
try {
config::opt->Flush();
}
catch (agi::fs::FileSystemError const& e) {
wxMessageBox(to_wx(e.GetMessage()), "Error saving config file", wxOK | wxICON_ERROR | wxCENTER);
}
#endif
}
#ifdef WITH_UPDATE_CHECKER
PerformVersionCheck(false);
#endif
Bind(FILE_LIST_DROPPED, &FrameMain::OnFilesDropped, this);
StartupLog("Leaving FrameMain constructor");
}
@ -446,10 +414,6 @@ void FrameMain::StatusTimeout(wxString text,int ms) {
StatusClear.Start(ms,true);
}
void FrameMain::OnFilesDropped(wxThreadEvent &evt) {
LoadList(evt.GetPayload<wxArrayString>());
}
bool FrameMain::LoadList(wxArrayString list) {
std::string audio, video, subs;
get_files_to_load(list, subs, audio, video);

View file

@ -73,7 +73,6 @@ class FrameMain : public wxFrame {
void InitToolbar();
void InitContents();
void OnFilesDropped(wxThreadEvent &evt);
void UpdateTitle();
void OnKeyDown(wxKeyEvent &event);

View file

@ -39,12 +39,12 @@
#include "command/command.h"
#include "include/aegisub/hotkey.h"
#include "ass_dialogue.h"
#include "ass_file.h"
#include "auto4_base.h"
#include "auto4_lua_factory.h"
#include "compat.h"
#include "crash_writer.h"
#include "dialog_version_check.h"
#include "export_fixstyle.h"
#include "export_framerate.h"
#include "frame_main.h"
@ -235,6 +235,14 @@ bool AegisubApp::OnInit() {
}
locale.Init(lang);
#ifdef __APPLE__
// When run from an app bundle, LC_CTYPE defaults to "C", which breaks on
// anything involving unicode and in some cases number formatting.
// The right thing to do here would be to query CoreFoundation for the user's
// locale and add .UTF-8 to that, but :effort:
setlocale(LC_CTYPE, "en_US.UTF-8");
#endif
exception_message = _("Oops, Aegisub has crashed!\n\nAn attempt has been made to save a copy of your file to:\n\n%s\n\nAegisub will now close.");
// Load plugins
@ -250,11 +258,34 @@ bool AegisubApp::OnInit() {
AssExportFilterChain::Register(agi::util::make_unique<AssFixStylesFilter>());
AssExportFilterChain::Register(agi::util::make_unique<AssTransformFramerateFilter>());
StartupLog("Install PNG handler");
wxImage::AddHandler(new wxPNGHandler);
// Open main frame
StartupLog("Create main window");
frame = new FrameMain;
SetTopWindow(frame);
// Version checker
StartupLog("Possibly perform automatic updates check");
if (OPT_GET("App/First Start")->GetBool()) {
OPT_SET("App/First Start")->SetBool(false);
#ifdef WITH_UPDATE_CHECKER
int result = wxMessageBox(_("Do you want Aegisub to check for updates whenever it starts? You can still do it manually via the Help menu."),_("Check for updates?"), wxYES_NO | wxCENTER);
OPT_SET("App/Auto/Check For Updates")->SetBool(result == wxYES);
try {
config::opt->Flush();
}
catch (agi::fs::FileSystemError const& e) {
wxMessageBox(to_wx(e.GetMessage()), "Error saving config file", wxOK | wxICON_ERROR | wxCENTER);
}
#endif
}
#ifdef WITH_UPDATE_CHECKER
PerformVersionCheck(false);
#endif
// Get parameter subs
StartupLog("Parse command line");
wxArrayString subs;