Remove time-consuming reparsing of the line in VisualTool::SetOverride

Originally committed to SVN as r4430.
This commit is contained in:
Thomas Goyne 2010-06-04 03:08:04 +00:00
parent 88f6bca9d7
commit 38d922c57a
4 changed files with 12 additions and 7 deletions

View file

@ -668,7 +668,7 @@ void AssDialogue::ConvertTagsToSRT () {
ClearBlocks();
}
/// @brief Updates text from tags
/// @brief Updates text from tags
void AssDialogue::UpdateText () {
using std::vector;
Text = _T("");

View file

@ -177,6 +177,7 @@ public:
ASS_BlockType GetType() { return BLOCK_OVERRIDE; }
wxString GetText();
void ParseTags(); // Parses tags
void AddTag(wxString const& tag);
/// Type of callback function passed to ProcessParameters
typedef void (*ProcessParametersCallback)(wxString,int,AssOverrideParameter*,void *);

View file

@ -131,6 +131,11 @@ void AssDialogueBlockOverride::ParseTags () {
curTag = _T("\\");
}
}
void AssDialogueBlockOverride::AddTag(wxString const& tag) {
AssOverrideTag *newTag = new AssOverrideTag;
newTag->SetText(tag);
Tags.push_back(newTag);
}
/// @brief Get Text representation
/// @return

View file

@ -776,23 +776,22 @@ void VisualTool<FeatureType>::SetOverride(AssDialogue* line, wxString tag, wxStr
// Get current block as plain or override
AssDialogueBlockPlain *plain = dynamic_cast<AssDialogueBlockPlain*>(block);
AssDialogueBlockOverride *ovr = dynamic_cast<AssDialogueBlockOverride*>(block);
assert(dynamic_cast<AssDialogueBlockDrawing*>(block) == NULL);
if (plain) {
line->Text = L"{" + insert + L"}" + line->Text;
}
else if (ovr) {
ovr->text += insert;
ovr->ParseTags();
// Remove old of same
for (size_t i = 0; i < ovr->Tags.size() - 1; i++) {
wxString name = ovr->Tags.at(i)->Name;
for (size_t i = 0; i < ovr->Tags.size(); i++) {
wxString name = ovr->Tags[i]->Name;
if (tag == name || removeTag == name) {
delete ovr->Tags.at(i);
delete ovr->Tags[i];
ovr->Tags.erase(ovr->Tags.begin() + i);
i--;
}
}
ovr->AddTag(insert);
line->UpdateText();
}