Make SubsController ensure files are non-empty on commit

There have been a bunch of recurring problems with things not handling
zero dialogue lines or zero styles very well, so add one to the file on
commit if needed.

Closes #1814.
This commit is contained in:
Thomas Goyne 2014-08-24 08:02:39 -07:00
parent 9ec4059096
commit d7fe7e3580
1 changed files with 6 additions and 6 deletions

View File

@ -178,12 +178,6 @@ ProjectProperties SubsController::Load(agi::fs::path const& filename, std::strin
SubtitleFormat::GetReader(filename, charset)->ReadFile(&temp, filename, context->project->Timecodes(), charset);
// Make sure the file has at least one style and one dialogue line
if (temp.Styles.empty())
temp.Styles.push_back(*new AssStyle);
if (temp.Events.empty())
temp.Events.push_back(*new AssDialogue);
context->ass->swap(temp);
auto props = context->ass->Properties;
@ -328,6 +322,12 @@ void SubsController::OnCommit(AssFileCommit c) {
undo_stack.pop_back();
}
// Make sure the file has at least one style and one dialogue line
if (context->ass->Styles.empty())
context->ass->Styles.push_back(*new AssStyle);
if (context->ass->Events.empty())
context->ass->Events.push_back(*new AssDialogue);
redo_stack.clear();
undo_stack.emplace_back(context, c.message, commit_id);