diff --git a/core/subs_edit_ctrl.cpp b/core/subs_edit_ctrl.cpp index 4076685c3..934ef4e1d 100644 --- a/core/subs_edit_ctrl.cpp +++ b/core/subs_edit_ctrl.cpp @@ -404,6 +404,7 @@ BEGIN_EVENT_TABLE(SubsTextEditCtrl,wxScintilla) EVT_MENU(EDIT_MENU_SELECT_ALL,SubsTextEditCtrl::OnSelectAll) EVT_MENU(EDIT_MENU_ADD_TO_DICT,SubsTextEditCtrl::OnAddToDictionary) EVT_MENU_RANGE(EDIT_MENU_SUGGESTIONS,EDIT_MENU_SUGGESTIONS+16,SubsTextEditCtrl::OnUseSuggestion) + EVT_MENU_RANGE(EDIT_MENU_THESAURUS_SUGS,EDIT_MENU_THESAURUS_SUGS+2000,SubsTextEditCtrl::OnUseThesaurusSuggestion) END_EVENT_TABLE() @@ -461,16 +462,43 @@ void SubsTextEditCtrl::ShowPopupMenu(int activePos) { // Thesaurus if (thesaurus) { - // Get suggestions + // Get results + ThesaurusEntryArray result; + thesaurus->Lookup(currentWord,result); + + // Compile list thesSugs.Clear(); - thesSugs = thesaurus->GetSuggestions(currentWord); + for (unsigned int i=0;iAppend(EDIT_MENU_THESAURUS_SUGS+curThesEntry,result[i].words[j]); + curThesEntry++; + } + + // Insert submenu + menu.AppendSubMenu(subMenu,result[i].name); + } + } // No suggestions - if (!nSugs) menu.Append(EDIT_MENU_THESAURUS,_("No thesaurus suggestions"))->Enable(false); + if (!result.size()) menu.Append(EDIT_MENU_THESAURUS,_("No thesaurus suggestions"))->Enable(false); // Separator menu.AppendSeparator(); @@ -635,3 +663,24 @@ void SubsTextEditCtrl::OnUseSuggestion(wxCommandEvent &event) { SetSelection(start,start+suggestion.Length()); SetFocus(); } + + + +//////////////////////////// +// Use thesaurus suggestion +void SubsTextEditCtrl::OnUseThesaurusSuggestion(wxCommandEvent &event) { + // Get suggestion + wxString suggestion = thesSugs[event.GetId()-EDIT_MENU_THESAURUS_SUGS]; + + // Get boundaries of text being replaced + int start,end; + GetBoundsOfWordAtPosition(currentWordPos,start,end); + + // Replace + wxString text = GetText(); + SetText(text.Left(MAX(0,start)) + suggestion + text.Mid(end+1)); + + // Set selection + SetSelection(start,start+suggestion.Length()); + SetFocus(); +} diff --git a/core/subs_edit_ctrl.h b/core/subs_edit_ctrl.h index 34155c893..e5c9ead3d 100644 --- a/core/subs_edit_ctrl.h +++ b/core/subs_edit_ctrl.h @@ -79,6 +79,7 @@ private: void OnSelectAll(wxCommandEvent &event); void OnAddToDictionary(wxCommandEvent &event); void OnUseSuggestion(wxCommandEvent &event); + void OnUseThesaurusSuggestion(wxCommandEvent &event); public: SubsEditBox *control; diff --git a/core/thesaurus.h b/core/thesaurus.h index 0bbb725c1..d152123a0 100644 --- a/core/thesaurus.h +++ b/core/thesaurus.h @@ -40,6 +40,21 @@ /////////// // Headers #include +#include + + +///////////////////////// +// Thesaurus entry class +class ThesaurusEntry { +public: + wxString name; + wxArrayString words; +}; + + +///////////////////////// +// Thesaurus entry array +typedef std::vector ThesaurusEntryArray; /////////////////////// @@ -51,7 +66,7 @@ public: Thesaurus() {} virtual ~Thesaurus() {} - virtual wxArrayString GetSuggestions(wxString word)=0; + virtual void Lookup(wxString word,ThesaurusEntryArray &result)=0; virtual wxArrayString GetLanguageList()=0; virtual void SetLanguage(wxString language)=0; }; diff --git a/core/thesaurus_myspell.cpp b/core/thesaurus_myspell.cpp index b5382419d..177421075 100644 --- a/core/thesaurus_myspell.cpp +++ b/core/thesaurus_myspell.cpp @@ -60,29 +60,25 @@ MySpellThesaurus::~MySpellThesaurus() { /////////////////// // Get suggestions -wxArrayString MySpellThesaurus::GetSuggestions(wxString word) { - // Array - wxArrayString suggestions; +void MySpellThesaurus::Lookup(wxString word,ThesaurusEntryArray &result) { + // Loaded? + if (!mythes) return; - // Get suggestions - if (mythes) { - // Grab raw from MyThes - mentry *me; - wxCharBuffer buf = word.mb_str(wxConvUTF8); - int n = mythes->Lookup(buf,strlen(buf),&me); + // Grab raw from MyThes + mentry *me; + wxCharBuffer buf = word.Lower().mb_str(wxConvUTF8); + int n = mythes->Lookup(buf,strlen(buf),&me); - // Each entry - for (int i=0;iCleanUpAfterLookup(&me,n); + // Each entry + for (int i=0;iCleanUpAfterLookup(&me,n); } diff --git a/core/thesaurus_myspell.h b/core/thesaurus_myspell.h index f817acab7..ed478d855 100644 --- a/core/thesaurus_myspell.h +++ b/core/thesaurus_myspell.h @@ -57,7 +57,7 @@ public: MySpellThesaurus(); ~MySpellThesaurus(); - wxArrayString GetSuggestions(wxString word); + void Lookup(wxString word,ThesaurusEntryArray &result); wxArrayString GetLanguageList(); void SetLanguage(wxString language); };