mirror of https://github.com/odrling/Aegisub
Move the CanSave logic to the subtitle formats as it's obviously format-specific
Originally committed to SVN as r6625.
This commit is contained in:
parent
0ae8479ffb
commit
a03b37bdef
|
@ -225,45 +225,9 @@ void AssFile::SaveMemory(std::vector<char> &dst) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AssFile::CanSave() {
|
bool AssFile::CanSave() const {
|
||||||
// ASS format?
|
const SubtitleFormat *writer = SubtitleFormat::GetWriter(filename);
|
||||||
wxString ext = filename.Lower().Right(4);
|
return writer && writer->CanSave(this);
|
||||||
if (ext == ".ass") return true;
|
|
||||||
|
|
||||||
// Never save texts
|
|
||||||
if (ext == ".txt") return false;
|
|
||||||
|
|
||||||
// Check if it's a known extension
|
|
||||||
if (!SubtitleFormat::GetWriter(filename)) 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 = dynamic_cast<AssStyle*>(*cur);
|
|
||||||
if (curstyle) {
|
|
||||||
if (curstyle->GetEntryData() != defstyle.GetEntryData()) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for attachments, if any is found, return false
|
|
||||||
if (dynamic_cast<AssAttachment*>(*cur)) return false;
|
|
||||||
|
|
||||||
// Check dialog
|
|
||||||
curdiag = dynamic_cast<AssDialogue*>(*cur);
|
|
||||||
if (curdiag) {
|
|
||||||
// Overrides?
|
|
||||||
curdiag->ParseASSTags();
|
|
||||||
for (size_t i=0;i<curdiag->Blocks.size();i++) {
|
|
||||||
if (curdiag->Blocks[i]->GetType() != BLOCK_PLAIN) return false;
|
|
||||||
}
|
|
||||||
curdiag->ClearBlocks();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Success
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssFile::AddLine(wxString data, int *version, AssAttachment **attach) {
|
void AssFile::AddLine(wxString data, int *version, AssAttachment **attach) {
|
||||||
|
|
|
@ -146,7 +146,7 @@ public:
|
||||||
/// Add file name to the MRU list
|
/// Add file name to the MRU list
|
||||||
void AddToRecent(wxString file);
|
void AddToRecent(wxString file);
|
||||||
/// Can the file be saved in its current format?
|
/// Can the file be saved in its current format?
|
||||||
bool CanSave();
|
bool CanSave() const;
|
||||||
/// @brief Get the list of wildcards supported
|
/// @brief Get the list of wildcards supported
|
||||||
/// @param mode 0 = open, 1 = save, 2 = export
|
/// @param mode 0 = open, 1 = save, 2 = export
|
||||||
static wxString GetWildcardList(int mode);
|
static wxString GetWildcardList(int mode);
|
||||||
|
|
|
@ -36,14 +36,17 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "subtitle_format.h"
|
||||||
|
|
||||||
#ifndef AGI_PRE
|
#ifndef AGI_PRE
|
||||||
#include <wx/intl.h>
|
#include <wx/intl.h>
|
||||||
#include <wx/choicdlg.h> // Keep this last so wxUSE_CHOICEDLG is set.
|
#include <wx/choicdlg.h> // Keep this last so wxUSE_CHOICEDLG is set.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "ass_attachment.h"
|
||||||
#include "ass_dialogue.h"
|
#include "ass_dialogue.h"
|
||||||
#include "ass_file.h"
|
#include "ass_file.h"
|
||||||
#include "subtitle_format.h"
|
#include "ass_style.h"
|
||||||
#include "subtitle_format_ass.h"
|
#include "subtitle_format_ass.h"
|
||||||
#include "subtitle_format_encore.h"
|
#include "subtitle_format_encore.h"
|
||||||
#include "subtitle_format_microdvd.h"
|
#include "subtitle_format_microdvd.h"
|
||||||
|
@ -75,7 +78,28 @@ bool SubtitleFormat::CanWriteFile(wxString const& filename) const {
|
||||||
return GetWriteWildcards().Index(filename.AfterLast('.'), false) != wxNOT_FOUND;
|
return GetWriteWildcards().Index(filename.AfterLast('.'), false) != wxNOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Ask the user to enter the FPS
|
bool SubtitleFormat::CanSave(const AssFile *subs) const {
|
||||||
|
AssStyle defstyle;
|
||||||
|
for (std::list<AssEntry*>::const_iterator cur = subs->Line.begin(); cur != subs->Line.end(); ++cur) {
|
||||||
|
// Check style, if anything non-default is found, return false
|
||||||
|
if (const AssStyle *curstyle = dynamic_cast<const AssStyle*>(*cur)) {
|
||||||
|
if (curstyle->GetEntryData() != defstyle.GetEntryData())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for attachments, if any is found, return false
|
||||||
|
if (dynamic_cast<const AssAttachment*>(*cur)) return false;
|
||||||
|
|
||||||
|
// Check dialog
|
||||||
|
if (const AssDialogue *curdiag = dynamic_cast<const AssDialogue*>(*cur)) {
|
||||||
|
if (curdiag->GetStrippedText() != curdiag->Text)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
FractionalTime SubtitleFormat::AskForFPS(bool showSMPTE) const {
|
FractionalTime SubtitleFormat::AskForFPS(bool showSMPTE) const {
|
||||||
wxArrayString choices;
|
wxArrayString choices;
|
||||||
bool drop = false;
|
bool drop = false;
|
||||||
|
|
|
@ -103,16 +103,22 @@ public:
|
||||||
|
|
||||||
/// @brief Check if the given file can be read by this format
|
/// @brief Check if the given file can be read by this format
|
||||||
///
|
///
|
||||||
/// Default implement ion simply checks if the file's extension is in the
|
/// Default implementation simply checks if the file's extension is in the
|
||||||
/// format's wildcard list
|
/// format's wildcard list
|
||||||
virtual bool CanReadFile(wxString const& filename) const;
|
virtual bool CanReadFile(wxString const& filename) const;
|
||||||
|
|
||||||
/// @brief Check if the given file can be written by this format
|
/// @brief Check if the given file can be written by this format
|
||||||
///
|
///
|
||||||
/// Default implement ion simply checks if the file's extension is in the
|
/// Default implementation simply checks if the file's extension is in the
|
||||||
/// format's wildcard list
|
/// format's wildcard list
|
||||||
virtual bool CanWriteFile(wxString const& filename) const;
|
virtual bool CanWriteFile(wxString const& filename) const;
|
||||||
|
|
||||||
|
/// @brief Check if the given subtitles can be losslessly written by this format
|
||||||
|
///
|
||||||
|
/// Default implementation rejects files with attachments, non-default
|
||||||
|
/// styles, and any overrides
|
||||||
|
virtual bool CanSave(const AssFile *file) const;
|
||||||
|
|
||||||
/// Load a subtitle file
|
/// Load a subtitle file
|
||||||
/// @param[out] target Destination to read lines into
|
/// @param[out] target Destination to read lines into
|
||||||
/// @param filename File to load
|
/// @param filename File to load
|
||||||
|
|
|
@ -48,6 +48,9 @@ public:
|
||||||
wxArrayString GetReadWildcards() const;
|
wxArrayString GetReadWildcards() const;
|
||||||
wxArrayString GetWriteWildcards() const;
|
wxArrayString GetWriteWildcards() const;
|
||||||
|
|
||||||
|
// Naturally the ASS subtitle format can save all Ass files
|
||||||
|
bool CanSave(const AssFile*) const { return true; }
|
||||||
|
|
||||||
void ReadFile(AssFile *target, wxString const& filename, wxString const& forceEncoding) const;
|
void ReadFile(AssFile *target, wxString const& filename, wxString const& forceEncoding) const;
|
||||||
void WriteFile(const AssFile *src, wxString const& filename, wxString const& encoding) const;
|
void WriteFile(const AssFile *src, wxString const& filename, wxString const& encoding) const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -47,6 +47,9 @@ public:
|
||||||
wxArrayString GetReadWildcards() const;
|
wxArrayString GetReadWildcards() const;
|
||||||
wxArrayString GetWriteWildcards() const;
|
wxArrayString GetWriteWildcards() const;
|
||||||
|
|
||||||
|
// TXT format supports so little that it should always require an export
|
||||||
|
bool CanSave(const AssFile*) const { return false; }
|
||||||
|
|
||||||
bool CanWriteFile(wxString const& filename) const;
|
bool CanWriteFile(wxString const& filename) const;
|
||||||
void ReadFile(AssFile *target, wxString const& filename, wxString const& forceEncoding) const;
|
void ReadFile(AssFile *target, wxString const& filename, wxString const& forceEncoding) const;
|
||||||
void WriteFile(const AssFile *src, wxString const& filename, wxString const& encoding) const;
|
void WriteFile(const AssFile *src, wxString const& filename, wxString const& encoding) const;
|
||||||
|
|
Loading…
Reference in New Issue