SubsController::SubsController(agi::Context *context) : context(context) , undo_connection(context->ass->AddUndoManager(&SubsController::OnCommit, this)) , commit_id(0) , saved_commit_id(0) , autosaved_commit_id(0) { autosave_timer_changed(&autosave_timer); OPT_SUB("App/Auto/Save", autosave_timer_changed, &autosave_timer); OPT_SUB("App/Auto/Save Every Seconds", autosave_timer_changed, &autosave_timer); autosave_timer.Bind(wxEVT_TIMER, [=](wxTimerEvent&) { try { auto fn = AutoSave(); if (!fn.empty()) StatusTimeout(wxString::Format(_("File backup saved as \"%s\"."), fn.wstring())); } catch (const agi::Exception& err) { StatusTimeout(to_wx("Exception when attempting to autosave file: " + err.GetMessage())); } catch (...) { StatusTimeout("Unhandled exception when attempting to autosave file."); } }); }
FrameMain::FrameMain (wxArrayString args) : wxFrame(0,-1,"",wxDefaultPosition,wxSize(920,700),wxDEFAULT_FRAME_STYLE | wxCLIP_CHILDREN) , context(new agi::Context) , showVideo(true) , showAudio(true) , blockVideoLoad(false) , blockAudioLoad(false) { StartupLog("Entering FrameMain constructor"); #ifdef __WXGTK__ // XXX HACK XXX // We need to set LC_ALL to "" here for input methods to work reliably. setlocale(LC_ALL, ""); // 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, 0); setlocale(LC_CTYPE, "en_US.UTF-8"); LOG_D("locale") << setlocale(LC_ALL, 0); #endif StartupLog("Initializing context models"); memset(context.get(), 0, sizeof(*context)); AssFile::top = context->ass = new AssFile; context->ass->AddCommitListener(&FrameMain::UpdateTitle, this); context->ass->AddFileOpenListener(&FrameMain::OnSubtitlesOpen, this); context->ass->AddFileSaveListener(&FrameMain::UpdateTitle, this); context->local_scripts = new Automation4::LocalScriptManager(context.get()); StartupLog("Initializing context controls"); context->audioController = new AudioController(context.get()); context->audioController->AddAudioOpenListener(&FrameMain::OnAudioOpen, this); context->audioController->AddAudioCloseListener(&FrameMain::OnAudioClose, this); // Initialized later due to that the selection controller is currently the subtitles grid context->selectionController = 0; context->videoController = VideoContext::Get(); // derp context->videoController->AddVideoOpenListener(&FrameMain::OnVideoOpen, this); StartupLog("Initializing context frames"); context->parent = this; context->previousFocus = 0; wxGetApp().frame = this; StartupLog("Install PNG handler"); wxImage::AddHandler(new wxPNGHandler); #ifndef __APPLE__ wxSafeYield(); #endif StartupLog("Apply saved Maximized state"); if (OPT_GET("App/Maximized")->GetBool()) Maximize(true); StartupLog("Initialize toolbar"); InitToolbar(); StartupLog("Initialize menu bar"); menu::GetMenuBar("main", this, context.get()); StartupLog("Create status bar"); CreateStatusBar(2); StartupLog("Set icon"); #ifdef _WIN32 SetIcon(wxICON(wxicon)); #else wxIcon icon; icon.CopyFromBitmap(GETIMAGE(wxicon)); SetIcon(icon); #endif StartupLog("Create views and inner main window controls"); context->dialog = new DialogManager; InitContents(); OPT_SUB("Video/Detached/Enabled", &FrameMain::OnVideoDetach, this, agi::signal::_1); StartupLog("Complete context initialization"); context->videoController->SetContext(context.get()); StartupLog("Set up Auto Save"); AutoSave.SetOwner(this, ID_APP_TIMER_AUTOSAVE); autosave_timer_changed(&AutoSave); OPT_SUB("App/Auto/Save", autosave_timer_changed, &AutoSave); OPT_SUB("App/Auto/Save Every Seconds", autosave_timer_changed, &AutoSave); StartupLog("Set up drag/drop target"); SetDropTarget(new AegisubFileDropTarget(this)); StartupLog("Load default file"); context->ass->LoadDefault(); StartupLog("Display main window"); AddFullScreenButton(this); Show(); SetDisplayMode(1, 1); StartupLog("Load files specified on command line"); LoadList(args); // 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); config::opt->Flush(); #endif } #ifdef WITH_UPDATE_CHECKER PerformVersionCheck(false); #endif Bind(FILE_LIST_DROPPED, &FrameMain::OnFilesDropped, this); StartupLog("Leaving FrameMain constructor"); }