From 5f41c378f1429b00480d86ffd20c5677884071b7 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Wed, 28 Jun 2006 22:51:33 +0000 Subject: [PATCH] Saving back to SRT directly (that is, via "save", not "export" or "save as") is now allowed, as long as no data will be lost. Originally committed to SVN as r434. --- core/ass_file.cpp | 42 +++++++++++++++++++++++++++++++----- core/ass_file.h | 2 +- core/changelog.txt | 1 + core/frame_main.cpp | 2 +- core/frame_main_events.cpp | 2 +- core/subtitle_format.cpp | 7 ------ core/subtitle_format.h | 1 - core/subtitle_format_ass.cpp | 3 --- core/subtitle_format_txt.cpp | 1 - 9 files changed, 41 insertions(+), 20 deletions(-) diff --git a/core/ass_file.cpp b/core/ass_file.cpp index e2103ab86..02757cd37 100644 --- a/core/ass_file.cpp +++ b/core/ass_file.cpp @@ -89,7 +89,6 @@ void AssFile::Load (const wxString _filename,const wxString charset) { // Generic preparation Clear(); - IsASS = false; // Get proper format reader SubtitleFormat *reader = SubtitleFormat::GetReader(_filename); @@ -167,7 +166,6 @@ void AssFile::Save(wxString _filename,bool setfilename,bool addToRecent,const wx if (setfilename) { Modified = false; filename = _filename; - IsASS = true; } } @@ -181,6 +179,43 @@ void AssFile::Export(wxString _filename) { } +////////////////// +// Can save file? +bool AssFile::CanSave() { + // ASS format? + if (filename.Lower().Right(4) == _T(".ass")) return true; + + // Check if it's a known extension + SubtitleFormat *writer = SubtitleFormat::GetWriter(filename); + if (!writer) return false; + + // Scan through the lines + AssStyle defstyle; + AssStyle *curstyle; + AssDialogue *curdiag; + for (entryIter cur=Line.begin();cur!=Line.end();cur++) { + // Check style, if anything non-default is found, return false + curstyle = AssEntry::GetAsStyle(*cur); + if (curstyle) { + if (curstyle->GetEntryData() != defstyle.GetEntryData()) return false; + } + + // Check dialog + curdiag = AssEntry::GetAsDialogue(*cur); + if (curdiag) { + curdiag->ParseASSTags(); + for (size_t i=0;iBlocks.size();i++) { + if (curdiag->Blocks[i]->type != BLOCK_PLAIN) return false; + } + curdiag->ClearBlocks(); + } + } + + // Success + return true; +} + + //////////////////////////////////// // Returns script as a single string wxString AssFile::GetString() { @@ -280,7 +315,6 @@ void AssFile::Clear () { } Line.clear(); - IsASS = false; loaded = false; filename = _T(""); Modified = false; @@ -315,7 +349,6 @@ void AssFile::LoadDefault (bool defline) { } loaded = true; - IsASS = true; } @@ -326,7 +359,6 @@ AssFile::AssFile (AssFile &from) { // Copy standard variables filename = from.filename; - IsASS = from.IsASS; loaded = from.loaded; Modified = from.Modified; bool IsSSA = false; diff --git a/core/ass_file.h b/core/ass_file.h index 9ff61917f..a6bf3eff5 100644 --- a/core/ass_file.h +++ b/core/ass_file.h @@ -72,7 +72,6 @@ public: wxString filename; bool loaded; - bool IsASS; AssFile(); AssFile(AssFile &from); @@ -92,6 +91,7 @@ public: void Save(wxString file,bool setfilename=false,bool addToRecent=true,const wxString encoding=_T("")); // Save to a file. Pass true to second argument if this isn't a copy void Export(wxString file); // Saves exported copy, with effects applied void AddToRecent(wxString file); // Adds file name to list of recently opened files + bool CanSave(); // Return true if the file can be saved in its current format int GetScriptInfoAsInt(const wxString key); wxString GetScriptInfo(const wxString key); // Returns the value in a [Script Info] key. diff --git a/core/changelog.txt b/core/changelog.txt index 421dc31c0..3618207d6 100644 --- a/core/changelog.txt +++ b/core/changelog.txt @@ -85,6 +85,7 @@ Please visit http://aegisub.net to download latest version - Text edit boxes in the subtitle editing area will now revert to unmodified if you restore the original text. (AMZ) - Re-arranged the controls in the subtitle editing area. (AMZ) - Right-clicking on the header of the subtitles grid will now bring up a popup menu that allows you to disable columns. (AMZ) +- Saving back to SRT directly (that is, via "save", not "export" or "save as") is now allowed, as long as no data will be lost. (AMZ) = 1.09 beta - 2006.01.16 =========================== diff --git a/core/frame_main.cpp b/core/frame_main.cpp index 945bf5f71..2e2e085bc 100644 --- a/core/frame_main.cpp +++ b/core/frame_main.cpp @@ -561,7 +561,7 @@ void FrameMain::LoadSubtitles (wxString filename,wxString charset) { bool FrameMain::SaveSubtitles(bool saveas,bool withCharset) { // Try to get filename from file wxString filename; - if (saveas == false && AssFile::top->IsASS) filename = AssFile::top->filename; + if (saveas == false && AssFile::top->CanSave()) filename = AssFile::top->filename; // Failed, ask user if (filename.IsEmpty()) { diff --git a/core/frame_main_events.cpp b/core/frame_main_events.cpp index ee738b4f9..82f9d8510 100644 --- a/core/frame_main_events.cpp +++ b/core/frame_main_events.cpp @@ -1133,7 +1133,7 @@ void FrameMain::OnOpenStylingAssistant (wxCommandEvent &event) { void FrameMain::OnAutoSave(wxTimerEvent &event) { // Auto Save try { - if (AssFile::top->loaded && AssFile::top->IsASS) { + if (AssFile::top->loaded && AssFile::top->CanSave()) { // Set path wxFileName origfile(AssFile::top->filename); wxString path = Options.AsText(_T("Auto save path")); diff --git a/core/subtitle_format.cpp b/core/subtitle_format.cpp index 52e6e64b1..3826b46eb 100644 --- a/core/subtitle_format.cpp +++ b/core/subtitle_format.cpp @@ -109,13 +109,6 @@ void SubtitleFormat::LoadDefault() { } -/////////////////// -// Set if it's ASS -void SubtitleFormat::SetIsASS(bool isASS) { - assFile->IsASS = isASS; -} - - //////////// // Add line int SubtitleFormat::AddLine(wxString data,wxString group,int lasttime,bool &IsSSA) { diff --git a/core/subtitle_format.h b/core/subtitle_format.h index de26b7803..75f49a046 100644 --- a/core/subtitle_format.h +++ b/core/subtitle_format.h @@ -69,7 +69,6 @@ protected: void Clear(); void LoadDefault(); - void SetIsASS(bool isASS); AssFile *GetAssFile() { return assFile; } int AddLine(wxString data,wxString group,int lasttime,bool &IsSSA); diff --git a/core/subtitle_format_ass.cpp b/core/subtitle_format_ass.cpp index 748c08787..fb1695aab 100644 --- a/core/subtitle_format_ass.cpp +++ b/core/subtitle_format_ass.cpp @@ -88,9 +88,6 @@ void ASSSubtitleFormat::ReadFile(wxString filename,wxString encoding) { throw wxString(_T("Error processing line: ")) + wxbuffer; } } - - // Set ASS - SetIsASS(!IsSSA); } diff --git a/core/subtitle_format_txt.cpp b/core/subtitle_format_txt.cpp index 3610ce2c2..34026948e 100644 --- a/core/subtitle_format_txt.cpp +++ b/core/subtitle_format_txt.cpp @@ -58,7 +58,6 @@ void TXTSubtitleFormat::ReadFile(wxString filename,wxString encoding) { using na // Default LoadDefault(); - SetIsASS(false); // Data wxString actor;