From 2ba88537a86574f0ae20303862dfe2e953d06db9 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Wed, 26 Mar 2014 11:33:33 -0700 Subject: [PATCH] Pull some global init logic out of FrameMain's constructor --- src/frame_main.cpp | 42 +++--------------------------------------- src/frame_main.h | 1 - src/main.cpp | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 41 deletions(-) diff --git a/src/frame_main.cpp b/src/frame_main.cpp index 867066dd9..d032306d3 100644 --- a/src/frame_main.cpp +++ b/src/frame_main.cpp @@ -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()); + }); 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()); -} - bool FrameMain::LoadList(wxArrayString list) { std::string audio, video, subs; get_files_to_load(list, subs, audio, video); diff --git a/src/frame_main.h b/src/frame_main.h index 497e75e28..2d0c3c890 100644 --- a/src/frame_main.h +++ b/src/frame_main.h @@ -73,7 +73,6 @@ class FrameMain : public wxFrame { void InitToolbar(); void InitContents(); - void OnFilesDropped(wxThreadEvent &evt); void UpdateTitle(); void OnKeyDown(wxKeyEvent &event); diff --git a/src/main.cpp b/src/main.cpp index a1806d256..ac7011252 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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()); AssExportFilterChain::Register(agi::util::make_unique()); + 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;