Also remove empty attachment sections not at the end of the file
Originally committed to SVN as r6043.
This commit is contained in:
parent
921f6c3bcf
commit
ef32c75609
1 changed files with 21 additions and 36 deletions
|
@ -91,8 +91,7 @@ DialogAttachments::DialogAttachments(wxWindow *parent, AssFile *ass)
|
||||||
wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
|
wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
|
||||||
mainSizer->Add(listView,1,wxTOP | wxLEFT | wxRIGHT | wxEXPAND,5);
|
mainSizer->Add(listView,1,wxTOP | wxLEFT | wxRIGHT | wxEXPAND,5);
|
||||||
mainSizer->Add(buttonSizer,0,wxALL | wxEXPAND,5);
|
mainSizer->Add(buttonSizer,0,wxALL | wxEXPAND,5);
|
||||||
mainSizer->SetSizeHints(this);
|
SetSizerAndFit(mainSizer);
|
||||||
SetSizer(mainSizer);
|
|
||||||
CenterOnParent();
|
CenterOnParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,44 +210,30 @@ void DialogAttachments::OnDelete(wxCommandEvent &) {
|
||||||
i = listView->GetNextSelected(i);
|
i = listView->GetNextSelected(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove empty attachment sections at the end of the file
|
// Remove empty attachment sections in the file
|
||||||
std::list<AssEntry*>::iterator cur = ass->Line.end();
|
for (std::list<AssEntry*>::iterator it = ass->Line.begin(); it != ass->Line.end(); ) {
|
||||||
--cur;
|
if ((*it)->GetType() == ENTRY_BASE && ((*it)->group == "[Fonts]" || (*it)->group == "[Graphics]")) {
|
||||||
|
wxString group = (*it)->group;
|
||||||
|
std::list<AssEntry*>::iterator header = it;
|
||||||
|
|
||||||
bool found_attachments = false;
|
bool has_attachments = false;
|
||||||
wxString last_section_name;
|
for (++it; it != ass->Line.end() && (*it)->group == group; ++it) {
|
||||||
|
if ((*it)->GetType() == ENTRY_ATTACHMENT) {
|
||||||
while (cur != ass->Line.begin()) {
|
has_attachments = true;
|
||||||
if (!((*cur)->group == "[Fonts]" || (*cur)->group == "[Graphics]"))
|
break;
|
||||||
break;
|
}
|
||||||
|
|
||||||
if ((*cur)->GetEntryData() == "[Fonts]" || (*cur)->GetEntryData() == "[Graphics]") {
|
|
||||||
if (found_attachments) {
|
|
||||||
--cur;
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
// found section heading with no attachments in, remove it
|
|
||||||
wxString delgroup = (*cur)->group;
|
// Empty group found, delete it
|
||||||
std::list<AssEntry*>::iterator di = cur;
|
if (!has_attachments) {
|
||||||
while (++di != ass->Line.end() && (*di)->group == delgroup) {
|
while (header != it) {
|
||||||
delete *di;
|
delete *header;
|
||||||
ass->Line.erase(di);
|
ass->Line.erase(header++);
|
||||||
di = cur;
|
}
|
||||||
}
|
}
|
||||||
di = cur;
|
|
||||||
--cur;
|
|
||||||
delete *di;
|
|
||||||
ass->Line.erase(di);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (last_section_name != (*cur)->group)
|
++it;
|
||||||
found_attachments = false;
|
|
||||||
if (dynamic_cast<AssAttachment*>(*cur) != 0)
|
|
||||||
found_attachments = true;
|
|
||||||
last_section_name = (*cur)->group;
|
|
||||||
|
|
||||||
--cur;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ass->Commit(_("remove attachment"), AssFile::COMMIT_ATTACHMENT);
|
ass->Commit(_("remove attachment"), AssFile::COMMIT_ATTACHMENT);
|
||||||
|
|
Loading…
Reference in a new issue