forked from mia/Aegisub
Make AssFile::Attachments a vector
This commit is contained in:
parent
bacbd8c2bf
commit
7d08dca912
5 changed files with 18 additions and 42 deletions
|
@ -22,7 +22,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
/// @class AssAttachment
|
/// @class AssAttachment
|
||||||
class AssAttachment : public AssEntry, public AssEntryListHook {
|
class AssAttachment : public AssEntry {
|
||||||
/// ASS uuencoded entry data, including header.
|
/// ASS uuencoded entry data, including header.
|
||||||
boost::flyweight<std::string> entry_data;
|
boost::flyweight<std::string> entry_data;
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ AssFile::AssFile() { }
|
||||||
AssFile::~AssFile() {
|
AssFile::~AssFile() {
|
||||||
Styles.clear_and_dispose([](AssStyle *e) { delete e; });
|
Styles.clear_and_dispose([](AssStyle *e) { delete e; });
|
||||||
Events.clear_and_dispose([](AssDialogue *e) { delete e; });
|
Events.clear_and_dispose([](AssDialogue *e) { delete e; });
|
||||||
Attachments.clear_and_dispose([](AssAttachment *e) { delete e; });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssFile::LoadDefault(bool include_dialogue_line) {
|
void AssFile::LoadDefault(bool include_dialogue_line) {
|
||||||
|
@ -56,6 +55,7 @@ void AssFile::LoadDefault(bool include_dialogue_line) {
|
||||||
|
|
||||||
AssFile::AssFile(const AssFile &from)
|
AssFile::AssFile(const AssFile &from)
|
||||||
: Info(from.Info)
|
: Info(from.Info)
|
||||||
|
, Attachments(from.Attachments)
|
||||||
{
|
{
|
||||||
Styles.clone_from(from.Styles,
|
Styles.clone_from(from.Styles,
|
||||||
[](AssStyle const& e) { return new AssStyle(e); },
|
[](AssStyle const& e) { return new AssStyle(e); },
|
||||||
|
@ -63,9 +63,6 @@ AssFile::AssFile(const AssFile &from)
|
||||||
Events.clone_from(from.Events,
|
Events.clone_from(from.Events,
|
||||||
[](AssDialogue const& e) { return new AssDialogue(e); },
|
[](AssDialogue const& e) { return new AssDialogue(e); },
|
||||||
[](AssDialogue *e) { delete e; });
|
[](AssDialogue *e) { delete e; });
|
||||||
Attachments.clone_from(from.Attachments,
|
|
||||||
[](AssAttachment const & e) { return new AssAttachment(e); },
|
|
||||||
[](AssAttachment *e) { delete e; });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssFile::swap(AssFile& from) throw() {
|
void AssFile::swap(AssFile& from) throw() {
|
||||||
|
@ -87,7 +84,7 @@ void AssFile::InsertAttachment(agi::fs::path const& filename) {
|
||||||
if (ext == ".ttf" || ext == ".ttc" || ext == ".pfb")
|
if (ext == ".ttf" || ext == ".ttc" || ext == ".pfb")
|
||||||
group = AssEntryGroup::FONT;
|
group = AssEntryGroup::FONT;
|
||||||
|
|
||||||
Attachments.push_back(*new AssAttachment(filename, group));
|
Attachments.emplace_back(filename, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string AssFile::GetScriptInfo(std::string const& key) const {
|
std::string AssFile::GetScriptInfo(std::string const& key) const {
|
||||||
|
|
|
@ -65,7 +65,7 @@ public:
|
||||||
std::vector<AssInfo> Info;
|
std::vector<AssInfo> Info;
|
||||||
EntryList<AssStyle> Styles;
|
EntryList<AssStyle> Styles;
|
||||||
EntryList<AssDialogue> Events;
|
EntryList<AssDialogue> Events;
|
||||||
EntryList<AssAttachment> Attachments;
|
std::vector<AssAttachment> Attachments;
|
||||||
|
|
||||||
AssFile();
|
AssFile();
|
||||||
AssFile(const AssFile &from);
|
AssFile(const AssFile &from);
|
||||||
|
|
|
@ -102,7 +102,6 @@ void DialogAttachments::UpdateList() {
|
||||||
listView->InsertItem(row, to_wx(attach.GetFileName(true)));
|
listView->InsertItem(row, to_wx(attach.GetFileName(true)));
|
||||||
listView->SetItem(row, 1, PrettySize(attach.GetSize()));
|
listView->SetItem(row, 1, PrettySize(attach.GetSize()));
|
||||||
listView->SetItem(row, 2, to_wx(attach.GroupHeader()));
|
listView->SetItem(row, 2, to_wx(attach.GroupHeader()));
|
||||||
listView->SetItemPtrData(row, wxPtrToUInt(&attach));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +152,7 @@ void DialogAttachments::OnExtract(wxCommandEvent &) {
|
||||||
path = SaveFileSelector(
|
path = SaveFileSelector(
|
||||||
_("Select the path to save the file to:"),
|
_("Select the path to save the file to:"),
|
||||||
"Path/Fonts Collector Destination",
|
"Path/Fonts Collector Destination",
|
||||||
((AssAttachment*)wxUIntToPtr(listView->GetItemData(i)))->GetFileName(),
|
ass->Attachments[i].GetFileName(),
|
||||||
".ttf", "Font Files (*.ttf)|*.ttf",
|
".ttf", "Font Files (*.ttf)|*.ttf",
|
||||||
this);
|
this);
|
||||||
fullPath = true;
|
fullPath = true;
|
||||||
|
@ -162,20 +161,16 @@ void DialogAttachments::OnExtract(wxCommandEvent &) {
|
||||||
|
|
||||||
// Loop through items in list
|
// Loop through items in list
|
||||||
while (i != -1) {
|
while (i != -1) {
|
||||||
AssAttachment *attach = (AssAttachment*)wxUIntToPtr(listView->GetItemData(i));
|
auto& attach = ass->Attachments[i];
|
||||||
attach->Extract(fullPath ? path : path/attach->GetFileName());
|
attach.Extract(fullPath ? path : path/attach.GetFileName());
|
||||||
i = listView->GetNextSelected(i);
|
i = listView->GetNextSelected(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogAttachments::OnDelete(wxCommandEvent &) {
|
void DialogAttachments::OnDelete(wxCommandEvent &) {
|
||||||
auto i = listView->GetFirstSelected();
|
size_t removed = 0;
|
||||||
if (i == -1) return;
|
for (auto i = listView->GetFirstSelected(); i != -1; i = listView->GetNextSelected(i))
|
||||||
|
ass->Attachments.erase(ass->Attachments.begin() + i - removed++);
|
||||||
while (i != -1) {
|
|
||||||
delete (AssEntry*)wxUIntToPtr(listView->GetItemData(i));
|
|
||||||
i = listView->GetNextSelected(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
ass->Commit(_("remove attachment"), AssFile::COMMIT_ATTACHMENT);
|
ass->Commit(_("remove attachment"), AssFile::COMMIT_ATTACHMENT);
|
||||||
|
|
||||||
|
|
|
@ -54,20 +54,21 @@ namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SubsController::UndoInfo {
|
struct SubsController::UndoInfo {
|
||||||
|
wxString undo_description;
|
||||||
|
int commit_id;
|
||||||
|
|
||||||
std::vector<std::pair<std::string, std::string>> script_info;
|
std::vector<std::pair<std::string, std::string>> script_info;
|
||||||
std::vector<AssStyle> styles;
|
std::vector<AssStyle> styles;
|
||||||
std::vector<AssDialogueBase> events;
|
std::vector<AssDialogueBase> events;
|
||||||
std::vector<AssAttachment> graphics;
|
std::vector<AssAttachment> attachments;
|
||||||
std::vector<AssAttachment> fonts;
|
|
||||||
|
|
||||||
mutable std::vector<int> selection;
|
mutable std::vector<int> selection;
|
||||||
int active_line_id = 0;
|
int active_line_id = 0;
|
||||||
|
|
||||||
wxString undo_description;
|
|
||||||
int commit_id;
|
|
||||||
|
|
||||||
UndoInfo(const agi::Context *c, wxString const& d, int commit_id)
|
UndoInfo(const agi::Context *c, wxString const& d, int commit_id)
|
||||||
: undo_description(d), commit_id(commit_id)
|
: undo_description(d)
|
||||||
|
, commit_id(commit_id)
|
||||||
|
, attachments(c->ass->Attachments)
|
||||||
{
|
{
|
||||||
script_info.reserve(c->ass->Info.size());
|
script_info.reserve(c->ass->Info.size());
|
||||||
for (auto const& info : c->ass->Info)
|
for (auto const& info : c->ass->Info)
|
||||||
|
@ -79,20 +80,6 @@ struct SubsController::UndoInfo {
|
||||||
events.reserve(c->ass->Events.size());
|
events.reserve(c->ass->Events.size());
|
||||||
events.assign(c->ass->Events.begin(), c->ass->Events.end());
|
events.assign(c->ass->Events.begin(), c->ass->Events.end());
|
||||||
|
|
||||||
for (auto const& line : c->ass->Attachments) {
|
|
||||||
switch (line.Group()) {
|
|
||||||
case AssEntryGroup::FONT:
|
|
||||||
fonts.push_back(line);
|
|
||||||
break;
|
|
||||||
case AssEntryGroup::GRAPHIC:
|
|
||||||
graphics.push_back(line);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
assert(false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateActiveLine(c);
|
UpdateActiveLine(c);
|
||||||
UpdateSelection(c);
|
UpdateSelection(c);
|
||||||
}
|
}
|
||||||
|
@ -111,10 +98,7 @@ struct SubsController::UndoInfo {
|
||||||
c->ass->Info.push_back(*new AssInfo(info.first, info.second));
|
c->ass->Info.push_back(*new AssInfo(info.first, info.second));
|
||||||
for (auto const& style : styles)
|
for (auto const& style : styles)
|
||||||
c->ass->Styles.push_back(*new AssStyle(style));
|
c->ass->Styles.push_back(*new AssStyle(style));
|
||||||
for (auto const& attachment : fonts)
|
c->ass->Attachments = attachments;
|
||||||
c->ass->Attachments.push_back(*new AssAttachment(attachment));
|
|
||||||
for (auto const& attachment : graphics)
|
|
||||||
c->ass->Attachments.push_back(*new AssAttachment(attachment));
|
|
||||||
for (auto const& event : events) {
|
for (auto const& event : events) {
|
||||||
auto copy = new AssDialogue(event);
|
auto copy = new AssDialogue(event);
|
||||||
c->ass->Events.push_back(*copy);
|
c->ass->Events.push_back(*copy);
|
||||||
|
|
Loading…
Reference in a new issue