From 09412e6be85b0229e7dea73fa536d6bfdf42b19d Mon Sep 17 00:00:00 2001 From: Dan Donovan Date: Tue, 16 Jan 2007 20:55:27 +0000 Subject: [PATCH] Some Kanji Timer improvements Originally committed to SVN as r808. --- aegisub/dialog_kanji_timer.cpp | 61 +++++++++++++++++++++------------- aegisub/dialog_kanji_timer.h | 2 ++ aegisub/options.cpp | 2 ++ 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/aegisub/dialog_kanji_timer.cpp b/aegisub/dialog_kanji_timer.cpp index 752f0169f..9026d58bd 100644 --- a/aegisub/dialog_kanji_timer.cpp +++ b/aegisub/dialog_kanji_timer.cpp @@ -34,8 +34,8 @@ // #define MIN(a,b) ((aSetValue(Options.AsBool(_T("kanji timer interpolation"))); //Static Text labels for source/dest wxStaticText *SourceLabel = new wxStaticText(this,-1,_("Source: ")); @@ -166,6 +167,8 @@ BEGIN_EVENT_TABLE(DialogKanjiTimer,wxDialog) END_EVENT_TABLE() void DialogKanjiTimer::OnClose(wxCommandEvent &event) { + Options.SetBool(_T("kanji timer interpolation"),Interpolate->IsChecked()); + Options.Save(); Close(); } @@ -358,13 +361,13 @@ void DialogKanjiTimer::OnAccept(wxCommandEvent &event) { } } void DialogKanjiTimer::OnKeyDown(wxKeyEvent &event) { - int KeyCode = event.GetKeyCode(); - switch(KeyCode) { + switch(event.GetKeyCode()) { case WXK_ESCAPE : - this->EndModal(0); + //this->EndModal(0); + OnClose((wxCommandEvent)NULL); break; case WXK_BACK : - this->OnUnlink((wxCommandEvent)NULL); + OnUnlink((wxCommandEvent)NULL); break; case WXK_RIGHT : //inc dest selection len if (DestText->GetStringSelection().Len()!=DestText->GetValue().Len()) @@ -439,7 +442,7 @@ void DialogKanjiTimer::SetSelected() { } } } - +#ifdef KANA_SEARCH_DISTANCE if (KANA_SEARCH_DISTANCE>0 && !foundit) { //Try some interpolation for kanji. If we find a hiragana we know after this, // then we may be able to figure this one out. @@ -460,7 +463,8 @@ void DialogKanjiTimer::SetSelected() { } } } - +#endif +#ifdef ROMAJI_SEARCH_DISTANCE if (ROMAJI_SEARCH_DISTANCE>0 && !foundit) { wxString Destext = DestText->GetValue(); wxString NextSGroup, trimmed; @@ -470,31 +474,40 @@ void DialogKanjiTimer::SetSelected() { // and not our current pos, so subtract 1 from it for end. int end = MIN(RegroupTotalLen,start+ROMAJI_SEARCH_DISTANCE-1); - for(int i=start;i!=end;i++) { + for(int i=start;!foundit&&i!=end;i++) { NextSGroup = RegroupSourceText[i]; trimmed = NextSGroup.Trim(false).Trim(true); NextSGroup = RegroupSourceText[i]; - for(std::list::iterator iter = kt->entries.begin(); iter != kt->entries.end(); iter++) { - KanaEntry ke = *iter; - if (trimmed==ke.hepburn) { - int foundhira = Destext.Find(ke.hiragana); - int foundkata = Destext.Find(ke.katakana); - int foundat; - if (foundhira>0&&foundkata>0) foundat=MIN(foundhira,foundkata); - else if (foundhira>0) foundat=foundhira; - else foundat = foundkata; //-1 is fine, the if below checks that + if ((NextSGroup.Len()>0||i==start) && NextSGroup.EndsWith(_T(" ")) && Destext.at(1)==' ') { + SourceText->SetSelection(0,highlight); + DestText->SetSelection(0,1); + foundit=true; + } + else { + for(std::list::iterator iter = kt->entries.begin(); iter != kt->entries.end(); iter++) { + KanaEntry ke = *iter; + if (trimmed==ke.hepburn) { + int foundhira = Destext.Find(ke.hiragana); + int foundkata = Destext.Find(ke.katakana); + int foundat; + if (foundhira>0&&foundkata>0) foundat=MIN(foundhira,foundkata); + else if (foundhira>0) foundat=foundhira; + else foundat = foundkata; //-1 is fine - if (foundat>0 && foundat<=ROMAJI_SEARCH_DISTANCE) { - SourceText->SetSelection(0,highlight); - DestText->SetSelection(0,foundat); - return; + if (foundat>0 && foundat<=ROMAJI_SEARCH_DISTANCE) { + SourceText->SetSelection(0,highlight); + DestText->SetSelection(0,foundat); + foundit=true; + } + break; } - } - }//end kana search + }//end kana search + } highlight += NextSGroup.Len(); } }//end romaji interpolation +#endif } if (!foundit&&DestText->GetValue().Len()!=0&&DestText->GetStringSelection().Len()==0) DestText->SetSelection(0,1); diff --git a/aegisub/dialog_kanji_timer.h b/aegisub/dialog_kanji_timer.h index 994983ed0..ed330f201 100644 --- a/aegisub/dialog_kanji_timer.h +++ b/aegisub/dialog_kanji_timer.h @@ -43,6 +43,8 @@ #include #include #include +#include +#include "options.h" #include "kana_table.h" diff --git a/aegisub/options.cpp b/aegisub/options.cpp index 775783bd7..87c94f8ca 100644 --- a/aegisub/options.cpp +++ b/aegisub/options.cpp @@ -322,6 +322,8 @@ void OptionsManager::LoadDefaults() { SetText(_T("Last open timecodes path"),_T("")); SetText(_T("Last open keyframes path"),_T("")); SetText(_T("Last open automation path"),_T("")); + + SetBool(_T("kanji timer interpolation"),true); }