mirror of https://github.com/odrling/Aegisub
Improvements to spell checker file handling
Originally committed to SVN as r669.
This commit is contained in:
parent
e79ef00863
commit
62c1f80eea
|
@ -93,6 +93,10 @@ void OptionsManager::LoadDefaults() {
|
|||
SetText(_T("Auto recovery path"),_T("recovered"));
|
||||
SetInt(_T("Autoload linked files"),2);
|
||||
|
||||
// Dictionary
|
||||
SetText(_T("Dictionaries path"),_T("dictionaries"));
|
||||
SetText(_T("Dictionary language"),_T("en_US"));
|
||||
|
||||
// Video Options
|
||||
SetInt(_T("Video Check Script Res"), 0);
|
||||
SetInt(_T("Video Default Zoom"), 7);
|
||||
|
|
|
@ -39,18 +39,20 @@
|
|||
#include "setup.h"
|
||||
#if USE_HUNSPELL == 1
|
||||
#include <hunspell/hunspell.hxx>
|
||||
#include <wx/wxprec.h>
|
||||
#include <wx/dir.h>
|
||||
#include "spellchecker_hunspell.h"
|
||||
#include "main.h"
|
||||
#include "utils.h"
|
||||
#include "options.h"
|
||||
|
||||
|
||||
///////////////
|
||||
// Constructor
|
||||
HunspellSpellChecker::HunspellSpellChecker() {
|
||||
wxString affpath = AegisubApp::folderName + _T("dictionaries/en_US.aff");
|
||||
wxString dpath = AegisubApp::folderName + _T("dictionaries/en_US.dic");
|
||||
hunspell = new Hunspell(affpath.mb_str(wxConvLocal),dpath.mb_str(wxConvLocal));
|
||||
hunspell = NULL;
|
||||
conv = NULL;
|
||||
if (hunspell) conv = new wxCSConv(wxString(hunspell->get_dic_encoding(),wxConvUTF8));
|
||||
SetLanguage(Options.AsText(_T("Dictionary Language")));
|
||||
}
|
||||
|
||||
|
||||
|
@ -95,12 +97,12 @@ wxArrayString HunspellSpellChecker::GetSuggestions(wxString word) {
|
|||
// Array
|
||||
wxArrayString suggestions;
|
||||
|
||||
// Word
|
||||
wxCharBuffer buf = word.mb_str(*conv);
|
||||
if (!buf) return suggestions;
|
||||
|
||||
// Get suggestions
|
||||
if (hunspell) {
|
||||
// Word
|
||||
wxCharBuffer buf = word.mb_str(*conv);
|
||||
if (!buf) return suggestions;
|
||||
|
||||
// Grab raw from Hunspell
|
||||
char **results;
|
||||
int n = hunspell->suggest(&results,buf);
|
||||
|
@ -124,7 +126,30 @@ wxArrayString HunspellSpellChecker::GetSuggestions(wxString word) {
|
|||
//////////////////////////////////////
|
||||
// Get list of available dictionaries
|
||||
wxArrayString HunspellSpellChecker::GetLanguageList() {
|
||||
// Get dir name
|
||||
wxString path = DecodeRelativePath(Options.AsText(_T("Dictionaries path")),AegisubApp::folderName) + _T("/");
|
||||
wxArrayString list;
|
||||
|
||||
// Get file lists
|
||||
wxArrayString dic;
|
||||
wxDir::GetAllFiles(path,&dic,_T("*.dic"),wxDIR_FILES);
|
||||
wxArrayString aff;
|
||||
wxDir::GetAllFiles(path,&aff,_T("*.aff"),wxDIR_FILES);
|
||||
|
||||
// For each dictionary match, see if it can find the corresponding .aff
|
||||
for (unsigned int i=0;i<dic.Count();i++) {
|
||||
wxString curAff = dic[i].Left(MAX(0,dic[i].Length()-4)) + _T(".aff");
|
||||
for (unsigned int j=0;j<aff.Count();j++) {
|
||||
// Found match
|
||||
if (curAff == aff[j]) {
|
||||
wxFileName fname(curAff);
|
||||
list.Add(fname.GetName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return list
|
||||
return list;
|
||||
}
|
||||
|
||||
|
@ -132,6 +157,26 @@ wxArrayString HunspellSpellChecker::GetLanguageList() {
|
|||
////////////////
|
||||
// Set language
|
||||
void HunspellSpellChecker::SetLanguage(wxString language) {
|
||||
// Get dir name
|
||||
wxString path = DecodeRelativePath(Options.AsText(_T("Dictionaries path")),AegisubApp::folderName) + _T("/");
|
||||
|
||||
// Get affix and dictionary paths
|
||||
wxString affpath = path + language + _T(".aff");
|
||||
wxString dicpath = path + language + _T(".dic");
|
||||
|
||||
// Check if language is available
|
||||
if (!wxFileExists(affpath) || !wxFileExists(dicpath)) return;
|
||||
|
||||
// Unload
|
||||
delete hunspell;
|
||||
hunspell = NULL;
|
||||
delete conv;
|
||||
conv = NULL;
|
||||
|
||||
// Load
|
||||
hunspell = new Hunspell(affpath.mb_str(wxConvLocal),dicpath.mb_str(wxConvLocal));
|
||||
conv = NULL;
|
||||
if (hunspell) conv = new wxCSConv(wxString(hunspell->get_dic_encoding(),wxConvUTF8));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -110,7 +110,12 @@ wxString DecodeRelativePath(wxString _path,wxString reference) {
|
|||
wxFileName path(_path);
|
||||
wxFileName refPath(reference);
|
||||
if (!path.IsAbsolute()) path.MakeAbsolute(refPath.GetPath());
|
||||
#ifdef __UNIX__
|
||||
return path.GetFullPath(wxPATH_UNIX); // also works on windows
|
||||
// No, it doesn't, this ommits drive letter in Windows. ~ amz
|
||||
#else
|
||||
return path.GetFullPath();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue