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.
This commit is contained in:
Rodrigo Braz Monteiro 2006-06-28 22:51:33 +00:00
parent 34257c39e8
commit 5f41c378f1
9 changed files with 41 additions and 20 deletions

View File

@ -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;i<curdiag->Blocks.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;

View File

@ -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.

View File

@ -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 ===========================

View File

@ -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()) {

View File

@ -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"));

View File

@ -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) {

View File

@ -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);

View File

@ -88,9 +88,6 @@ void ASSSubtitleFormat::ReadFile(wxString filename,wxString encoding) {
throw wxString(_T("Error processing line: ")) + wxbuffer;
}
}
// Set ASS
SetIsASS(!IsSSA);
}

View File

@ -58,7 +58,6 @@ void TXTSubtitleFormat::ReadFile(wxString filename,wxString encoding) { using na
// Default
LoadDefault();
SetIsASS(false);
// Data
wxString actor;