diff --git a/athenasub/include/athenasub/interfaces.h b/athenasub/include/athenasub/interfaces.h index 22cd2da17..801b1e970 100644 --- a/athenasub/include/athenasub/interfaces.h +++ b/athenasub/include/athenasub/interfaces.h @@ -116,7 +116,7 @@ namespace Athenasub { virtual void Clear() = 0; virtual void Load(wxInputStream &input,Format format=Format(),const String encoding="") = 0; - virtual void AddSection(String name) = 0; + virtual Section AddSection(String name) = 0; virtual Section GetMutableSection(String name) = 0; virtual Section GetMutableSectionByIndex(size_t index) = 0; diff --git a/athenasub/src/format_handler.h b/athenasub/src/format_handler.h index 872ac9743..3b5f5e955 100644 --- a/athenasub/src/format_handler.h +++ b/athenasub/src/format_handler.h @@ -45,7 +45,7 @@ namespace Athenasub { protected: virtual ~CFormatHandler() {} - void AddSection(IModel &model,String name) const { model.AddSection(name); } + Section AddSection(IModel &model,String name) const { return model.AddSection(name); } ConstSection GetSection(const IModel &model,String name) const { return model.GetSection(name); } ConstSection GetSectionByIndex(const IModel &model,size_t index) const { return model.GetSectionByIndex(index); } Section GetSection(IModel &model,String name) const { return model.GetMutableSection(name); } diff --git a/athenasub/src/formats/format_ass.cpp b/athenasub/src/formats/format_ass.cpp index e02b8c5e3..8c9f06b70 100644 --- a/athenasub/src/formats/format_ass.cpp +++ b/athenasub/src/formats/format_ass.cpp @@ -378,9 +378,7 @@ void FormatHandlerASS::MakeValid(IModel &model) // Check for [Script Info] Section section = GetSection(model,"Script Info"); - if (!section) AddSection(model,"Script Info"); - section = GetSection(model,"Script Info"); - if (!section) THROW_ATHENA_EXCEPTION(Exception::Internal_Error); + if (!section) section = AddSection(model,"Script Info"); // Check if necessary variables are available if (section->GetProperty("PlayResX").IsEmpty()) section->SetProperty("PlayResX","384"); // These two mystical values come from Substation Alpha @@ -389,15 +387,11 @@ void FormatHandlerASS::MakeValid(IModel &model) // Get [V4+ Styles] section = GetSection(model,"V4+ Styles"); - if (!section) AddSection(model,"V4+ Styles"); - section = GetSection(model,"V4+ Styles"); - if (!section) THROW_ATHENA_EXCEPTION(Exception::Internal_Error); + if (!section) section = AddSection(model,"V4+ Styles"); section->SetProperty("Format","Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding"); // Get [Events] section = GetSection(model,"Events"); - if (!section) AddSection(model,"Events"); - section = GetSection(model,"Events"); - if (!section) THROW_ATHENA_EXCEPTION(Exception::Internal_Error); + if (!section) section = AddSection(model,"Events"); section->SetProperty("Format","Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text"); } diff --git a/athenasub/src/model.cpp b/athenasub/src/model.cpp index 3e67591a4..0bdf5493d 100644 --- a/athenasub/src/model.cpp +++ b/athenasub/src/model.cpp @@ -153,11 +153,14 @@ void CModel::Save(wxOutputStream &output,const Format _format,const String encod ///////////////////////// // Inserts a new section -void CModel::AddSection(String name) +Section CModel::AddSection(String name) { ConstSection prev = GetSection(name); if (prev) THROW_ATHENA_EXCEPTION(Exception::Section_Already_Exists); - sections.push_back(Section(new CSection(name))); + + Section result = Section(new CSection(name)); + sections.push_back(result); + return result; } diff --git a/athenasub/src/model.h b/athenasub/src/model.h index a07250a85..ceca0ccd5 100644 --- a/athenasub/src/model.h +++ b/athenasub/src/model.h @@ -82,7 +82,7 @@ namespace Athenasub { void Clear(); void Load(wxInputStream &input,Format format=Format(),const String encoding=""); - void AddSection(String name); + Section AddSection(String name); Section GetMutableSection(String name); Section GetMutableSectionByIndex(size_t index);