Remove empty attachments sections when the Attachments dialogue is closed. Updates #1212.

Originally committed to SVN as r4593.
This commit is contained in:
Niels Martin Hansen 2010-06-24 19:14:13 +00:00
parent e2a42ccb6c
commit eec24ce562

View file

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