Remove empty attachments sections when the Attachments dialogue is closed. Updates #1212.
Originally committed to SVN as r4593.
This commit is contained in:
parent
e2a42ccb6c
commit
eec24ce562
1 changed files with 44 additions and 0 deletions
|
@ -129,6 +129,50 @@ void DialogAttachments::UpdateList() {
|
|||
/// @brief Destructor
|
||||
///
|
||||
DialogAttachments::~DialogAttachments() {
|
||||
|
||||
// Remove empty attachments sections from the file
|
||||
|
||||
std::list<AssEntry*>::iterator cur = AssFile::top->Line.end();
|
||||
--cur;
|
||||
|
||||
bool found_attachments = false;
|
||||
bool removed_any = false;
|
||||
wxString last_section_name;
|
||||
|
||||
while (cur != AssFile::top->Line.begin()) {
|
||||
if (!((*cur)->group == L"[Fonts]" || (*cur)->group == L"[Graphics]"))
|
||||
break;
|
||||
|
||||
if ((*cur)->GetEntryData() == L"[Fonts]" || (*cur)->GetEntryData() == L"[Graphics]") {
|
||||
if (found_attachments) continue;
|
||||
// found section heading with no attachments in, remove it
|
||||
wxString delgroup = (*cur)->group;
|
||||
std::list<AssEntry*>::iterator di = cur;
|
||||
while (++di != AssFile::top->Line.end() && (*di)->group == delgroup) {
|
||||
delete *di;
|
||||
AssFile::top->Line.erase(di);
|
||||
di = cur;
|
||||
}
|
||||
di = cur;
|
||||
--cur;
|
||||
delete *di;
|
||||
AssFile::top->Line.erase(di);
|
||||
removed_any = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (last_section_name != (*cur)->group)
|
||||
found_attachments = false;
|
||||
if (dynamic_cast<AssAttachment*>(*cur) != 0)
|
||||
found_attachments = true;
|
||||
last_section_name = (*cur)->group;
|
||||
|
||||
--cur;
|
||||
}
|
||||
|
||||
if (removed_any) {
|
||||
AssFile::top->FlagAsModified(_("remove empty attachments sections"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue