Add a subtitle open signal and move most of the logic in FrameMain::LoadSubtitles to slots for this signal.

Originally committed to SVN as r5206.
This commit is contained in:
Thomas Goyne 2011-01-16 07:16:33 +00:00
parent 314a07c9ab
commit 59300cbc27
7 changed files with 257 additions and 269 deletions

View file

@ -54,6 +54,7 @@
#include "charset_detect.h" #include "charset_detect.h"
#include "compat.h" #include "compat.h"
#include "main.h" #include "main.h"
#include "standard_paths.h"
#include "subtitle_format.h" #include "subtitle_format.h"
#include "text_file_reader.h" #include "text_file_reader.h"
#include "text_file_writer.h" #include "text_file_writer.h"
@ -128,6 +129,30 @@ void AssFile::Load(const wxString &_filename,wxString charset,bool addToRecent)
// Set general data // Set general data
loaded = true; loaded = true;
filename = _filename; filename = _filename;
wxFileName fn(filename);
StandardPaths::SetPathValue("?script", fn.GetPath());
// Save backup of file
if (CanSave() && OPT_GET("App/Auto/Backup")->GetBool()) {
wxFileName file(filename);
if (file.FileExists()) {
wxString path = lagi_wxString(OPT_GET("Path/Auto/Backup")->GetString());
if (path.empty()) path = file.GetPath();
wxFileName dstpath(path);
if (!dstpath.IsAbsolute())
path = StandardPaths::DecodePathMaybeRelative(path, "?user/");
path += "/";
dstpath.Assign(path);
if (!dstpath.DirExists()) {
wxMkdir(path);
}
wxString backup = path + file.GetName() + ".ORIGINAL." + file.GetExt();
wxCopyFile(file.GetFullPath(), backup, true);
}
}
// Add comments and set vars // Add comments and set vars
AddComment(_T("Script generated by Aegisub ") + GetAegisubLongVersionString()); AddComment(_T("Script generated by Aegisub ") + GetAegisubLongVersionString());
@ -143,7 +168,8 @@ void AssFile::Load(const wxString &_filename,wxString charset,bool addToRecent)
Commit(""); Commit("");
// Add to recent // Add to recent
if (addToRecent) AddToRecent(_filename); if (addToRecent) AddToRecent(filename);
FileOpen(filename);
} }
void AssFile::Save(wxString _filename,bool setfilename,bool addToRecent,const wxString encoding) { void AssFile::Save(wxString _filename,bool setfilename,bool addToRecent,const wxString encoding) {
@ -426,7 +452,7 @@ void AssFile::Clear() {
savedCommitId = 0; savedCommitId = 0;
} }
void AssFile::LoadDefault (bool defline) { void AssFile::LoadDefault(bool defline) {
Clear(); Clear();
// Write headers // Write headers
@ -455,6 +481,8 @@ void AssFile::LoadDefault (bool defline) {
Commit(""); Commit("");
savedCommitId = commitId; savedCommitId = commitId;
loaded = true; loaded = true;
StandardPaths::SetPathValue("?script", "");
FileOpen("");
} }
void AssFile::swap(AssFile &that) throw() { void AssFile::swap(AssFile &that) throw() {

View file

@ -73,6 +73,8 @@ class AssFile {
int savedCommitId; int savedCommitId;
agi::signal::Signal<int> AnnounceCommit; agi::signal::Signal<int> AnnounceCommit;
agi::signal::Signal<wxString> FileOpen;
agi::signal::Signal<> FileSave;
public: public:
/// The lines in the file /// The lines in the file
@ -169,6 +171,8 @@ public:
}; };
DEFINE_SIGNAL_ADDERS(AnnounceCommit, AddCommitListener) DEFINE_SIGNAL_ADDERS(AnnounceCommit, AddCommitListener)
DEFINE_SIGNAL_ADDERS(FileOpen, AddFileOpenListener)
DEFINE_SIGNAL_ADDERS(FileSave, AddFileSaveListener)
/// @brief Flag the file as modified and push a copy onto the undo stack /// @brief Flag the file as modified and push a copy onto the undo stack
/// @param desc Undo description /// @param desc Undo description

View file

@ -231,7 +231,7 @@ struct subtitle_new : public Command {
STR_HELP("New subtitles.") STR_HELP("New subtitles.")
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
wxGetApp().frame->LoadSubtitles(_T("")); c->SubsGrid->LoadDefault();
} }
}; };
@ -248,8 +248,6 @@ struct subtitle_open : public Command {
wxString filename = wxFileSelector(_("Open subtitles file"),path,_T(""),_T(""),AssFile::GetWildcardList(0),wxFD_OPEN | wxFD_FILE_MUST_EXIST); wxString filename = wxFileSelector(_("Open subtitles file"),path,_T(""),_T(""),AssFile::GetWildcardList(0),wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (!filename.empty()) { if (!filename.empty()) {
wxGetApp().frame->LoadSubtitles(filename); wxGetApp().frame->LoadSubtitles(filename);
wxFileName filepath(filename);
OPT_SET("Path/Last/Subtitles")->SetString(STD_STR(filepath.GetPath()));
} }
} }
}; };
@ -273,7 +271,6 @@ struct subtitle_open_charset : public Command {
if (!charset.empty()) { if (!charset.empty()) {
wxGetApp().frame->LoadSubtitles(filename,charset); wxGetApp().frame->LoadSubtitles(filename,charset);
} }
OPT_SET("Path/Last/Subtitles")->SetString(STD_STR(filename));
} }
} }
}; };

View file

@ -45,6 +45,7 @@
#include <wx/tokenzr.h> #include <wx/tokenzr.h>
#endif #endif
#include <libaegisub/access.h>
#include <libaegisub/log.h> #include <libaegisub/log.h>
#include "include/aegisub/context.h" #include "include/aegisub/context.h"
@ -210,7 +211,7 @@ FrameMain::FrameMain (wxArrayString args)
// Parse arguments // Parse arguments
StartupLog(_T("Initialize empty file")); StartupLog(_T("Initialize empty file"));
LoadSubtitles(_T("")); SubsGrid->LoadDefault();
StartupLog(_T("Load files specified on command line")); StartupLog(_T("Load files specified on command line"));
LoadList(args); LoadList(args);
@ -298,7 +299,9 @@ void FrameMain::InitMenu() {
void FrameMain::InitContents() { void FrameMain::InitContents() {
AssFile::top = ass = new AssFile; AssFile::top = ass = new AssFile;
temp_context->ass = ass; temp_context->ass = ass;
ass->AddCommitListener(&FrameMain::OnSubtitlesFileChanged, this); ass->AddCommitListener(&FrameMain::OnSubtitlesCommit, this);
ass->AddFileOpenListener(&FrameMain::OnSubtitlesOpen, this);
ass->AddFileSaveListener(&FrameMain::UpdateTitle, this);
// Set a background panel // Set a background panel
StartupLog(_T("Create background panel")); StartupLog(_T("Create background panel"));
@ -410,59 +413,29 @@ void FrameMain::UpdateToolbar() {
/// @brief Open subtitles /// @brief Open subtitles
/// @param filename /// @param filename
/// @param charset /// @param charset
void FrameMain::LoadSubtitles (wxString filename,wxString charset) { void FrameMain::LoadSubtitles(wxString filename,wxString charset) {
// First check if there is some loaded if (ass->loaded) {
if (ass && ass->loaded) {
if (TryToCloseSubs() == wxCANCEL) return; if (TryToCloseSubs() == wxCANCEL) return;
} }
// Setup
bool isFile = !filename.empty();
// Load
try { try {
// File exists? // Make sure that file isn't actually a timecode file
if (isFile) { try {
wxFileName fileCheck(filename); TextFileReader testSubs(filename,charset);
if (!fileCheck.FileExists()) { wxString cur = testSubs.ReadLineFromFile();
throw agi::FileNotFoundError(STD_STR(filename)); if (cur.Left(10) == _T("# timecode")) {
} temp_context->videoContext->LoadTimecodes(filename);
return;
// Make sure that file isn't actually a timecode file
try {
TextFileReader testSubs(filename,charset);
wxString cur = testSubs.ReadLineFromFile();
if (cur.Left(10) == _T("# timecode")) {
LoadVFR(filename);
OPT_SET("Path/Last/Timecodes")->SetString(STD_STR(fileCheck.GetPath()));
return;
}
}
catch (...) {
// if trying to load the file as timecodes fails it's fairly
// safe to assume that it is in fact not a timecode file
} }
} }
catch (...) {
// if trying to load the file as timecodes fails it's fairly
// safe to assume that it is in fact not a timecode file
}
// Proceed into loading ass->Load(filename,charset);
SubsGrid->ClearMaps();
if (isFile) {
ass->Load(filename,charset);
if (SubsGrid->GetRows()) {
SubsGrid->SetActiveLine(SubsGrid->GetDialogue(0));
SubsGrid->SelectRow(0);
}
wxFileName fn(filename);
StandardPaths::SetPathValue(_T("?script"),fn.GetPath());
OPT_SET("Path/Last/Subtitles")->SetString(STD_STR(fn.GetPath()));
}
else {
SubsGrid->LoadDefault();
StandardPaths::SetPathValue(_T("?script"),_T(""));
}
SubsGrid->SetColumnWidths();
} }
catch (agi::FileNotFoundError const&) { catch (agi::acs::AcsNotFound const&) {
wxMessageBox(filename + L" not found.", L"Error", wxOK | wxICON_ERROR, NULL); wxMessageBox(filename + L" not found.", L"Error", wxOK | wxICON_ERROR, NULL);
config::mru->Remove("Subtitle", STD_STR(filename)); config::mru->Remove("Subtitle", STD_STR(filename));
return; return;
@ -479,29 +452,6 @@ void FrameMain::LoadSubtitles (wxString filename,wxString charset) {
wxMessageBox(_T("Unknown error"), _T("Error"), wxOK | wxICON_ERROR, NULL); wxMessageBox(_T("Unknown error"), _T("Error"), wxOK | wxICON_ERROR, NULL);
return; return;
} }
// Save copy
wxFileName origfile(filename);
if (ass->CanSave() && OPT_GET("App/Auto/Backup")->GetBool() && origfile.FileExists()) {
// Get path
wxString path = lagi_wxString(OPT_GET("Path/Auto/Backup")->GetString());
if (path.IsEmpty()) path = origfile.GetPath();
wxFileName dstpath(path);
if (!dstpath.IsAbsolute()) path = StandardPaths::DecodePathMaybeRelative(path, _T("?user/"));
path += _T("/");
dstpath.Assign(path);
if (!dstpath.DirExists()) wxMkdir(path);
// Save
wxString backup = path + origfile.GetName() + _T(".ORIGINAL.") + origfile.GetExt();
wxCopyFile(filename,backup,true);
}
// Sync
SynchronizeProject(true);
// Update title bar
UpdateTitle();
} }
/// @brief Save subtitles /// @brief Save subtitles
@ -543,7 +493,6 @@ bool FrameMain::SaveSubtitles(bool saveas,bool withCharset) {
// Save // Save
try { try {
ass->Save(filename,true,true,charset); ass->Save(filename,true,true,charset);
UpdateTitle();
} }
catch (const agi::Exception& err) { catch (const agi::Exception& err) {
wxMessageBox(lagi_wxString(err.GetMessage()), "Error", wxOK | wxICON_ERROR, NULL); wxMessageBox(lagi_wxString(err.GetMessage()), "Error", wxOK | wxICON_ERROR, NULL);
@ -621,28 +570,27 @@ void FrameMain::SetDisplayMode(int video, int audio) {
/// @brief Update title bar /// @brief Update title bar
void FrameMain::UpdateTitle() { void FrameMain::UpdateTitle() {
// Determine if current subs are modified
bool subsMod = ass->IsModified(); bool subsMod = ass->IsModified();
// Create ideal title wxString newTitle;
wxString newTitle = _T("");
#ifndef __WXMAC__
if (subsMod) newTitle << _T("* "); if (subsMod) newTitle << _T("* ");
if (ass->filename != _T("")) { if (ass->filename.empty()) {
wxFileName file (ass->filename); // Apple HIG says "untitled" should not be capitalised
newTitle << file.GetFullName(); // and the window is a document window, it shouldn't contain the app name
} // (The app name is already present in the menu bar)
else newTitle << _("Untitled"); #ifndef __WXMAC__
newTitle << _T(" - Aegisub ") << GetAegisubLongVersionString(); newTitle << _("Untitled");
#else #else
// Apple HIG says "untitled" should not be capitalised newTitle << _("untitled");
// and the window is a document window, it shouldn't contain the app name #endif
// (The app name is already present in the menu bar) }
if (ass->filename != _T("")) { else {
wxFileName file (ass->filename); wxFileName file (ass->filename);
newTitle << file.GetFullName(); newTitle << file.GetFullName();
} }
else newTitle << _("untitled");
#ifndef __WXMAC__
newTitle << " - Aegisub " << GetAegisubLongVersionString();
#endif #endif
#if defined(__WXMAC__) && !defined(__LP64__) #if defined(__WXMAC__) && !defined(__LP64__)
@ -650,183 +598,70 @@ void FrameMain::UpdateTitle() {
OSXSetModified(subsMod); OSXSetModified(subsMod);
#endif #endif
// Get current title if (GetTitle() != newTitle) SetTitle(newTitle);
wxString curTitle = GetTitle();
if (curTitle != newTitle) SetTitle(newTitle);
} }
/// @brief Updates subs with video/whatever data /// @brief Updates subs with video/whatever data
/// @param fromSubs /// @param fromSubs
void FrameMain::SynchronizeProject(bool fromSubs) { void FrameMain::SynchronizeProject() {
// Retrieve data from subs
if (fromSubs) {
// Reset the state
long videoPos = 0;
long videoAr = 0;
double videoArValue = 0.0;
double videoZoom = 0.;
// Get AR
wxString arString = ass->GetScriptInfo(_T("Video Aspect Ratio"));
if (arString.Left(1) == _T("c")) {
videoAr = 4;
arString = arString.Mid(1);
arString.ToDouble(&videoArValue);
}
else if (arString.IsNumber()) arString.ToLong(&videoAr);
// Get new state info
ass->GetScriptInfo(_T("Video Position")).ToLong(&videoPos);
ass->GetScriptInfo(_T("Video Zoom Percent")).ToDouble(&videoZoom);
wxString curSubsVideo = DecodeRelativePath(ass->GetScriptInfo(_T("Video File")),ass->filename);
wxString curSubsVFR = DecodeRelativePath(ass->GetScriptInfo(_T("VFR File")),ass->filename);
wxString curSubsKeyframes = DecodeRelativePath(ass->GetScriptInfo(_T("Keyframes File")),ass->filename);
wxString curSubsAudio = DecodeRelativePath(ass->GetScriptInfo(_T("Audio URI")),ass->filename);
wxString AutoScriptString = ass->GetScriptInfo(_T("Automation Scripts"));
// Check if there is anything to change
int autoLoadMode = OPT_GET("App/Auto/Load Linked Files")->GetInt();
bool hasToLoad = false;
if (curSubsAudio !=audioController->GetAudioURL() ||
curSubsVFR != temp_context->videoContext->GetTimecodesName() ||
curSubsVideo != temp_context->videoContext->videoName ||
curSubsKeyframes != temp_context->videoContext->GetKeyFramesName()
#ifdef WITH_AUTOMATION
|| !AutoScriptString.IsEmpty() || local_scripts->GetScripts().size() > 0
#endif
) {
hasToLoad = true;
}
// Decide whether to load or not
bool doLoad = false;
if (hasToLoad) {
if (autoLoadMode == 1) doLoad = true;
else if (autoLoadMode == 2) {
int result = wxMessageBox(_("Do you want to load/unload the associated files?"),_("(Un)Load files?"),wxYES_NO);
if (result == wxYES) doLoad = true;
}
}
if (doLoad) {
// Video
if (!blockVideoLoad && curSubsVideo != temp_context->videoContext->videoName) {
temp_context->videoContext->SetVideo(curSubsVideo);
if (temp_context->videoContext->IsLoaded()) {
temp_context->videoContext->SetAspectRatio(videoAr,videoArValue);
videoBox->videoDisplay->SetZoom(videoZoom);
temp_context->videoContext->JumpToFrame(videoPos);
}
}
temp_context->videoContext->LoadTimecodes(curSubsVFR);
temp_context->videoContext->LoadKeyframes(curSubsKeyframes);
// Audio
if (curSubsAudio != audioController->GetAudioURL()) {
audioController->OpenAudio(curSubsAudio);
}
// Automation scripts
#ifdef WITH_AUTOMATION
local_scripts->RemoveAll();
wxStringTokenizer tok(AutoScriptString, _T("|"), wxTOKEN_STRTOK);
wxFileName assfn(ass->filename);
wxString autobasefn(lagi_wxString(OPT_GET("Path/Automation/Base")->GetString()));
while (tok.HasMoreTokens()) {
wxString sfnames = tok.GetNextToken().Trim(true).Trim(false);
wxString sfnamel = sfnames.Left(1);
sfnames.Remove(0, 1);
wxString basepath;
if (sfnamel == _T("~")) {
basepath = assfn.GetPath();
} else if (sfnamel == _T("$")) {
basepath = autobasefn;
} else if (sfnamel == _T("/")) {
basepath = _T("");
} else {
wxLogWarning(_T("Automation Script referenced with unknown location specifier character.\nLocation specifier found: %s\nFilename specified: %s"),
sfnamel.c_str(), sfnames.c_str());
continue;
}
wxFileName sfname(sfnames);
sfname.MakeAbsolute(basepath);
if (sfname.FileExists()) {
sfnames = sfname.GetFullPath();
local_scripts->Add(Automation4::ScriptFactory::CreateFromFile(sfnames, true));
} else {
wxLogWarning(_T("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());
}
}
#endif
}
// Display
SetDisplayMode(1,1);
}
// Store data on ass // Store data on ass
else { wxString seekpos = _T("0");
// Setup wxString ar = _T("0");
wxString seekpos = _T("0"); wxString zoom = _T("6");
wxString ar = _T("0"); if (temp_context->videoContext->IsLoaded()) {
wxString zoom = _T("6"); seekpos = wxString::Format(_T("%i"),temp_context->videoContext->GetFrameN());
if (temp_context->videoContext->IsLoaded()) { zoom = wxString::Format(_T("%f"),videoBox->videoDisplay->GetZoom());
seekpos = wxString::Format(_T("%i"),temp_context->videoContext->GetFrameN());
zoom = wxString::Format(_T("%f"),videoBox->videoDisplay->GetZoom());
int arType = temp_context->videoContext->GetAspectRatioType(); int arType = temp_context->videoContext->GetAspectRatioType();
if (arType == 4) ar = wxString(_T("c")) + AegiFloatToString(temp_context->videoContext->GetAspectRatioValue()); if (arType == 4) ar = wxString(_T("c")) + AegiFloatToString(temp_context->videoContext->GetAspectRatioValue());
else ar = wxString::Format(_T("%i"),arType); else ar = wxString::Format(_T("%i"),arType);
}
// Store audio data
ass->SetScriptInfo(_T("Audio URI"),MakeRelativePath(audioController->GetAudioURL(),ass->filename));
// Store video data
ass->SetScriptInfo(_T("Video File"),MakeRelativePath(temp_context->videoContext->videoName,ass->filename));
ass->SetScriptInfo(_T("Video Aspect Ratio"),ar);
ass->SetScriptInfo(_T("Video Zoom Percent"),zoom);
ass->SetScriptInfo(_T("Video Position"),seekpos);
ass->SetScriptInfo(_T("VFR File"),MakeRelativePath(temp_context->videoContext->GetTimecodesName(),ass->filename));
ass->SetScriptInfo(_T("Keyframes File"),MakeRelativePath(temp_context->videoContext->GetKeyFramesName(),ass->filename));
// Store Automation script data
// Algorithm:
// 1. If script filename has Automation Base Path as a prefix, the path is relative to that (ie. "$")
// 2. Otherwise try making it relative to the ass filename
// 3. If step 2 failed, or absolut path is shorter than path relative to ass, use absolute path ("/")
// 4. Otherwise, use path relative to ass ("~")
#ifdef WITH_AUTOMATION
wxString scripts_string;
wxString autobasefn(lagi_wxString(OPT_GET("Path/Automation/Base")->GetString()));
const std::vector<Automation4::Script*> &scripts = local_scripts->GetScripts();
for (unsigned int i = 0; i < scripts.size(); i++) {
Automation4::Script *script = scripts[i];
if (i != 0)
scripts_string += _T("|");
wxString autobase_rel, assfile_rel;
wxString scriptfn(script->GetFilename());
autobase_rel = MakeRelativePath(scriptfn, autobasefn);
assfile_rel = MakeRelativePath(scriptfn, ass->filename);
if (autobase_rel.size() <= scriptfn.size() && autobase_rel.size() <= assfile_rel.size()) {
scriptfn = _T("$") + autobase_rel;
} else if (assfile_rel.size() <= scriptfn.size() && assfile_rel.size() <= autobase_rel.size()) {
scriptfn = _T("~") + assfile_rel;
} else {
scriptfn = _T("/") + wxFileName(scriptfn).GetFullPath(wxPATH_UNIX);
}
scripts_string += scriptfn;
}
ass->SetScriptInfo(_T("Automation Scripts"), scripts_string);
#endif
} }
// Store audio data
ass->SetScriptInfo(_T("Audio URI"),MakeRelativePath(audioController->GetAudioURL(),ass->filename));
// Store video data
ass->SetScriptInfo(_T("Video File"),MakeRelativePath(temp_context->videoContext->videoName,ass->filename));
ass->SetScriptInfo(_T("Video Aspect Ratio"),ar);
ass->SetScriptInfo(_T("Video Zoom Percent"),zoom);
ass->SetScriptInfo(_T("Video Position"),seekpos);
ass->SetScriptInfo(_T("VFR File"),MakeRelativePath(temp_context->videoContext->GetTimecodesName(),ass->filename));
ass->SetScriptInfo(_T("Keyframes File"),MakeRelativePath(temp_context->videoContext->GetKeyFramesName(),ass->filename));
// Store Automation script data
// Algorithm:
// 1. If script filename has Automation Base Path as a prefix, the path is relative to that (ie. "$")
// 2. Otherwise try making it relative to the ass filename
// 3. If step 2 failed, or absolut path is shorter than path relative to ass, use absolute path ("/")
// 4. Otherwise, use path relative to ass ("~")
#ifdef WITH_AUTOMATION
wxString scripts_string;
wxString autobasefn(lagi_wxString(OPT_GET("Path/Automation/Base")->GetString()));
const std::vector<Automation4::Script*> &scripts = local_scripts->GetScripts();
for (unsigned int i = 0; i < scripts.size(); i++) {
Automation4::Script *script = scripts[i];
if (i != 0)
scripts_string += _T("|");
wxString autobase_rel, assfile_rel;
wxString scriptfn(script->GetFilename());
autobase_rel = MakeRelativePath(scriptfn, autobasefn);
assfile_rel = MakeRelativePath(scriptfn, ass->filename);
if (autobase_rel.size() <= scriptfn.size() && autobase_rel.size() <= assfile_rel.size()) {
scriptfn = _T("$") + autobase_rel;
} else if (assfile_rel.size() <= scriptfn.size() && assfile_rel.size() <= autobase_rel.size()) {
scriptfn = _T("~") + assfile_rel;
} else {
scriptfn = _T("/") + wxFileName(scriptfn).GetFullPath(wxPATH_UNIX);
}
scripts_string += scriptfn;
}
ass->SetScriptInfo(_T("Automation Scripts"), scripts_string);
#endif
} }
void FrameMain::OnVideoOpen() { void FrameMain::OnVideoOpen() {
@ -1453,7 +1288,7 @@ void FrameMain::OnAudioClose()
SetDisplayMode(-1, 0); SetDisplayMode(-1, 0);
} }
void FrameMain::OnSubtitlesFileChanged() { void FrameMain::OnSubtitlesCommit() {
if (OPT_GET("App/Auto/Save on Every Change")->GetBool()) { if (OPT_GET("App/Auto/Save on Every Change")->GetBool()) {
if (ass->IsModified() && !ass->filename.empty()) SaveSubtitles(false); if (ass->IsModified() && !ass->filename.empty()) SaveSubtitles(false);
} }
@ -1461,6 +1296,114 @@ void FrameMain::OnSubtitlesFileChanged() {
UpdateTitle(); UpdateTitle();
} }
void FrameMain::OnSubtitlesOpen() {
UpdateTitle();
/// @todo figure out how to move this to the relevant controllers without
/// prompting for each file loaded/unloaded
// Load stuff from the new script
wxString curSubsVideo = DecodeRelativePath(ass->GetScriptInfo("Video File"),ass->filename);
wxString curSubsVFR = DecodeRelativePath(ass->GetScriptInfo("VFR File"),ass->filename);
wxString curSubsKeyframes = DecodeRelativePath(ass->GetScriptInfo("Keyframes File"),ass->filename);
wxString curSubsAudio = DecodeRelativePath(ass->GetScriptInfo("Audio URI"),ass->filename);
wxString AutoScriptString = ass->GetScriptInfo("Automation Scripts");
// Check if there is anything to change
int autoLoadMode = OPT_GET("App/Auto/Load Linked Files")->GetInt();
bool doLoad = false;
if (curSubsAudio != audioController->GetAudioURL() ||
curSubsVFR != temp_context->videoContext->GetTimecodesName() ||
curSubsVideo != temp_context->videoContext->videoName ||
curSubsKeyframes != temp_context->videoContext->GetKeyFramesName()
#ifdef WITH_AUTOMATION
|| !AutoScriptString.IsEmpty() || local_scripts->GetScripts().size() > 0
#endif
)
{
if (autoLoadMode == 1) {
doLoad = true;
}
else if (autoLoadMode == 2) {
doLoad = wxMessageBox(_("Do you want to load/unload the associated files?"), _("(Un)Load files?"), wxYES_NO) == wxYES;
}
}
if (doLoad) {
// Video
if (!blockVideoLoad && curSubsVideo != temp_context->videoContext->videoName) {
temp_context->videoContext->SetVideo(curSubsVideo);
if (temp_context->videoContext->IsLoaded()) {
long videoPos = 0;
long videoAr = 0;
double videoArValue = 0.0;
double videoZoom = 0.;
ass->GetScriptInfo("Video Position").ToLong(&videoPos);
ass->GetScriptInfo("Video Zoom Percent").ToDouble(&videoZoom);
wxString arString = ass->GetScriptInfo("Video Aspect Ratio");
if (arString.Left(1) == "c") {
videoAr = 4;
arString = arString.Mid(1);
arString.ToDouble(&videoArValue);
}
else if (arString.IsNumber()) {
arString.ToLong(&videoAr);
}
temp_context->videoContext->SetAspectRatio(videoAr,videoArValue);
videoBox->videoDisplay->SetZoom(videoZoom);
temp_context->videoContext->JumpToFrame(videoPos);
}
}
temp_context->videoContext->LoadTimecodes(curSubsVFR);
temp_context->videoContext->LoadKeyframes(curSubsKeyframes);
// Audio
if (curSubsAudio != audioController->GetAudioURL()) {
audioController->OpenAudio(curSubsAudio);
}
// Automation scripts
#ifdef WITH_AUTOMATION
local_scripts->RemoveAll();
wxStringTokenizer tok(AutoScriptString, _T("|"), wxTOKEN_STRTOK);
wxFileName assfn(ass->filename);
wxString autobasefn(lagi_wxString(OPT_GET("Path/Automation/Base")->GetString()));
while (tok.HasMoreTokens()) {
wxString sfnames = tok.GetNextToken().Trim(true).Trim(false);
wxString sfnamel = sfnames.Left(1);
sfnames.Remove(0, 1);
wxString basepath;
if (sfnamel == _T("~")) {
basepath = assfn.GetPath();
} else if (sfnamel == _T("$")) {
basepath = autobasefn;
} else if (sfnamel == _T("/")) {
basepath = _T("");
} else {
wxLogWarning(_T("Automation Script referenced with unknown location specifier character.\nLocation specifier found: %s\nFilename specified: %s"),
sfnamel.c_str(), sfnames.c_str());
continue;
}
wxFileName sfname(sfnames);
sfname.MakeAbsolute(basepath);
if (sfname.FileExists()) {
sfnames = sfname.GetFullPath();
local_scripts->Add(Automation4::ScriptFactory::CreateFromFile(sfnames, true));
} else {
wxLogWarning(_T("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());
}
}
#endif
}
// Display
SetDisplayMode(1,1);
}
void FrameMain::OnKeyDown(wxKeyEvent &event) { void FrameMain::OnKeyDown(wxKeyEvent &event) {
hotkey::check("Main Frame", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers()); hotkey::check("Main Frame", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers());
} }

View file

@ -88,7 +88,7 @@ class FrameMain: public wxFrame {
public: public:
void StatusTimeout(wxString text,int ms=10000); void StatusTimeout(wxString text,int ms=10000);
void SetDisplayMode(int showVid,int showAudio); void SetDisplayMode(int showVid,int showAudio);
void LoadSubtitles(wxString filename,wxString charset=_T("")); void LoadSubtitles(wxString filename,wxString charset="");
bool SaveSubtitles(bool saveas=false,bool withCharset=false); bool SaveSubtitles(bool saveas=false,bool withCharset=false);
void DetachVideo(bool detach=true); void DetachVideo(bool detach=true);
void LoadVFR(wxString filename); void LoadVFR(wxString filename);
@ -165,7 +165,7 @@ private:
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);
void SynchronizeProject(bool FromSubs=false); void SynchronizeProject();
// AudioControllerAudioEventListener implementation // AudioControllerAudioEventListener implementation
void OnAudioOpen(AudioProvider *provider); void OnAudioOpen(AudioProvider *provider);
@ -173,7 +173,8 @@ private:
void OnVideoOpen(); void OnVideoOpen();
void OnSubtitlesFileChanged(); void OnSubtitlesCommit();
void OnSubtitlesOpen();
public: public:

View file

@ -115,7 +115,8 @@ SubtitlesGrid::SubtitlesGrid(FrameMain* parentFr, wxWindow *parent, wxWindowID i
OnHighlightVisibleChange(*OPT_GET("Subtitle/Grid/Highlight Subtitles in Frame")); OnHighlightVisibleChange(*OPT_GET("Subtitle/Grid/Highlight Subtitles in Frame"));
OPT_SUB("Subtitle/Grid/Highlight Subtitles in Frame", &SubtitlesGrid::OnHighlightVisibleChange, this); OPT_SUB("Subtitle/Grid/Highlight Subtitles in Frame", &SubtitlesGrid::OnHighlightVisibleChange, this);
OPT_SUB("Subtitle/Grid/Hide Overrides", std::tr1::bind(&SubtitlesGrid::Refresh, this, false, (const wxRect*)0)); OPT_SUB("Subtitle/Grid/Hide Overrides", std::tr1::bind(&SubtitlesGrid::Refresh, this, false, (const wxRect*)0));
ass->AddCommitListener(&SubtitlesGrid::OnCommit, this); ass->AddCommitListener(&SubtitlesGrid::OnSubtitlesCommit, this);
ass->AddFileOpenListener(&SubtitlesGrid::OnSubtitlesOpen, this);
} }
/// @brief Destructor /// @brief Destructor
@ -123,7 +124,7 @@ SubtitlesGrid::~SubtitlesGrid() {
ClearMaps(); ClearMaps();
} }
void SubtitlesGrid::OnCommit(int type) { void SubtitlesGrid::OnSubtitlesCommit(int type) {
if (type == AssFile::COMMIT_FULL) if (type == AssFile::COMMIT_FULL)
UpdateMaps(); UpdateMaps();
else if (type == AssFile::COMMIT_UNDO) else if (type == AssFile::COMMIT_UNDO)
@ -139,6 +140,19 @@ void SubtitlesGrid::OnCommit(int type) {
} }
} }
void SubtitlesGrid::OnSubtitlesOpen() {
BeginBatch();
ClearMaps();
UpdateMaps();
if (GetRows()) {
SetActiveLine(GetDialogue(0));
SelectRow(0);
}
EndBatch();
SetColumnWidths();
}
/// @brief Popup menu /// @brief Popup menu
/// @param alternate /// @param alternate
void SubtitlesGrid::OnPopupMenu(bool alternate) { void SubtitlesGrid::OnPopupMenu(bool alternate) {

View file

@ -99,7 +99,8 @@ private:
void OnHighlightVisibleChange(agi::OptionValue const& opt); void OnHighlightVisibleChange(agi::OptionValue const& opt);
void OnCommit(int type); void OnSubtitlesCommit(int type);
void OnSubtitlesOpen();
public: public:
/// Currently open file /// Currently open file