From 62c1f80eeafa8e9b23053f06bc648228bf998680 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Mon, 1 Jan 2007 04:15:54 +0000 Subject: [PATCH] Improvements to spell checker file handling Originally committed to SVN as r669. --- aegisub/options.cpp | 4 ++ aegisub/spellchecker_hunspell.cpp | 61 +++++++++++++++++++++++++++---- aegisub/utils.cpp | 5 +++ 3 files changed, 62 insertions(+), 8 deletions(-) diff --git a/aegisub/options.cpp b/aegisub/options.cpp index b95b5d2a3..8eab60869 100644 --- a/aegisub/options.cpp +++ b/aegisub/options.cpp @@ -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); diff --git a/aegisub/spellchecker_hunspell.cpp b/aegisub/spellchecker_hunspell.cpp index d3bd40239..3a329c4f8 100644 --- a/aegisub/spellchecker_hunspell.cpp +++ b/aegisub/spellchecker_hunspell.cpp @@ -39,18 +39,20 @@ #include "setup.h" #if USE_HUNSPELL == 1 #include +#include +#include #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;iget_dic_encoding(),wxConvUTF8)); } #endif diff --git a/aegisub/utils.cpp b/aegisub/utils.cpp index 3fe1490cc..cbc8d8905 100644 --- a/aegisub/utils.cpp +++ b/aegisub/utils.cpp @@ -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 }