Added spellchecker support for different dictionaries/languages:

mozilla\editor\base\nsEditorShell.cpp
    mozilla\editor\idl\nsIEditorSpellCheck.idl
    mozilla\editor\txtsvc\public\nsISpellChecker.h

      - Added GetDictionaryList() and Get/SetCurrentDictionary() methods.

    mozilla\editor\ui\dialogs\content\EdDialogCommon.js

      - Added AppendValueAndDataToMenulist() function.

    mozilla\editor\ui\dialogs\content\EdSpellCheck.xul

      - We now import strres.js.

    mozilla\editor\ui\dialogs\content\EdSpellCheck.js

      - Added InitLanguageMenu().
This commit is contained in:
kin%netscape.com 2000-05-04 14:37:56 +00:00
Родитель fdced22104
Коммит 9a62a21851
8 изменённых файлов: 359 добавлений и 13 удалений

Просмотреть файл

@ -244,10 +244,12 @@ GetTreeOwner(nsIDocShell* aDocShell, nsIBaseWindow** aBaseWindow)
/////////////////////////////////////////////////////////////////////////
nsEditorShell::nsEditorShell()
: mParserObserver(nsnull)
, mStateMaintainer(nsnull)
: mMailCompose(0)
, mDisplayMode(eDisplayModeNormal)
, mWebShellWindow(nsnull)
, mContentWindow(nsnull)
, mParserObserver(nsnull)
, mStateMaintainer(nsnull)
, mEditorController(nsnull)
, mDocShell(nsnull)
, mContentAreaDocShell(nsnull)
@ -256,8 +258,6 @@ nsEditorShell::nsEditorShell()
, mWrapColumn(0)
, mSuggestedWordIndex(0)
, mDictionaryIndex(0)
, mDisplayMode(eDisplayModeNormal)
, mMailCompose(0)
{
//TODO:Save last-used display mode in prefs so new window inherits?
NS_INIT_REFCNT();
@ -4200,6 +4200,108 @@ nsEditorShell::RemoveWordFromDictionary(const PRUnichar *aWord)
return result;
}
NS_IMETHODIMP
nsEditorShell::GetDictionaryList(PRUnichar ***aDictionaryList, PRUint32 *aCount)
{
nsresult result = NS_ERROR_NOT_IMPLEMENTED;
if (!aDictionaryList || !aCount)
return NS_ERROR_NULL_POINTER;
*aDictionaryList = 0;
*aCount = 0;
if (mEditor && mSpellChecker)
{
nsStringArray dictList;
result = mSpellChecker->GetDictionaryList(&dictList);
if (NS_FAILED(result))
return result;
PRUnichar **tmpPtr = 0;
if (dictList.Count() < 1)
{
// If there are no dictionaries, return an array containing
// one element and a count of one.
tmpPtr = (PRUnichar **)nsAllocator::Alloc(sizeof(PRUnichar *));
if (!tmpPtr)
return NS_ERROR_OUT_OF_MEMORY;
*tmpPtr = 0;
*aDictionaryList = tmpPtr;
*aCount = 0;
return NS_OK;
}
tmpPtr = (PRUnichar **)nsAllocator::Alloc(sizeof(PRUnichar *) * dictList.Count());
if (!tmpPtr)
return NS_ERROR_OUT_OF_MEMORY;
*aDictionaryList = tmpPtr;
*aCount = dictList.Count();
nsAutoString dictStr;
PRUint32 i;
for (i = 0; i < *aCount; i++)
{
dictList.StringAt(i, dictStr);
tmpPtr[i] = dictStr.ToNewUnicode();
}
}
return result;
}
NS_IMETHODIMP
nsEditorShell::GetCurrentDictionary(PRUnichar **aDictionary)
{
nsresult result = NS_ERROR_NOT_INITIALIZED;
if (!aDictionary)
return NS_ERROR_NULL_POINTER;
*aDictionary = 0;
if (mEditor && mSpellChecker)
{
nsAutoString dictStr;
result = mSpellChecker->GetCurrentDictionary(&dictStr);
if (NS_FAILED(result))
return result;
*aDictionary = dictStr.ToNewUnicode();
}
return result;
}
NS_IMETHODIMP
nsEditorShell::SetCurrentDictionary(const PRUnichar *aDictionary)
{
nsresult result = NS_ERROR_NOT_INITIALIZED;
if (!aDictionary)
return NS_ERROR_NULL_POINTER;
if (mEditor && mSpellChecker)
{
nsAutoString dictStr(aDictionary);
result = mSpellChecker->SetCurrentDictionary(&dictStr);
}
return result;
}
NS_IMETHODIMP
nsEditorShell::CloseSpellChecking()
{

Просмотреть файл

@ -244,10 +244,12 @@ GetTreeOwner(nsIDocShell* aDocShell, nsIBaseWindow** aBaseWindow)
/////////////////////////////////////////////////////////////////////////
nsEditorShell::nsEditorShell()
: mParserObserver(nsnull)
, mStateMaintainer(nsnull)
: mMailCompose(0)
, mDisplayMode(eDisplayModeNormal)
, mWebShellWindow(nsnull)
, mContentWindow(nsnull)
, mParserObserver(nsnull)
, mStateMaintainer(nsnull)
, mEditorController(nsnull)
, mDocShell(nsnull)
, mContentAreaDocShell(nsnull)
@ -256,8 +258,6 @@ nsEditorShell::nsEditorShell()
, mWrapColumn(0)
, mSuggestedWordIndex(0)
, mDictionaryIndex(0)
, mDisplayMode(eDisplayModeNormal)
, mMailCompose(0)
{
//TODO:Save last-used display mode in prefs so new window inherits?
NS_INIT_REFCNT();
@ -4200,6 +4200,108 @@ nsEditorShell::RemoveWordFromDictionary(const PRUnichar *aWord)
return result;
}
NS_IMETHODIMP
nsEditorShell::GetDictionaryList(PRUnichar ***aDictionaryList, PRUint32 *aCount)
{
nsresult result = NS_ERROR_NOT_IMPLEMENTED;
if (!aDictionaryList || !aCount)
return NS_ERROR_NULL_POINTER;
*aDictionaryList = 0;
*aCount = 0;
if (mEditor && mSpellChecker)
{
nsStringArray dictList;
result = mSpellChecker->GetDictionaryList(&dictList);
if (NS_FAILED(result))
return result;
PRUnichar **tmpPtr = 0;
if (dictList.Count() < 1)
{
// If there are no dictionaries, return an array containing
// one element and a count of one.
tmpPtr = (PRUnichar **)nsAllocator::Alloc(sizeof(PRUnichar *));
if (!tmpPtr)
return NS_ERROR_OUT_OF_MEMORY;
*tmpPtr = 0;
*aDictionaryList = tmpPtr;
*aCount = 0;
return NS_OK;
}
tmpPtr = (PRUnichar **)nsAllocator::Alloc(sizeof(PRUnichar *) * dictList.Count());
if (!tmpPtr)
return NS_ERROR_OUT_OF_MEMORY;
*aDictionaryList = tmpPtr;
*aCount = dictList.Count();
nsAutoString dictStr;
PRUint32 i;
for (i = 0; i < *aCount; i++)
{
dictList.StringAt(i, dictStr);
tmpPtr[i] = dictStr.ToNewUnicode();
}
}
return result;
}
NS_IMETHODIMP
nsEditorShell::GetCurrentDictionary(PRUnichar **aDictionary)
{
nsresult result = NS_ERROR_NOT_INITIALIZED;
if (!aDictionary)
return NS_ERROR_NULL_POINTER;
*aDictionary = 0;
if (mEditor && mSpellChecker)
{
nsAutoString dictStr;
result = mSpellChecker->GetCurrentDictionary(&dictStr);
if (NS_FAILED(result))
return result;
*aDictionary = dictStr.ToNewUnicode();
}
return result;
}
NS_IMETHODIMP
nsEditorShell::SetCurrentDictionary(const PRUnichar *aDictionary)
{
nsresult result = NS_ERROR_NOT_INITIALIZED;
if (!aDictionary)
return NS_ERROR_NULL_POINTER;
if (mEditor && mSpellChecker)
{
nsAutoString dictStr(aDictionary);
result = mSpellChecker->SetCurrentDictionary(&dictStr);
}
return result;
}
NS_IMETHODIMP
nsEditorShell::CloseSpellChecking()
{

Просмотреть файл

@ -36,6 +36,9 @@ interface nsIEditorSpellCheck : nsISupports
wstring GetPersonalDictionaryWord();
void AddWordToDictionary(in wstring word);
void RemoveWordFromDictionary(in wstring word);
void GetDictionaryList([array, size_is(count)] out wstring dictionaryList, out PRUint32 count);
void GetCurrentDictionary(out wstring dictionary);
void SetCurrentDictionary(in wstring dictionary);
void CloseSpellChecking();
};

Просмотреть файл

@ -102,6 +102,32 @@ public:
* list of words in the user's personal dictionary.
*/
NS_IMETHOD GetPersonalDictionary(nsStringArray *aWordList) = 0;
/**
* Returns the list of strings representing the dictionaries
* the spellchecker supports. It was suggested that the strings
* returned be in the RFC 1766 format. This format looks something
* like <ISO 639 language code>-<ISO 3166 country code>.
* For example: en-US
* @param aDictionaryList is an array of nsStrings that represent the
* dictionaries supported by the spellchecker.
*/
NS_IMETHOD GetDictionaryList(nsStringArray *aDictionaryList) = 0;
/**
* Returns a string representing the current dictionary.
* @param aDictionary will contain the name of the dictionary.
* This name is the same string that is in the list returned
* by GetDictionaryList().
*/
NS_IMETHOD GetCurrentDictionary(nsString *aDictionary) = 0;
/**
* Tells the spellchecker to use a specific dictionary.
* @param aDictionary a string that is in the list returned
* by GetDictionaryList().
*/
NS_IMETHOD SetCurrentDictionary(const nsString *aDictionary) = 0;
};
#endif // nsISpellChecker_h__

Просмотреть файл

@ -102,6 +102,32 @@ public:
* list of words in the user's personal dictionary.
*/
NS_IMETHOD GetPersonalDictionary(nsStringArray *aWordList) = 0;
/**
* Returns the list of strings representing the dictionaries
* the spellchecker supports. It was suggested that the strings
* returned be in the RFC 1766 format. This format looks something
* like <ISO 639 language code>-<ISO 3166 country code>.
* For example: en-US
* @param aDictionaryList is an array of nsStrings that represent the
* dictionaries supported by the spellchecker.
*/
NS_IMETHOD GetDictionaryList(nsStringArray *aDictionaryList) = 0;
/**
* Returns a string representing the current dictionary.
* @param aDictionary will contain the name of the dictionary.
* This name is the same string that is in the list returned
* by GetDictionaryList().
*/
NS_IMETHOD GetCurrentDictionary(nsString *aDictionary) = 0;
/**
* Tells the spellchecker to use a specific dictionary.
* @param aDictionary a string that is in the list returned
* by GetDictionaryList().
*/
NS_IMETHOD SetCurrentDictionary(const nsString *aDictionary) = 0;
};
#endif // nsISpellChecker_h__

Просмотреть файл

@ -354,6 +354,35 @@ function AppendStringToMenulist(menulist, string)
return null;
}
function AppendValueAndDataToMenulist(menulist, valueStr, dataStr)
{
if (menulist)
{
var menupopup = menulist.firstChild;
// May not have any popup yet -- so create one
if (!menupopup)
{
menupopup = document.createElement("menupopup");
if (menupopup)
menulist.appendChild(menupopup);
else
{
dump("Failed to create menupoup\n");
return null;
}
}
menuItem = document.createElement("menuitem");
if (menuItem)
{
menuItem.setAttribute("value", valueStr);
menuItem.setAttribute("data", dataStr);
menupopup.appendChild(menuItem);
return menuItem;
}
}
return null;
}
function ClearMenulist(menulist)
{
// There is usually not more than 1 menupopup under a menulist,

Просмотреть файл

@ -75,15 +75,67 @@ function Startup()
// Initial replace word is the misspelled word;
dialog.ReplaceWordInput.value = MisspelledWord;
//Use English for now TODO: Kin needs to finish this work so we can fill in list
dump("Language Listed Index = "+dialog.LanguageMenulist.selectedIndex+"\n");
if (dialog.LanguageMenulist)
InitLanguageMenu("");
DoEnabling();
dialog.SuggestedList.focus();
}
function InitLanguageMenu(defaultLangStr)
{
ClearMenulist(dialog.LanguageMenulist);
var o1 = {};
var o2 = {};
// Get the list of dictionaries from
// the spellchecker.
spellChecker.GetDictionaryList(o1, o2);
var dictList = o1.value;
var count = o2.value;
// Load the string bundle that will help us map
// RFC 1766 strings to UI strings.
var bundle = srGetStrBundle("resource:/res/acceptlanguage.properties");
var menuStr;
var defaultIndex = 0;
for (var i = 0; i < dictList.length; i++)
{
try {
menuStr = bundle.GetStringFromName(dictList[i]+".title");
if (!menuStr)
menuStr = dictList[i];
if (defaultLangStr && dictList[i] == defaultLangStr)
defaultIndex = i;
} catch (ex) {
// GetStringFromName throws an exception when
// a key is not found in the bundle. In that
// case, just use the original dictList string.
menuStr = dictList[i];
}
AppendValueAndDataToMenulist(dialog.LanguageMenulist, menuStr, dictList[i]);
}
// Now make sure the correct item in the menu list
// is selected and that the spellchecker is in sync!
if (dictList.length > 0)
{
dialog.LanguageMenulist.selectedIndex = defaultIndex;
// SelectLanguage();
}
}
function DoEnabling()
{
if (MisspelledWord.length == 0)
@ -225,8 +277,13 @@ function EditDictionary()
function SelectLanguage()
{
// A bug in combobox prevents this from working
dump("SpellCheck: SelectLanguage.\n");
var item = dialog.LanguageMenulist.selectedItem;
try {
spellChecker.SetCurrentDictionary(item.data);
} catch (ex) {
dump(ex);
}
}
function Recheck()

Просмотреть файл

@ -35,6 +35,7 @@
<html:script language="JavaScript" src="chrome://editor/content/EdDialogCommon.js"/>
<html:script language="JavaScript" src="chrome://editor/content/EdSpellCheck.js"/>
<html:script language="Javascript" src="chrome://global/content/strres.js" />
<!-- The argument to ShowWindowWithArgs (the editor appCore name) is placed here -->
<broadcaster id="args" value=""/>