Kanji timer now changes all lines at once on dialogue close (for easier undo)

Originally committed to SVN as r892.
This commit is contained in:
Dan Donovan 2007-01-25 22:47:29 +00:00
parent 297dbd74b8
commit a29fcb2d47
2 changed files with 24 additions and 7 deletions

View File

@ -170,6 +170,17 @@ END_EVENT_TABLE()
void DialogKanjiTimer::OnClose(wxCommandEvent &event) { void DialogKanjiTimer::OnClose(wxCommandEvent &event) {
Options.SetBool(_T("kanji timer interpolation"),Interpolate->IsChecked()); Options.SetBool(_T("kanji timer interpolation"),Interpolate->IsChecked());
Options.Save(); Options.Save();
while(LinesToChange.empty()==false) {
std::pair<int,wxString> p = LinesToChange.back();
LinesToChange.pop_back();
AssDialogue *line = grid->GetDialogue(p.first);
line->Text = p.second;
}
grid->ass->FlagAsModified();
grid->CommitChanges();
LinesToChange.clear();
Close(); Close();
} }
@ -185,6 +196,7 @@ void DialogKanjiTimer::OnStart(wxCommandEvent &event) {
OnSkipSource(blank); OnSkipSource(blank);
DestText->SetFocus(); DestText->SetFocus();
} }
LinesToChange.clear();
} }
void DialogKanjiTimer::OnLink(wxCommandEvent &event) { void DialogKanjiTimer::OnLink(wxCommandEvent &event) {
int sourceLen = SourceText->GetStringSelection().Len(); int sourceLen = SourceText->GetStringSelection().Len();
@ -318,6 +330,8 @@ void DialogKanjiTimer::OnSkipDest(wxCommandEvent &event) {
void DialogKanjiTimer::OnGoBack(wxCommandEvent &event) { void DialogKanjiTimer::OnGoBack(wxCommandEvent &event) {
DestIndex-=2; DestIndex-=2;
SourceIndex-=2; SourceIndex-=2;
if (LinesToChange.empty()==false)
LinesToChange.pop_back(); //If we go back, then take out the modified line we saved.
wxCommandEvent tmpEvent; wxCommandEvent tmpEvent;
OnSkipDest(tmpEvent); OnSkipDest(tmpEvent);
OnSkipSource(tmpEvent); OnSkipSource(tmpEvent);
@ -330,7 +344,8 @@ void DialogKanjiTimer::OnAccept(wxCommandEvent &event) {
else { else {
wxString OutputText = TextBeforeKaraoke; wxString OutputText = TextBeforeKaraoke;
wxString ThisText; wxString ThisText;
AssDialogue *line = grid->GetDialogue(ListIndexFromStyleandIndex(DestStyle->GetValue(), DestIndex-1)); int diagindex = ListIndexFromStyleandIndex(DestStyle->GetValue(), DestIndex-1);
//AssDialogue *line = grid->GetDialogue(diagindex);
int ItemCount = GroupsList->GetItemCount(); int ItemCount = GroupsList->GetItemCount();
int SourceLength; int SourceLength;
int WorkingK = 0; int WorkingK = 0;
@ -342,7 +357,7 @@ void DialogKanjiTimer::OnAccept(wxCommandEvent &event) {
if (RegroupSourceText[SourceIndex].Len() == 0) { if (RegroupSourceText[SourceIndex].Len() == 0) {
//Karaoke block w/o text that is NOT in the middle of a group, just copy it over //Karaoke block w/o text that is NOT in the middle of a group, just copy it over
// since we can't figure out if it should go to the previous or the next group // since we can't figure out if it should go to the previous or the next group
OutputText = wxString::Format(_("%s{\\k%i}"),OutputText,RegroupSourceKLengths[SourceIndex]); OutputText = wxString::Format(_("%s{\\k%i}"),OutputText.c_str(),RegroupSourceKLengths[SourceIndex]);
SourceIndex++; SourceIndex++;
} }
@ -351,13 +366,15 @@ void DialogKanjiTimer::OnAccept(wxCommandEvent &event) {
SourceLength -= (RegroupSourceText[SourceIndex]).Len(); SourceLength -= (RegroupSourceText[SourceIndex]).Len();
SourceIndex++; SourceIndex++;
} }
OutputText = wxString::Format(_("%s{\\k%i}%s"),OutputText,WorkingK,RegroupGroups[(index<<1)+1]); OutputText = wxString::Format(_("%s{\\k%i}%s"),OutputText.c_str(),WorkingK,(RegroupGroups[(index<<1)+1]).c_str());
WorkingK = 0; WorkingK = 0;
} }
line->Text = OutputText; std::pair<int,wxString> ins(diagindex,OutputText);
grid->ass->FlagAsModified(); LinesToChange.push_back(ins);
grid->CommitChanges(); //line->Text = OutputText;
//grid->ass->FlagAsModified();
//grid->CommitChanges();
wxCommandEvent evt; wxCommandEvent evt;
OnSkipDest(evt); OnSkipDest(evt);
@ -368,7 +385,6 @@ void DialogKanjiTimer::OnKeyDown(wxKeyEvent &event) {
wxCommandEvent evt; wxCommandEvent evt;
switch(event.GetKeyCode()) { switch(event.GetKeyCode()) {
case WXK_ESCAPE : case WXK_ESCAPE :
//this->EndModal(0);
OnClose(evt); OnClose(evt);
break; break;
case WXK_BACK : case WXK_BACK :

View File

@ -67,6 +67,7 @@ private:
wxString TextBeforeKaraoke; wxString TextBeforeKaraoke;
wxString *RegroupSourceText, *RegroupGroups; wxString *RegroupSourceText, *RegroupGroups;
std::vector<std::pair<int,wxString>> LinesToChange;
int *RegroupSourceKLengths; int *RegroupSourceKLengths;
int RegroupSourceSelected, RegroupTotalLen; int RegroupSourceSelected, RegroupTotalLen;
int SourceIndex, DestIndex; int SourceIndex, DestIndex;