зеркало из https://github.com/mozilla/gecko-dev.git
b=397982. r=bsmedberg. a=dsicore. Default the spellcheck to load dictionaries from GRE and APP folders
This commit is contained in:
Родитель
f301bebb74
Коммит
58bd4f099f
|
@ -1,20 +1,20 @@
|
|||
/******* BEGIN LICENSE BLOCK *******
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
*
|
||||
* The Initial Developers of the Original Code are Kevin Hendricks (MySpell)
|
||||
* and László Németh (Hunspell). Portions created by the Initial Developers
|
||||
* are Copyright (C) 2002-2005 the Initial Developers. All Rights Reserved.
|
||||
*
|
||||
*
|
||||
* Contributor(s): Kevin Hendricks (kevin.hendricks@sympatico.ca)
|
||||
* David Einstein (deinst@world.std.com)
|
||||
* Michiel van Leeuwen (mvl@exedo.nl)
|
||||
|
@ -41,7 +41,7 @@
|
|||
* Harri Pitkanen
|
||||
* Andras Timar
|
||||
* Tor Lillqvist
|
||||
*
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
|
@ -309,17 +309,29 @@ mozHunspell::LoadDictionaryList()
|
|||
nsCOMPtr<nsIFile> dictDir;
|
||||
rv = dirSvc->Get(DICTIONARY_SEARCH_DIRECTORY,
|
||||
NS_GET_IID(nsIFile), getter_AddRefs(dictDir));
|
||||
if (NS_FAILED(rv)) {
|
||||
// default to appdir/dictionaries
|
||||
rv = dirSvc->Get(NS_XPCOM_CURRENT_PROCESS_DIR,
|
||||
NS_GET_IID(nsIFile), getter_AddRefs(dictDir));
|
||||
if (NS_FAILED(rv))
|
||||
return;
|
||||
|
||||
dictDir->AppendNative(NS_LITERAL_CSTRING("dictionaries"));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
LoadDictionariesFromDir(dictDir);
|
||||
}
|
||||
else {
|
||||
// try to load gredir/dictionaries
|
||||
nsCOMPtr<nsIFile> greDir;
|
||||
rv = dirSvc->Get(NS_GRE_DIR,
|
||||
NS_GET_IID(nsIFile), getter_AddRefs(greDir));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
greDir->AppendNative(NS_LITERAL_CSTRING("dictionaries"));
|
||||
LoadDictionariesFromDir(greDir);
|
||||
}
|
||||
|
||||
LoadDictionariesFromDir(dictDir);
|
||||
// try to load appdir/dictionaries only if different than gredir
|
||||
nsCOMPtr<nsIFile> appDir;
|
||||
rv = dirSvc->Get(NS_XPCOM_CURRENT_PROCESS_DIR,
|
||||
NS_GET_IID(nsIFile), getter_AddRefs(appDir));
|
||||
PRBool equals;
|
||||
if (NS_SUCCEEDED(rv) && NS_SUCCEEDED(appDir->Equals(greDir, &equals)) && !equals) {
|
||||
appDir->AppendNative(NS_LITERAL_CSTRING("dictionaries"));
|
||||
LoadDictionariesFromDir(appDir);
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISimpleEnumerator> dictDirs;
|
||||
rv = dirSvc->Get(DICTIONARY_SEARCH_DIRECTORY_LIST,
|
||||
|
@ -402,7 +414,7 @@ nsresult mozHunspell::ConvertCharset(const PRUnichar* aStr, char ** aDst)
|
|||
|
||||
rv = mEncoder->Convert(aStr, &inLength, *aDst, &outLength);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
(*aDst)[outLength] = '\0';
|
||||
(*aDst)[outLength] = '\0';
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
@ -421,9 +433,9 @@ NS_IMETHODIMP mozHunspell::Check(const PRUnichar *aWord, PRBool *aResult)
|
|||
*aResult = !!mHunspell->spell(charsetWord);
|
||||
|
||||
|
||||
if (!*aResult && mPersonalDictionary)
|
||||
if (!*aResult && mPersonalDictionary)
|
||||
rv = mPersonalDictionary->Check(aWord, mLanguage.get(), aResult);
|
||||
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -436,7 +448,7 @@ NS_IMETHODIMP mozHunspell::Suggest(const PRUnichar *aWord, PRUnichar ***aSuggest
|
|||
|
||||
nsresult rv;
|
||||
*aSuggestionCount = 0;
|
||||
|
||||
|
||||
nsXPIDLCString charsetWord;
|
||||
rv = ConvertCharset(aWord, getter_Copies(charsetWord));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -444,12 +456,12 @@ NS_IMETHODIMP mozHunspell::Suggest(const PRUnichar *aWord, PRUnichar ***aSuggest
|
|||
char ** wlst;
|
||||
*aSuggestionCount = mHunspell->suggest(&wlst, charsetWord);
|
||||
|
||||
if (*aSuggestionCount) {
|
||||
*aSuggestions = (PRUnichar **)nsMemory::Alloc(*aSuggestionCount * sizeof(PRUnichar *));
|
||||
if (*aSuggestionCount) {
|
||||
*aSuggestions = (PRUnichar **)nsMemory::Alloc(*aSuggestionCount * sizeof(PRUnichar *));
|
||||
if (*aSuggestions) {
|
||||
PRUint32 index = 0;
|
||||
for (index = 0; index < *aSuggestionCount && NS_SUCCEEDED(rv); ++index) {
|
||||
// Convert the suggestion to utf16
|
||||
// Convert the suggestion to utf16
|
||||
PRInt32 inLength = nsCRT::strlen(wlst[index]);
|
||||
PRInt32 outLength;
|
||||
rv = mDecoder->GetMaxLength(wlst[index], inLength, &outLength);
|
||||
|
@ -461,7 +473,7 @@ NS_IMETHODIMP mozHunspell::Suggest(const PRUnichar *aWord, PRUnichar ***aSuggest
|
|||
rv = mDecoder->Convert(wlst[index], &inLength, (*aSuggestions)[index], &outLength);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
(*aSuggestions)[index][outLength] = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -473,7 +485,7 @@ NS_IMETHODIMP mozHunspell::Suggest(const PRUnichar *aWord, PRUnichar ***aSuggest
|
|||
else // if (*aSuggestions)
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
||||
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(*aSuggestionCount, wlst);
|
||||
return rv;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче