Implemented setting of language for Thesaurus

Originally committed to SVN as r671.
This commit is contained in:
Rodrigo Braz Monteiro 2007-01-01 05:15:05 +00:00
parent 166e7cba7c
commit bac9e14fc4
4 changed files with 80 additions and 11 deletions

View File

@ -95,7 +95,7 @@ void OptionsManager::LoadDefaults() {
// Dictionary
SetText(_T("Dictionaries path"),_T("dictionaries"));
SetText(_T("Dictionary language"),_T("en_US"));
SetText(_T("Spell checker language"),_T("en_US"));
SetText(_T("Thesaurus language"),_T("en_US"));
// Video Options

View File

@ -41,6 +41,7 @@
#include <hunspell/hunspell.hxx>
#include <wx/wxprec.h>
#include <wx/dir.h>
#include <wx/filename.h>
#include "spellchecker_hunspell.h"
#include "main.h"
#include "utils.h"
@ -52,7 +53,7 @@
HunspellSpellChecker::HunspellSpellChecker() {
hunspell = NULL;
conv = NULL;
SetLanguage(Options.AsText(_T("Dictionary Language")));
SetLanguage(Options.AsText(_T("Spell checker Language")));
}

View File

@ -515,7 +515,7 @@ void SubsTextEditCtrl::ShowPopupMenu(int activePos) {
wxArrayString langs = spellchecker->GetLanguageList(); // This probably should be cached...
if (langs.Count()) {
// Current language
wxString curLang = Options.AsText(_T("Dictionary Language"));
wxString curLang = Options.AsText(_T("Spell checker language"));
// Languages
wxMenu *languageMenu = new wxMenu();
@ -526,12 +526,12 @@ void SubsTextEditCtrl::ShowPopupMenu(int activePos) {
info = wxLocale::FindLanguageInfo(langs[i]);
if (info) name = info->Description;
else name = langs[i];
cur = languageMenu->AppendRadioItem(EDIT_MENU_DIC_LANGS+i,name);
cur = languageMenu->AppendCheckItem(EDIT_MENU_DIC_LANGS+i,name);
if (langs[i] == curLang) cur->Check();
}
menu.AppendSubMenu(languageMenu,_("Language"));
menu.AppendSubMenu(languageMenu,_("Spell checker language"));
}
else menu.Append(EDIT_MENU_DIC_LANGUAGE,_("No Dictionaries Available"))->Enable(false);
else menu.Append(EDIT_MENU_DIC_LANGUAGE,_("No dictionaries available"))->Enable(false);
menu.AppendSeparator();
}
@ -588,6 +588,28 @@ void SubsTextEditCtrl::ShowPopupMenu(int activePos) {
// No suggestions
if (!result.size()) menu.Append(EDIT_MENU_THESAURUS,_("No thesaurus suggestions"))->Enable(false);
// Language list
wxArrayString langs = thesaurus->GetLanguageList(); // This probably should be cached...
if (langs.Count()) {
// Current language
wxString curLang = Options.AsText(_T("Thesaurus language"));
// Languages
wxMenu *languageMenu = new wxMenu();
wxMenuItem *cur;
wxString name;
const wxLanguageInfo *info;
for (unsigned int i=0;i<langs.Count();i++) {
info = wxLocale::FindLanguageInfo(langs[i].Mid(3));
if (info) name = info->Description;
else name = langs[i];
cur = languageMenu->AppendCheckItem(EDIT_MENU_THES_LANGS+i,name);
if (langs[i].Mid(3) == curLang) cur->Check();
}
menu.AppendSubMenu(languageMenu,_("Thesaurus language"));
}
else menu.Append(EDIT_MENU_THES_LANGUAGE,_("No thesauruses available"))->Enable(false);
// Separator
menu.AppendSeparator();
}
@ -812,7 +834,7 @@ void SubsTextEditCtrl::OnSetDicLanguage(wxCommandEvent &event) {
// Set dictionary
int index = event.GetId() - EDIT_MENU_DIC_LANGS;
spellchecker->SetLanguage(langs[index]);
Options.SetText(_T("Dictionary language"),langs[index]);
Options.SetText(_T("Spell checker language"),langs[index]);
Options.Save();
// Update styling

View File

@ -36,19 +36,22 @@
///////////
// Headers
#include <wx/wxprec.h>
#include <wx/dir.h>
#include <wx/filename.h>
#include "thesaurus_myspell.h"
#include "mythes.hxx"
#include "main.h"
#include "options.h"
#include "utils.h"
///////////////
// Constructor
MySpellThesaurus::MySpellThesaurus() {
wxString idxpath = AegisubApp::folderName + _T("dictionaries/th_en_US.idx");
wxString datpath = AegisubApp::folderName + _T("dictionaries/th_en_US.dat");
mythes = new MyThes(idxpath.mb_str(wxConvLocal),datpath.mb_str(wxConvLocal));
conv = NULL;
if (mythes) conv = new wxCSConv(wxString(mythes->get_th_encoding(),wxConvUTF8));
mythes = NULL;
SetLanguage(Options.AsText(_T("Thesaurus Language")));
}
@ -90,7 +93,30 @@ void MySpellThesaurus::Lookup(wxString word,ThesaurusEntryArray &result) {
/////////////////////
// Get language list
wxArrayString MySpellThesaurus::GetLanguageList() {
// Get dir name
wxString path = DecodeRelativePath(Options.AsText(_T("Dictionaries path")),AegisubApp::folderName) + _T("/");
wxArrayString list;
// Get file lists
wxArrayString idx;
wxDir::GetAllFiles(path,&idx,_T("*.idx"),wxDIR_FILES);
wxArrayString dat;
wxDir::GetAllFiles(path,&dat,_T("*.dat"),wxDIR_FILES);
// For each idxtionary match, see if it can find the corresponding .dat
for (unsigned int i=0;i<idx.Count();i++) {
wxString curdat = idx[i].Left(MAX(0,idx[i].Length()-4)) + _T(".dat");
for (unsigned int j=0;j<dat.Count();j++) {
// Found match
if (curdat == dat[j]) {
wxFileName fname(curdat);
list.Add(fname.GetName());
break;
}
}
}
// Return list
return list;
}
@ -98,4 +124,24 @@ wxArrayString MySpellThesaurus::GetLanguageList() {
////////////////
// Set language
void MySpellThesaurus::SetLanguage(wxString language) {
// Get dir name
wxString path = DecodeRelativePath(Options.AsText(_T("Dictionaries path")),AegisubApp::folderName) + _T("/");
// Get affix and dictionary paths
wxString idxpath = path + _T("th_") + language + _T(".idx");
wxString datpath = path + _T("th_") + language + _T(".dat");
// Check if language is available
if (!wxFileExists(idxpath) || !wxFileExists(datpath)) return;
// Unload
delete mythes;
mythes = NULL;
delete conv;
conv = NULL;
// Load
mythes = new MyThes(idxpath.mb_str(wxConvLocal),datpath.mb_str(wxConvLocal));
conv = NULL;
if (mythes) conv = new wxCSConv(wxString(mythes->get_th_encoding(),wxConvUTF8));
}