Clean up frame_main a bit

Delete some pointless comments, move documentation to the header, and
extend it a bit

Sort prototypes in the header

Move event IDs out of the header

Remove a few unused includes

Assorted cosmetic changse

Originally committed to SVN as r5463.
This commit is contained in:
Thomas Goyne 2011-07-15 04:05:49 +00:00
parent 95cadb5226
commit 0af7ae7fca
2 changed files with 126 additions and 229 deletions

View File

@ -35,6 +35,8 @@
#include "config.h" #include "config.h"
#include "frame_main.h"
#ifndef AGI_PRE #ifndef AGI_PRE
#include <wx/clipbrd.h> #include <wx/clipbrd.h>
#include <wx/filename.h> #include <wx/filename.h>
@ -59,9 +61,6 @@
#ifdef WITH_AUTOMATION #ifdef WITH_AUTOMATION
#include "auto4_base.h" #include "auto4_base.h"
#endif #endif
#ifdef WITH_AVISYNTH
#include "avisynth_wrap.h"
#endif
#include "compat.h" #include "compat.h"
#include "command/command.h" #include "command/command.h"
#include "dialog_detached_video.h" #include "dialog_detached_video.h"
@ -69,7 +68,6 @@
#include "dialog_styling_assistant.h" #include "dialog_styling_assistant.h"
#include "dialog_version_check.h" #include "dialog_version_check.h"
#include "drop.h" #include "drop.h"
#include "frame_main.h"
#include "help_button.h" #include "help_button.h"
#include "libresrc/libresrc.h" #include "libresrc/libresrc.h"
#include "main.h" #include "main.h"
@ -78,7 +76,6 @@
#include "subs_edit_ctrl.h" #include "subs_edit_ctrl.h"
#include "subs_grid.h" #include "subs_grid.h"
#include "text_file_reader.h" #include "text_file_reader.h"
#include "text_file_writer.h"
#include "utils.h" #include "utils.h"
#include "version.h" #include "version.h"
#include "video_box.h" #include "video_box.h"
@ -87,21 +84,24 @@
#include "video_provider_manager.h" #include "video_provider_manager.h"
#include "video_slider.h" #include "video_slider.h"
enum {
ID_TOOLBAR_ZOOM_DROPDOWN = 11001,
ID_APP_TIMER_AUTOSAVE = 12001,
ID_APP_TIMER_STATUSCLEAR = 12002,
ID_MENU_AUTOMATION_MACRO = 13006,
ID_SASH_MAIN_AUDIO = 14001
};
#ifdef WITH_STARTUPLOG #ifdef WITH_STARTUPLOG
#define StartupLog(a) MessageBox(0, a, "Aegisub startup log", 0)
/// DOCME
#define StartupLog(a) MessageBox(0, a, _T("Aegisub startup log"), 0)
#else #else
/// DOCME
#define StartupLog(a) #define StartupLog(a)
#endif #endif
static void autosave_timer_changed(wxTimer *timer, const agi::OptionValue &opt); static void autosave_timer_changed(wxTimer *timer, const agi::OptionValue &opt);
FrameMain::FrameMain (wxArrayString args) FrameMain::FrameMain (wxArrayString args)
: wxFrame ((wxFrame*)NULL,-1,_T(""),wxDefaultPosition,wxSize(920,700),wxDEFAULT_FRAME_STYLE | wxCLIP_CHILDREN) : wxFrame(0,-1,"",wxDefaultPosition,wxSize(920,700),wxDEFAULT_FRAME_STYLE | wxCLIP_CHILDREN)
, context(new agi::Context) , context(new agi::Context)
, showVideo(true) , showVideo(true)
, showAudio(true) , showAudio(true)
@ -121,7 +121,6 @@ FrameMain::FrameMain (wxArrayString args)
/* XXX HACK XXX */ /* XXX HACK XXX */
#endif #endif
StartupLog("Initializing context models"); StartupLog("Initializing context models");
AssFile::top = context->ass = new AssFile; AssFile::top = context->ass = new AssFile;
context->ass->AddCommitListener(&FrameMain::UpdateTitle, this); context->ass->AddCommitListener(&FrameMain::UpdateTitle, this);
@ -220,15 +219,20 @@ FrameMain::FrameMain (wxArrayString args)
Show(); Show();
SetDisplayMode(1, 1); SetDisplayMode(1, 1);
//ShowFullScreen(true,wxFULLSCREEN_NOBORDER | wxFULLSCREEN_NOCAPTION);
StartupLog("Leaving FrameMain constructor"); StartupLog("Leaving FrameMain constructor");
} }
/// @brief FrameMain destructor
FrameMain::~FrameMain () { FrameMain::~FrameMain () {
context->videoController->SetVideo(""); context->videoController->SetVideo("");
context->audioController->CloseAudio(); context->audioController->CloseAudio();
DeInitContents(); if (context->detachedVideo) context->detachedVideo->Destroy();
if (context->stylingAssistant) context->stylingAssistant->Destroy();
SubsGrid->ClearMaps();
delete audioBox;
delete EditBox;
delete videoBox;
delete context->ass;
HelpButton::ClearPages();
delete context->audioController; delete context->audioController;
#ifdef WITH_AUTOMATION #ifdef WITH_AUTOMATION
delete context->local_scripts; delete context->local_scripts;
@ -244,31 +248,26 @@ void FrameMain::cmd_call(wxCommandEvent& event) {
OnAutomationMacro(event); OnAutomationMacro(event);
} }
/// @brief Initialize toolbar
void FrameMain::InitToolbar () { void FrameMain::InitToolbar () {
// Create toolbar wxSystemOptions::SetOption("msw.remap", 0);
wxSystemOptions::SetOption(_T("msw.remap"), 0); Toolbar = CreateToolBar(wxTB_FLAT | wxTB_HORIZONTAL,-1,"Toolbar");
Toolbar = CreateToolBar(wxTB_FLAT | wxTB_HORIZONTAL,-1,_T("Toolbar"));
toolbar::toolbar->GetToolbar("main", Toolbar); toolbar::toolbar->GetToolbar("main", Toolbar);
wxArrayString choices; wxArrayString choices;
for (int i=1;i<=24;i++) { for (int i=1;i<=24;i++) {
wxString toAdd = wxString::Format(_T("%i"),int(i*12.5)); wxString toAdd = wxString::Format("%i",int(i*12.5));
if (i%2) toAdd += _T(".5"); if (i%2) toAdd += ".5";
toAdd += _T("%"); toAdd += "%";
choices.Add(toAdd); choices.Add(toAdd);
} }
ZoomBox = new wxComboBox(Toolbar,ID_TOOLBAR_ZOOM_DROPDOWN,_T("75%"),wxDefaultPosition,wxDefaultSize,choices,wxCB_DROPDOWN); ZoomBox = new wxComboBox(Toolbar,ID_TOOLBAR_ZOOM_DROPDOWN,"75%",wxDefaultPosition,wxDefaultSize,choices,wxCB_DROPDOWN);
Toolbar->AddControl(ZoomBox); Toolbar->AddControl(ZoomBox);
Toolbar->AddSeparator(); Toolbar->AddSeparator();
// Update
Toolbar->Realize(); Toolbar->Realize();
} }
/// @brief Initialize menu bar
void FrameMain::InitMenu() { void FrameMain::InitMenu() {
#ifdef __WXMAC__ #ifdef __WXMAC__
@ -282,8 +281,6 @@ void FrameMain::InitMenu() {
SetMenuBar(menu::menu->GetMainMenu()); SetMenuBar(menu::menu->GetMainMenu());
} }
/// @brief Initialize contents
void FrameMain::InitContents() { void FrameMain::InitContents() {
StartupLog("Create background panel"); StartupLog("Create background panel");
Panel = new wxPanel(this,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL | wxCLIP_CHILDREN); Panel = new wxPanel(this,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL | wxCLIP_CHILDREN);
@ -334,23 +331,10 @@ void FrameMain::InitContents() {
StartupLog("Leaving InitContents"); StartupLog("Leaving InitContents");
} }
/// @brief Deinitialize controls
void FrameMain::DeInitContents() {
if (context->detachedVideo) context->detachedVideo->Destroy();
if (context->stylingAssistant) context->stylingAssistant->Destroy();
SubsGrid->ClearMaps();
delete audioBox;
delete EditBox;
delete videoBox;
delete context->ass;
HelpButton::ClearPages();
}
static void validate_toolbar(wxToolBar *toolbar, const char *command, const agi::Context *context) { static void validate_toolbar(wxToolBar *toolbar, const char *command, const agi::Context *context) {
toolbar->FindById(cmd::id(command))->Enable(cmd::get(command)->Validate(context)); toolbar->FindById(cmd::id(command))->Enable(cmd::get(command)->Validate(context));
} }
/// @brief Update toolbar
void FrameMain::UpdateToolbar() { void FrameMain::UpdateToolbar() {
wxToolBar* toolbar = GetToolBar(); wxToolBar* toolbar = GetToolBar();
const agi::Context *c = context.get(); const agi::Context *c = context.get();
@ -372,9 +356,6 @@ void FrameMain::UpdateToolbar() {
toolbar->Realize(); toolbar->Realize();
} }
/// @brief Open subtitles
/// @param filename
/// @param charset
void FrameMain::LoadSubtitles(wxString filename,wxString charset) { void FrameMain::LoadSubtitles(wxString filename,wxString charset) {
if (context->ass->loaded) { if (context->ass->loaded) {
if (TryToCloseSubs() == wxCANCEL) return; if (TryToCloseSubs() == wxCANCEL) return;
@ -385,7 +366,7 @@ void FrameMain::LoadSubtitles(wxString filename,wxString charset) {
try { try {
TextFileReader testSubs(filename,charset); TextFileReader testSubs(filename,charset);
wxString cur = testSubs.ReadLineFromFile(); wxString cur = testSubs.ReadLineFromFile();
if (cur.Left(10) == _T("# timecode")) { if (cur.Left(10) == "# timecode") {
context->videoController->LoadTimecodes(filename); context->videoController->LoadTimecodes(filename);
return; return;
} }
@ -398,27 +379,24 @@ void FrameMain::LoadSubtitles(wxString filename,wxString charset) {
context->ass->Load(filename,charset); context->ass->Load(filename,charset);
} }
catch (agi::acs::AcsNotFound const&) { catch (agi::acs::AcsNotFound const&) {
wxMessageBox(filename + L" not found.", L"Error", wxOK | wxICON_ERROR, NULL); wxMessageBox(filename + " not found.", "Error", wxOK | wxICON_ERROR, NULL);
config::mru->Remove("Subtitle", STD_STR(filename)); config::mru->Remove("Subtitle", STD_STR(filename));
return; return;
} }
catch (const wchar_t *err) { catch (const wchar_t *err) {
wxMessageBox(wxString(err), _T("Error"), wxOK | wxICON_ERROR, NULL); wxMessageBox(wxString(err), "Error", wxOK | wxICON_ERROR, NULL);
return; return;
} }
catch (wxString err) { catch (wxString err) {
wxMessageBox(err, _T("Error"), wxOK | wxICON_ERROR, NULL); wxMessageBox(err, "Error", wxOK | wxICON_ERROR, NULL);
return; return;
} }
catch (...) { catch (...) {
wxMessageBox(_T("Unknown error"), _T("Error"), wxOK | wxICON_ERROR, NULL); wxMessageBox("Unknown error", "Error", wxOK | wxICON_ERROR, NULL);
return; return;
} }
} }
/// @brief Try to close subtitles
/// @param enableCancel
/// @return
int FrameMain::TryToCloseSubs(bool enableCancel) { int FrameMain::TryToCloseSubs(bool enableCancel) {
if (context->ass->IsModified()) { if (context->ass->IsModified()) {
int flags = wxYES_NO; int flags = wxYES_NO;
@ -436,9 +414,6 @@ int FrameMain::TryToCloseSubs(bool enableCancel) {
} }
} }
/// @brief Set the video and audio display visibilty
/// @param video -1: leave unchanged; 0: hide; 1: show
/// @param audio -1: leave unchanged; 0: hide; 1: show
void FrameMain::SetDisplayMode(int video, int audio) { void FrameMain::SetDisplayMode(int video, int audio) {
if (!IsShownOnScreen()) return; if (!IsShownOnScreen()) return;
@ -461,11 +436,9 @@ void FrameMain::SetDisplayMode(int video, int audio) {
context->videoController->Stop(); context->videoController->Stop();
// Set display
TopSizer->Show(videoBox, showVideo, true); TopSizer->Show(videoBox, showVideo, true);
ToolsSizer->Show(audioSash, showAudio, true); ToolsSizer->Show(audioSash, showAudio, true);
// Update
UpdateToolbar(); UpdateToolbar();
MainSizer->CalcMin(); MainSizer->CalcMin();
MainSizer->RecalcSizes(); MainSizer->RecalcSizes();
@ -475,10 +448,9 @@ void FrameMain::SetDisplayMode(int video, int audio) {
if (didFreeze) Thaw(); if (didFreeze) Thaw();
} }
/// @brief Update title bar
void FrameMain::UpdateTitle() { void FrameMain::UpdateTitle() {
wxString newTitle; wxString newTitle;
if (context->ass->IsModified()) newTitle << _T("* "); if (context->ass->IsModified()) newTitle << "* ";
if (context->ass->filename.empty()) { if (context->ass->filename.empty()) {
// Apple HIG says "untitled" should not be capitalised // Apple HIG says "untitled" should not be capitalised
// and the window is a document window, it shouldn't contain the app name // and the window is a document window, it shouldn't contain the app name
@ -563,8 +535,6 @@ void FrameMain::LoadVFR(wxString filename) {
} }
} }
/// @brief Detach video window
/// @param detach
void FrameMain::DetachVideo(bool detach) { void FrameMain::DetachVideo(bool detach) {
if (detach) { if (detach) {
if (!context->detachedVideo) { if (!context->detachedVideo) {
@ -580,21 +550,13 @@ void FrameMain::DetachVideo(bool detach) {
UpdateToolbar(); UpdateToolbar();
} }
/// @brief Sets status and clear after n milliseconds
/// @param text
/// @param ms
void FrameMain::StatusTimeout(wxString text,int ms) { void FrameMain::StatusTimeout(wxString text,int ms) {
SetStatusText(text,1); SetStatusText(text,1);
StatusClear.SetOwner(this, ID_APP_TIMER_STATUSCLEAR); StatusClear.SetOwner(this, ID_APP_TIMER_STATUSCLEAR);
StatusClear.Start(ms,true); StatusClear.Start(ms,true);
} }
/// @brief Load list of files
/// @param list
/// @return
bool FrameMain::LoadList(wxArrayString list) { bool FrameMain::LoadList(wxArrayString list) {
// Build list
wxArrayString List; wxArrayString List;
for (size_t i=0;i<list.Count();i++) { for (size_t i=0;i<list.Count();i++) {
wxFileName file(list[i]); wxFileName file(list[i]);
@ -604,43 +566,43 @@ bool FrameMain::LoadList(wxArrayString list) {
// Video formats // Video formats
wxArrayString videoList; wxArrayString videoList;
videoList.Add(_T("avi")); videoList.Add("avi");
videoList.Add(_T("mkv")); videoList.Add("mkv");
videoList.Add(_T("mp4")); videoList.Add("mp4");
videoList.Add(_T("d2v")); videoList.Add("d2v");
videoList.Add(_T("mpg")); videoList.Add("mpg");
videoList.Add(_T("mpeg")); videoList.Add("mpeg");
videoList.Add(_T("ogm")); videoList.Add("ogm");
videoList.Add(_T("avs")); videoList.Add("avs");
videoList.Add(_T("wmv")); videoList.Add("wmv");
videoList.Add(_T("asf")); videoList.Add("asf");
videoList.Add(_T("mov")); videoList.Add("mov");
videoList.Add(_T("rm")); videoList.Add("rm");
videoList.Add(_T("y4m")); videoList.Add("y4m");
videoList.Add(_T("yuv")); videoList.Add("yuv");
// Subtitle formats // Subtitle formats
wxArrayString subsList; wxArrayString subsList;
subsList.Add(_T("ass")); subsList.Add("ass");
subsList.Add(_T("ssa")); subsList.Add("ssa");
subsList.Add(_T("srt")); subsList.Add("srt");
subsList.Add(_T("sub")); subsList.Add("sub");
subsList.Add(_T("txt")); subsList.Add("txt");
subsList.Add(_T("ttxt")); subsList.Add("ttxt");
// Audio formats // Audio formats
wxArrayString audioList; wxArrayString audioList;
audioList.Add(_T("wav")); audioList.Add("wav");
audioList.Add(_T("mp3")); audioList.Add("mp3");
audioList.Add(_T("ogg")); audioList.Add("ogg");
audioList.Add(_T("wma")); audioList.Add("wma");
audioList.Add(_T("ac3")); audioList.Add("ac3");
audioList.Add(_T("aac")); audioList.Add("aac");
audioList.Add(_T("mpc")); audioList.Add("mpc");
audioList.Add(_T("ape")); audioList.Add("ape");
audioList.Add(_T("flac")); audioList.Add("flac");
audioList.Add(_T("mka")); audioList.Add("mka");
audioList.Add(_T("m4a")); audioList.Add("m4a");
// Scan list // Scan list
wxString audio; wxString audio;
@ -656,7 +618,6 @@ bool FrameMain::LoadList(wxArrayString list) {
if (audio.empty() && audioList.Index(ext) != wxNOT_FOUND) audio = List[i]; if (audio.empty() && audioList.Index(ext) != wxNOT_FOUND) audio = List[i];
} }
// Set blocking
blockVideoLoad = !video.empty(); blockVideoLoad = !video.empty();
// Load files // Load files
@ -670,14 +631,12 @@ bool FrameMain::LoadList(wxArrayString list) {
if (!audio.empty()) if (!audio.empty())
context->audioController->OpenAudio(audio); context->audioController->OpenAudio(audio);
// Result
return subs.size() || audio.size() || video.size(); return subs.size() || audio.size() || video.size();
} }
/// @brief Check if ASSDraw is available
bool FrameMain::HasASSDraw() { bool FrameMain::HasASSDraw() {
#ifdef __WINDOWS__ #ifdef __WINDOWS__
wxFileName fn(StandardPaths::DecodePath(_T("?data/ASSDraw3.exe"))); wxFileName fn(StandardPaths::DecodePath("?data/ASSDraw3.exe"));
return fn.FileExists(); return fn.FileExists();
#else #else
return false; return false;
@ -704,19 +663,12 @@ BEGIN_EVENT_TABLE(FrameMain, wxFrame)
EVT_MENU_OPEN(FrameMain::OnMenuOpen) EVT_MENU_OPEN(FrameMain::OnMenuOpen)
EVT_KEY_DOWN(FrameMain::OnKeyDown) EVT_KEY_DOWN(FrameMain::OnKeyDown)
// EVT_COMBOBOX(Toolbar_Zoom_Dropdown, FrameMain::OnSetZoom)
// EVT_TEXT_ENTER(Toolbar_Zoom_Dropdown, FrameMain::OnSetZoom)
#ifdef __WXMAC__ #ifdef __WXMAC__
// EVT_MENU(wxID_ABOUT, FrameMain::OnAbout) // EVT_MENU(wxID_ABOUT, FrameMain::OnAbout)
// EVT_MENU(wxID_EXIT, FrameMain::OnExit) // EVT_MENU(wxID_EXIT, FrameMain::OnExit)
#endif #endif
END_EVENT_TABLE() END_EVENT_TABLE()
/// @brief Rebuild recent list
/// @param listName
/// @param menu
/// @param startID
void FrameMain::RebuildRecentList(const char *root_command, const char *mru_name) { void FrameMain::RebuildRecentList(const char *root_command, const char *mru_name) {
wxMenu *menu = menu::menu->GetMenu(root_command); wxMenu *menu = menu::menu->GetMenu(root_command);
@ -750,10 +702,7 @@ static void validate(wxMenuBar *menu, const agi::Context *c, const char *command
menu->Enable(cmd::id(command), cmd::get(command)->Validate(c)); menu->Enable(cmd::id(command), cmd::get(command)->Validate(c));
} }
/// @brief Menu is being opened
/// @param event
void FrameMain::OnMenuOpen (wxMenuEvent &event) { void FrameMain::OnMenuOpen (wxMenuEvent &event) {
// Get menu
wxMenuBar *MenuBar = menu::menu->GetMainMenu(); wxMenuBar *MenuBar = menu::menu->GetMainMenu();
MenuBar->Freeze(); MenuBar->Freeze();
@ -767,7 +716,6 @@ void FrameMain::OnMenuOpen (wxMenuEvent &event) {
// View menu // View menu
else if (curMenu == menu::menu->GetMenu("main/view")) { else if (curMenu == menu::menu->GetMenu("main/view")) {
// Select option
if (!showVideo && !showAudio) MenuBar->Check(cmd::id("app/display/subs"),true); if (!showVideo && !showAudio) MenuBar->Check(cmd::id("app/display/subs"),true);
else if (showVideo && !showAudio) MenuBar->Check(cmd::id("app/display/video_subs"),true); else if (showVideo && !showAudio) MenuBar->Check(cmd::id("app/display/video_subs"),true);
else if (showAudio && showVideo) MenuBar->Check(cmd::id("app/display/full"),true); else if (showAudio && showVideo) MenuBar->Check(cmd::id("app/display/full"),true);
@ -785,7 +733,6 @@ void FrameMain::OnMenuOpen (wxMenuEvent &event) {
validate(MenuBar, context.get(), "keyframe/close"); validate(MenuBar, context.get(), "keyframe/close");
validate(MenuBar, context.get(), "keyframe/save"); validate(MenuBar, context.get(), "keyframe/save");
// Set AR radio
int arType = context->videoController->GetAspectRatioType(); int arType = context->videoController->GetAspectRatioType();
MenuBar->Check(cmd::id("video/aspect/default"),false); MenuBar->Check(cmd::id("video/aspect/default"),false);
MenuBar->Check(cmd::id("video/aspect/full"),false); MenuBar->Check(cmd::id("video/aspect/full"),false);
@ -800,10 +747,8 @@ void FrameMain::OnMenuOpen (wxMenuEvent &event) {
case 4: MenuBar->Check(cmd::id("video/aspect/custom"),true); break; case 4: MenuBar->Check(cmd::id("video/aspect/custom"),true); break;
} }
// Set overscan mask
MenuBar->Check(cmd::id("video/show_overscan"),OPT_GET("Video/Overscan Mask")->GetBool()); MenuBar->Check(cmd::id("video/show_overscan"),OPT_GET("Video/Overscan Mask")->GetBool());
// Rebuild recent lists
RebuildRecentList("recent/video", "Video"); RebuildRecentList("recent/video", "Video");
RebuildRecentList("recent/timecode", "Timecodes"); RebuildRecentList("recent/timecode", "Timecodes");
RebuildRecentList("recent/keyframe", "Keyframes"); RebuildRecentList("recent/keyframe", "Keyframes");
@ -898,10 +843,6 @@ void FrameMain::OnMenuOpen (wxMenuEvent &event) {
MenuBar->Thaw(); MenuBar->Thaw();
} }
/// @brief Macro menu creation helper
/// @param menu
/// @param macros
/// @return
int FrameMain::AddMacroMenuItems(wxMenu *menu, const std::vector<Automation4::FeatureMacro*> &macros) { int FrameMain::AddMacroMenuItems(wxMenu *menu, const std::vector<Automation4::FeatureMacro*> &macros) {
#ifdef WITH_AUTOMATION #ifdef WITH_AUTOMATION
if (macros.empty()) { if (macros.empty()) {
@ -922,8 +863,6 @@ int FrameMain::AddMacroMenuItems(wxMenu *menu, const std::vector<Automation4::Fe
#endif #endif
} }
/// @brief General handler for all Automation-generated menu items
/// @param event
void FrameMain::OnAutomationMacro (wxCommandEvent &event) { void FrameMain::OnAutomationMacro (wxCommandEvent &event) {
#ifdef WITH_AUTOMATION #ifdef WITH_AUTOMATION
SubsGrid->BeginBatch(); SubsGrid->BeginBatch();
@ -937,9 +876,6 @@ void FrameMain::OnAutomationMacro (wxCommandEvent &event) {
#endif #endif
} }
/// @brief Window is attempted to be closed
/// @param event
void FrameMain::OnCloseWindow (wxCloseEvent &event) { void FrameMain::OnCloseWindow (wxCloseEvent &event) {
// Stop audio and video // Stop audio and video
context->videoController->Stop(); context->videoController->Stop();
@ -960,54 +896,47 @@ void FrameMain::OnCloseWindow (wxCloseEvent &event) {
else Destroy(); else Destroy();
} }
/// @brief Autosave the currently open file, if any void FrameMain::OnAutoSave(wxTimerEvent &) try {
void FrameMain::OnAutoSave(wxTimerEvent &) {
try {
if (context->ass->loaded && context->ass->IsModified()) { if (context->ass->loaded && context->ass->IsModified()) {
// Set path
wxFileName origfile(context->ass->filename); wxFileName origfile(context->ass->filename);
wxString path = lagi_wxString(OPT_GET("Path/Auto/Save")->GetString()); wxString path = lagi_wxString(OPT_GET("Path/Auto/Save")->GetString());
if (path.IsEmpty()) path = origfile.GetPath(); if (path.IsEmpty()) path = origfile.GetPath();
wxFileName dstpath(path); wxFileName dstpath(path);
if (!dstpath.IsAbsolute()) path = StandardPaths::DecodePathMaybeRelative(path, _T("?user/")); if (!dstpath.IsAbsolute()) path = StandardPaths::DecodePathMaybeRelative(path, "?user/");
dstpath.AssignDir(path); dstpath.AssignDir(path);
if (!dstpath.DirExists()) wxMkdir(path); if (!dstpath.DirExists()) wxMkdir(path);
wxString name = origfile.GetName(); wxString name = origfile.GetName();
if (name.IsEmpty()) { if (name.empty()) {
dstpath.SetFullName("Untitled.AUTOSAVE.ass"); dstpath.SetFullName("Untitled.AUTOSAVE.ass");
} }
else { else {
dstpath.SetFullName(name + L".AUTOSAVE.ass"); dstpath.SetFullName(name + ".AUTOSAVE.ass");
} }
context->ass->Save(dstpath.GetFullPath(),false,false); context->ass->Save(dstpath.GetFullPath(),false,false);
// Set status bar StatusTimeout(_("File backup saved as \"") + dstpath.GetFullPath() + "\".");
StatusTimeout(_("File backup saved as \"") + dstpath.GetFullPath() + _T("\"."));
} }
} }
catch (const agi::Exception& err) { catch (const agi::Exception& err) {
StatusTimeout(lagi_wxString("Exception when attempting to autosave file: " + err.GetMessage())); StatusTimeout(lagi_wxString("Exception when attempting to autosave file: " + err.GetMessage()));
} }
catch (wxString err) { catch (wxString err) {
StatusTimeout(_T("Exception when attempting to autosave file: ") + err); StatusTimeout("Exception when attempting to autosave file: " + err);
} }
catch (const wchar_t *err) { catch (const wchar_t *err) {
StatusTimeout(_T("Exception when attempting to autosave file: ") + wxString(err)); StatusTimeout("Exception when attempting to autosave file: " + wxString(err));
} }
catch (...) { catch (...) {
StatusTimeout(_T("Unhandled exception when attempting to autosave file.")); StatusTimeout("Unhandled exception when attempting to autosave file.");
}
} }
/// @brief Clear statusbar
void FrameMain::OnStatusClear(wxTimerEvent &) { void FrameMain::OnStatusClear(wxTimerEvent &) {
SetStatusText(_T(""),1); SetStatusText("",1);
} }
void FrameMain::OnAudioBoxResize(wxSashEvent &event) void FrameMain::OnAudioBoxResize(wxSashEvent &event) {
{
if (event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE) if (event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE)
return; return;
@ -1021,13 +950,11 @@ void FrameMain::OnAudioBoxResize(wxSashEvent &event)
Refresh(); Refresh();
} }
void FrameMain::OnAudioOpen(AudioProvider *provider) void FrameMain::OnAudioOpen(AudioProvider *provider) {
{
SetDisplayMode(-1, 1); SetDisplayMode(-1, 1);
} }
void FrameMain::OnAudioClose() void FrameMain::OnAudioClose() {
{
SetDisplayMode(-1, 0); SetDisplayMode(-1, 0);
} }
@ -1103,7 +1030,7 @@ void FrameMain::OnSubtitlesOpen() {
// Automation scripts // Automation scripts
#ifdef WITH_AUTOMATION #ifdef WITH_AUTOMATION
context->local_scripts->RemoveAll(); context->local_scripts->RemoveAll();
wxStringTokenizer tok(AutoScriptString, _T("|"), wxTOKEN_STRTOK); wxStringTokenizer tok(AutoScriptString, "|", wxTOKEN_STRTOK);
wxFileName assfn(context->ass->filename); wxFileName assfn(context->ass->filename);
wxString autobasefn(lagi_wxString(OPT_GET("Path/Automation/Base")->GetString())); wxString autobasefn(lagi_wxString(OPT_GET("Path/Automation/Base")->GetString()));
while (tok.HasMoreTokens()) { while (tok.HasMoreTokens()) {
@ -1111,14 +1038,14 @@ void FrameMain::OnSubtitlesOpen() {
wxString sfnamel = sfnames.Left(1); wxString sfnamel = sfnames.Left(1);
sfnames.Remove(0, 1); sfnames.Remove(0, 1);
wxString basepath; wxString basepath;
if (sfnamel == _T("~")) { if (sfnamel == "~") {
basepath = assfn.GetPath(); basepath = assfn.GetPath();
} else if (sfnamel == _T("$")) { } else if (sfnamel == "$") {
basepath = autobasefn; basepath = autobasefn;
} else if (sfnamel == _T("/")) { } else if (sfnamel == "/") {
basepath = _T(""); basepath = "";
} else { } else {
wxLogWarning(_T("Automation Script referenced with unknown location specifier character.\nLocation specifier found: %s\nFilename specified: %s"), wxLogWarning("Automation Script referenced with unknown location specifier character.\nLocation specifier found: %s\nFilename specified: %s",
sfnamel.c_str(), sfnames.c_str()); sfnamel.c_str(), sfnames.c_str());
continue; continue;
} }
@ -1128,7 +1055,7 @@ void FrameMain::OnSubtitlesOpen() {
sfnames = sfname.GetFullPath(); sfnames = sfname.GetFullPath();
context->local_scripts->Add(Automation4::ScriptFactory::CreateFromFile(sfnames, true)); context->local_scripts->Add(Automation4::ScriptFactory::CreateFromFile(sfnames, true));
} else { } else {
wxLogWarning(_T("Automation Script referenced could not be found.\nFilename specified: %s%s\nSearched relative to: %s\nResolved filename: %s"), wxLogWarning("Automation Script referenced could not be found.\nFilename specified: %s%s\nSearched relative to: %s\nResolved filename: %s",
sfnamel.c_str(), sfnames.c_str(), basepath.c_str(), sfname.GetFullPath().c_str()); sfnamel.c_str(), sfnames.c_str(), basepath.c_str(), sfname.GetFullPath().c_str());
} }
} }
@ -1157,7 +1084,7 @@ void FrameMain::OnSubtitlesSave() {
Automation4::Script *script = scripts[i]; Automation4::Script *script = scripts[i];
if (i != 0) if (i != 0)
scripts_string += _T("|"); scripts_string += "|";
wxString autobase_rel, assfile_rel; wxString autobase_rel, assfile_rel;
wxString scriptfn(script->GetFilename()); wxString scriptfn(script->GetFilename());
@ -1165,22 +1092,20 @@ void FrameMain::OnSubtitlesSave() {
assfile_rel = MakeRelativePath(scriptfn, context->ass->filename); assfile_rel = MakeRelativePath(scriptfn, context->ass->filename);
if (autobase_rel.size() <= scriptfn.size() && autobase_rel.size() <= assfile_rel.size()) { if (autobase_rel.size() <= scriptfn.size() && autobase_rel.size() <= assfile_rel.size()) {
scriptfn = _T("$") + autobase_rel; scriptfn = "$" + autobase_rel;
} else if (assfile_rel.size() <= scriptfn.size() && assfile_rel.size() <= autobase_rel.size()) { } else if (assfile_rel.size() <= scriptfn.size() && assfile_rel.size() <= autobase_rel.size()) {
scriptfn = _T("~") + assfile_rel; scriptfn = "~" + assfile_rel;
} else { } else {
scriptfn = _T("/") + wxFileName(scriptfn).GetFullPath(wxPATH_UNIX); scriptfn = "/" + wxFileName(scriptfn).GetFullPath(wxPATH_UNIX);
} }
scripts_string += scriptfn; scripts_string += scriptfn;
} }
context->ass->SetScriptInfo(_T("Automation Scripts"), scripts_string); context->ass->SetScriptInfo("Automation Scripts", scripts_string);
#endif #endif
} }
void FrameMain::OnKeyDown(wxKeyEvent &event) { void FrameMain::OnKeyDown(wxKeyEvent &event) {
if (!hotkey::check("Main Frame", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) if (!hotkey::check("Main Frame", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers()))
event.Skip(); event.Skip();
} }

View File

@ -49,32 +49,23 @@
#include <libaegisub/scoped_ptr.h> #include <libaegisub/scoped_ptr.h>
class AegisubFileDropTarget;
class AssFile; class AssFile;
class AudioBox;
class AudioController;
class AudioProvider;
class DialogDetachedVideo;
class DialogStyling;
class SubsEditBox;
class SubtitlesGrid;
class VideoBox;
class VideoDisplay; class VideoDisplay;
class VideoSlider; class VideoSlider;
class VideoZoomSlider; class VideoZoomSlider;
class SubtitlesGrid;
class SubsEditBox;
class AudioBox;
class VideoBox;
class DialogDetachedVideo;
class DialogStyling;
class AegisubFileDropTarget;
class AudioController;
class AudioProvider;
namespace agi { struct Context; } namespace agi { struct Context; }
namespace Automation4 { class FeatureMacro; class ScriptManager; } namespace Automation4 { class FeatureMacro; class ScriptManager; }
enum SubMenuID {
ID_TOOLBAR_ZOOM_DROPDOWN = 11001,
ID_APP_TIMER_AUTOSAVE = 12001,
ID_APP_TIMER_STATUSCLEAR = 12002,
ID_MENU_AUTOMATION_MACRO = 13006,
ID_SASH_MAIN_AUDIO = 14001
};
/// DOCME /// DOCME
/// @class FrameMain /// @class FrameMain
/// @brief DOCME /// @brief DOCME
@ -84,8 +75,14 @@ class FrameMain: public wxFrame {
friend class AegisubFileDropTarget; friend class AegisubFileDropTarget;
public: public:
/// Set the status bar text
/// @param text New status bar text
/// @param ms Time in milliseconds that the message should be visible
void StatusTimeout(wxString text,int ms=10000); void StatusTimeout(wxString text,int ms=10000);
void SetDisplayMode(int showVid,int showAudio); /// @brief Set the video and audio display visibility
/// @param video -1: leave unchanged; 0: hide; 1: show
/// @param audio -1: leave unchanged; 0: hide; 1: show
void SetDisplayMode(int showVid, int showAudio);
void LoadSubtitles(wxString filename,wxString charset=""); void LoadSubtitles(wxString filename,wxString charset="");
void DetachVideo(bool detach=true); void DetachVideo(bool detach=true);
void LoadVFR(wxString filename); void LoadVFR(wxString filename);
@ -100,53 +97,42 @@ private:
#endif #endif
void cmd_call(wxCommandEvent& event); void cmd_call(wxCommandEvent& event);
/// DOCME bool showVideo; ///< Is the video display shown?
bool showAudio; ///< Is the audio display shown?
/// DOCME wxTimer AutoSave; ///< Autosave timer
bool showVideo,showAudio; wxTimer StatusClear; ///< Status bar timeout timer
/// Block video loading; used when both video and subtitles are opened at
/// DOCME /// the same time, so that the video associated with the subtitles (if any)
wxTimer AutoSave; /// isn't loaded
/// DOCME
wxTimer StatusClear;
/// DOCME
bool blockVideoLoad; bool blockVideoLoad;
/// DOCME
wxPanel *Panel; wxPanel *Panel;
wxToolBar *Toolbar; ///< The main toolbar
/// DOCME wxComboBox *ZoomBox; ///< The video zoom dropdown in the main toolbar
wxToolBar *Toolbar;
/// DOCME
wxComboBox *ZoomBox;
/// DOCME
std::vector<Automation4::FeatureMacro*> activeMacroItems; std::vector<Automation4::FeatureMacro*> activeMacroItems;
int AddMacroMenuItems(wxMenu *menu, const std::vector<Automation4::FeatureMacro*> &macros); int AddMacroMenuItems(wxMenu *menu, const std::vector<Automation4::FeatureMacro*> &macros);
void InitToolbar(); void InitToolbar();
void InitContents(); void InitContents();
void DeInitContents(); void InitMenu();
bool LoadList(wxArrayString list); bool LoadList(wxArrayString list);
void UpdateTitle(); void UpdateTitle();
void InitMenu();
void OnKeyDown(wxKeyEvent &event); void OnKeyDown(wxKeyEvent &event);
void OnMenuOpen (wxMenuEvent &event); void OnMenuOpen (wxMenuEvent &event);
void OnAudioBoxResize(wxSashEvent &event); void OnAudioBoxResize(wxSashEvent &event);
/// @brief Autosave the currently open file, if any
void OnAutoSave(wxTimerEvent &event); void OnAutoSave(wxTimerEvent &event);
void OnStatusClear(wxTimerEvent &event); void OnStatusClear(wxTimerEvent &event);
void OnCloseWindow (wxCloseEvent &event); void OnCloseWindow (wxCloseEvent &event);
/// @brief General handler for all Automation-generated menu items
void OnAutomationMacro(wxCommandEvent &event); void OnAutomationMacro(wxCommandEvent &event);
/// Close the currently open subs, asking the user if they want to save if there are unsaved changes
/// @param enableCancel Should the user be able to cancel the close?
int TryToCloseSubs(bool enableCancel=true); int TryToCloseSubs(bool enableCancel=true);
void RebuildRecentList(const char *root_command, const char *mru_name); void RebuildRecentList(const char *root_command, const char *mru_name);
@ -161,29 +147,15 @@ private:
void OnSubtitlesSave(); void OnSubtitlesSave();
/// The subtitle editing area SubtitlesGrid *SubsGrid; ///< The subtitle editing area
SubtitlesGrid *SubsGrid; SubsEditBox *EditBox; ///< The subtitle editing textbox
wxSashWindow *audioSash; ///< Sash for resizing the audio area
AudioBox *audioBox; ///< The audio area
VideoBox *videoBox; ///< The video area
/// The subtitle editing textbox wxBoxSizer *MainSizer; ///< Arranges things from top to bottom in the window
SubsEditBox *EditBox; wxBoxSizer *TopSizer; ///< Arranges video box and tool box from left to right
wxBoxSizer *ToolsSizer; ///< Arranges audio and editing areas top to bottom
/// Sash for resizing the audio area
wxSashWindow *audioSash;
/// The audio area
AudioBox *audioBox;
/// The video area
VideoBox *videoBox;
/// Arranges things from top to bottom in the window
wxBoxSizer *MainSizer;
/// Arranges video box and tool box from left to right
wxBoxSizer *TopSizer;
/// Arranges audio and editing areas top to bottom
wxBoxSizer *ToolsSizer;
public: public:
FrameMain(wxArrayString args); FrameMain(wxArrayString args);