mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 21:06:59 -04:00
The check_spelling function now has support for additional dictionaries and regexes to match.
The magic game uses these features. git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1269 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -120,6 +120,27 @@ InputStreamP PackageManager::openFileFromPackage(Packaged*& package, const Strin
|
||||
throw FileNotFoundError(name, _("No package name specified, use '/package/filename'"));
|
||||
}
|
||||
|
||||
String PackageManager::openFilenameFromPackage(Packaged*& package, const String& name) {
|
||||
if (!name.empty() && name.GetChar(0) == _('/')) {
|
||||
// absolute name; break name
|
||||
size_t start = name.find_first_not_of(_("/\\"), 1); // allow "//package/name" from incorrect scripts
|
||||
size_t pos = name.find_first_of(_("/\\"), start);
|
||||
if (start < pos && pos != String::npos) {
|
||||
// open package
|
||||
PackagedP p = openAny(name.substr(start, pos-start));
|
||||
if (package && !is_substr(name,start,_(":NO-WARN-DEP:"))) {
|
||||
package->requireDependency(p.get());
|
||||
}
|
||||
package = p.get();
|
||||
return p->absoluteFilename() + _("/") + name.substr(pos + 1);
|
||||
}
|
||||
} else if (package) {
|
||||
// relative name
|
||||
return package->absoluteFilename() + _("/") + name;
|
||||
}
|
||||
throw FileNotFoundError(name, _("No package name specified, use '/package/filename'"));
|
||||
}
|
||||
|
||||
String PackageManager::getDictionaryDir(bool l) const {
|
||||
String dir = (l ? local : global).getDirectory();
|
||||
if (dir.empty()) return wxEmptyString;
|
||||
|
||||
@@ -150,6 +150,12 @@ class PackageManager {
|
||||
*/
|
||||
InputStreamP openFileFromPackage(Packaged*& package, const String& name);
|
||||
|
||||
/// Get a filename to open from a package
|
||||
/** WARNING: this is a bit of a hack, since not all package types support names in this way.
|
||||
* It is needed for third party libraries (i.e. hunspell) that load stuff from files.
|
||||
*/
|
||||
String openFilenameFromPackage(Packaged*& package, const String& name);
|
||||
|
||||
// --------------------------------------------------- : Packages on disk
|
||||
|
||||
/// Check if the given dependency is currently installed
|
||||
|
||||
@@ -35,6 +35,31 @@ SpellChecker& SpellChecker::get(const String& language) {
|
||||
return *speller;
|
||||
}
|
||||
|
||||
SpellChecker& SpellChecker::get(const String& filename, const String& language) {
|
||||
SpellCheckerP& speller = spellers[filename + _(".") + language];
|
||||
if (!speller) {
|
||||
Packaged* package = nullptr;
|
||||
String prefix = package_manager.openFilenameFromPackage(package, filename) + _(".");
|
||||
String local_dir = package_manager.getDictionaryDir(true);
|
||||
String global_dir = package_manager.getDictionaryDir(false);
|
||||
String aff_path = language + _(".aff");
|
||||
String dic_path = language + _(".dic");
|
||||
if (wxFileExists(prefix + aff_path) && wxFileExists(prefix + dic_path)) {
|
||||
speller = SpellCheckerP(new SpellChecker((prefix + aff_path).mb_str(),
|
||||
(prefix + dic_path).mb_str()));
|
||||
} else if (wxFileExists(local_dir + aff_path) && wxFileExists(prefix + dic_path)) {
|
||||
speller = SpellCheckerP(new SpellChecker((local_dir + aff_path).mb_str(),
|
||||
(prefix + dic_path).mb_str()));
|
||||
} else if (wxFileExists(global_dir + aff_path) && wxFileExists(prefix + dic_path)) {
|
||||
speller = SpellCheckerP(new SpellChecker((global_dir + aff_path).mb_str(),
|
||||
(prefix + dic_path).mb_str()));
|
||||
} else {
|
||||
throw Error(_("Dictionary '") + filename + _("' not found for language: ") + language);
|
||||
}
|
||||
}
|
||||
return *speller;
|
||||
}
|
||||
|
||||
SpellChecker::SpellChecker(const char* aff_path, const char* dic_path)
|
||||
: Hunspell(aff_path,dic_path)
|
||||
, encoding(String(get_dic_encoding(), IF_UNICODE(wxConvLibc, wxSTRING_MAXLEN)))
|
||||
|
||||
@@ -22,6 +22,9 @@ class SpellChecker : public Hunspell, public IntrusivePtrBase<SpellChecker> {
|
||||
/// Get a SpellChecker object for the given language.
|
||||
/** Note: This is not threadsafe yet */
|
||||
static SpellChecker& get(const String& language);
|
||||
/// Get a SpellChecker object for the given language and filename
|
||||
/** Note: This is not threadsafe yet */
|
||||
static SpellChecker& get(const String& filename, const String& language);
|
||||
/// Destroy all cached SpellChecker objects
|
||||
static void destroyAll();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user