Move some stuff from AssFile::Load to FrameMain::LoadSubtitles

This is still not a very good place for it, but AssFile really shouldn't
be mucking around in global program state.
This commit is contained in:
Thomas Goyne 2012-10-11 20:26:51 -07:00
parent a53432736c
commit 9547bc4ef2
5 changed files with 27 additions and 27 deletions

View file

@ -78,7 +78,7 @@ AssFile::~AssFile() {
}
/// @brief Load generic subs
void AssFile::Load(const wxString &_filename, wxString charset, bool addToRecent) {
void AssFile::Load(const wxString &_filename, wxString const& charset) {
try {
// Get proper format reader
const SubtitleFormat *reader = SubtitleFormat::GetReader(_filename);
@ -113,23 +113,6 @@ void AssFile::Load(const wxString &_filename, wxString charset, bool addToRecent
// Set general data
loaded = true;
filename = _filename;
StandardPaths::SetPathValue("?script", wxFileName(filename).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(StandardPaths::DecodePath(path + "/"));
if (!dstpath.DirExists())
wxMkdir(dstpath.GetPath());
dstpath.SetFullName(file.GetName() + ".ORIGINAL." + file.GetExt());
wxCopyFile(file.GetFullPath(), dstpath.GetFullPath(), true);
}
}
// Add comments and set vars
AddComment(wxString("Script generated by Aegisub ") + GetAegisubLongVersionString());
@ -143,8 +126,6 @@ void AssFile::Load(const wxString &_filename, wxString charset, bool addToRecent
autosavedCommitId = savedCommitId = commitId + 1;
Commit("", COMMIT_NEW);
// Add to recent
if (addToRecent) AddToRecent(filename);
FileOpen(filename);
}

View file

@ -122,8 +122,7 @@ public:
/// @brief Load from a file
/// @param file File name
/// @param charset Character set of file or empty to autodetect
/// @param addToRecent Should the file be added to the MRU list?
void Load(const wxString &file,wxString charset="",bool addToRecent=true);
void Load(const wxString &file, wxString const& charset="");
/// @brief Save to a file
/// @param file Path to save to

View file

@ -598,7 +598,7 @@ void DialogStyleManager::OnCurrentImport() {
AssFile temp;
try {
temp.Load(filename, "", false);
temp.Load(filename);
}
catch (const char *err) {
wxMessageBox(err, "Error", wxOK | wxICON_ERROR | wxCENTER, this);

View file

@ -408,7 +408,7 @@ void FrameMain::InitContents() {
StartupLog("Leaving InitContents");
}
void FrameMain::LoadSubtitles(wxString filename,wxString charset) {
void FrameMain::LoadSubtitles(wxString const& filename, wxString const& charset) {
if (context->ass->loaded) {
if (TryToCloseSubs() == wxCANCEL) return;
}
@ -416,7 +416,7 @@ void FrameMain::LoadSubtitles(wxString filename,wxString charset) {
try {
// Make sure that file isn't actually a timecode file
try {
TextFileReader testSubs(filename,charset);
TextFileReader testSubs(filename, charset);
wxString cur = testSubs.ReadLineFromFile();
if (cur.Left(10) == "# timecode") {
context->videoController->LoadTimecodes(filename);
@ -428,7 +428,27 @@ void FrameMain::LoadSubtitles(wxString filename,wxString charset) {
// safe to assume that it is in fact not a timecode file
}
context->ass->Load(filename,charset);
context->ass->Load(filename, charset);
wxFileName file(filename);
StandardPaths::SetPathValue("?script", file.GetPath());
config::mru->Add("Subtitle", STD_STR(filename));
OPT_SET("Path/Last/Subtitles")->SetString(STD_STR(file.GetPath()));
// Save backup of file
if (context->ass->CanSave() && OPT_GET("App/Auto/Backup")->GetBool()) {
if (file.FileExists()) {
wxString path = lagi_wxString(OPT_GET("Path/Auto/Backup")->GetString());
if (path.empty()) path = file.GetPath();
wxFileName dstpath(StandardPaths::DecodePath(path + "/"));
if (!dstpath.DirExists())
wxMkdir(dstpath.GetPath());
dstpath.SetFullName(file.GetName() + ".ORIGINAL." + file.GetExt());
wxCopyFile(file.GetFullPath(), dstpath.GetFullPath(), true);
}
}
}
catch (agi::FileNotFoundError const&) {
wxMessageBox(filename + " not found.", "Error", wxOK | wxICON_ERROR | wxCENTER, this);

View file

@ -146,7 +146,7 @@ public:
/// @param enableCancel Should the user be able to cancel the close?
int TryToCloseSubs(bool enableCancel=true);
void LoadSubtitles(wxString filename,wxString charset="");
void LoadSubtitles(wxString const& filename, wxString const& charset="");
DECLARE_EVENT_TABLE()
};