Exception error in Spelling Dictionary dialog and XUL1.0 fixup, b=132697, r=andreww, sr=hewitt, a=asa

This commit is contained in:
cmanske%netscape.com 2002-03-23 01:28:49 +00:00
parent b73b564c8c
commit edb94adb74
4 changed files with 35 additions and 64 deletions

View File

@ -399,33 +399,6 @@ function AppendStringToTreelist(tree, string)
return null;
}
function ReplaceStringInTreeList(tree, index, string)
{
if (tree)
{
var treecols = tree.firstChild;
if (!treecols)
{
dump("Bad XUL: Must have <treecolgroup> as first child\n");
return;
}
var treechildren = treecols.nextSibling;
if (!treechildren)
return;
// Each list item is a <treeitem><treerow><treecell> under <treechildren> node
var childNodes = treechildren.childNodes;
if (!childNodes || index >= childNodes.length)
return;
var row = childNodes.item(index).firstChild;
if (row && row.firstChild)
{
row.firstChild.setAttribute("label", string);
}
}
}
function ClearTreelist(tree)
{
if (tree)

View File

@ -49,8 +49,6 @@ function Startup()
// Select the supplied word if it is already in the list
SelectWordToAddInList();
SetTextboxFocus(gDialog.WordInput);
SetWindowLocation();
}
function ValidateWordToAdd()
@ -66,11 +64,13 @@ function ValidateWordToAdd()
function SelectWordToAddInList()
{
for (var index = 0; index < gDialog.DictionaryList.getAttribute("length"); index++)
for (var i = 0; i < gDialog.DictionaryList.getRowCount(); i++)
{
if (gWordToAdd == GetTreelistValueAt(gDialog.DictionaryList,index))
var wordInList = gDialog.DictionaryList.getItemAtIndex(i);
if (wordInList && gWordToAdd == wordInList.label)
{
gDialog.DictionaryList.selectedIndex = index;
gDialog.DictionaryList.selectedIndex = i;
break;
}
}
@ -99,16 +99,20 @@ function ReplaceWord()
{
if (ValidateWordToAdd())
{
var selIndex = gDialog.DictionaryList.selectedIndex;
if (selIndex >= 0)
var selItem = gDialog.DictionaryList.selectedItem;
if (selItem)
{
gSpellChecker.RemoveWordFromDictionary(GetSelectedTreelistValue(gDialog.DictionaryList));
try {
gSpellChecker.RemoveWordFromDictionary(selItem.label);
} catch (e) {}
try {
// Add to the dictionary list
gSpellChecker.AddWordToDictionary(gWordToAdd);
// Just change the text on the selected item
// instead of rebuilding the list
ReplaceStringInTreeList(gDialog.DictionaryList, selIndex, gWordToAdd);
selItem.label = gWordToAdd;
} catch (e) {
// Rebuild list and select the word - it was probably already in the list
dump("Exception occured adding word in ReplaceWord\n");
@ -124,10 +128,10 @@ function RemoveWord()
var selIndex = gDialog.DictionaryList.selectedIndex;
if (selIndex >= 0)
{
var word = GetSelectedTreelistValue(gDialog.DictionaryList);
var word = gDialog.DictionaryList.selectedItem.label;
// Remove word from list
RemoveSelectedTreelistItem(gDialog.DictionaryList);
gDialog.DictionaryList.removeItemAt(selIndex);
// Remove from dictionary
try {
@ -148,7 +152,8 @@ function FillDictionaryList()
var selIndex = gDialog.DictionaryList.selectedIndex;
// Clear the current contents of the list
ClearTreelist(gDialog.DictionaryList);
ClearListbox(gDialog.DictionaryList);
// Get the list from the spell checker
gSpellChecker.GetPersonalDictionary()
@ -159,22 +164,22 @@ function FillDictionaryList()
var word = gSpellChecker.GetPersonalDictionaryWord();
if (word != "")
{
AppendStringToTreelist(gDialog.DictionaryList, word);
gDialog.DictionaryList.appendItem(word, "");
haveList = true;
}
} while (word != "");
//XXX: BUG 74467: If list is empty, tree doesn't layout to full height correctly
//XXX: BUG 74467: If list is empty, it doesn't layout to full height correctly
// (ignores "rows" attribute) (bug is latered, so we are fixing here for now)
if (!haveList)
AppendStringToTreelist(gDialog.DictionaryList, " ");
gDialog.DictionaryList.appendItem("", "");
ResetSelectedItem(selIndex);
}
function ResetSelectedItem(index)
{
var lastIndex = gDialog.DictionaryList.getAttribute("length") - 1;
var lastIndex = gDialog.DictionaryList.getRowCount() - 1;
if (index > lastIndex)
index = lastIndex;
@ -183,14 +188,10 @@ function ResetSelectedItem(index)
if (index == -1 && lastIndex >= 0)
index = 0;
dump("ResetSelectedItem to index="+index+"\n");
gDialog.DictionaryList.selectedIndex = index;
}
function Close()
function onClose()
{
// Close the dialog
SaveWindowLocation();
window.close();
return true;
}

View File

@ -26,6 +26,7 @@
<!DOCTYPE window SYSTEM "chrome://editor/locale/EditorPersonalDictionary.dtd">
<dialog buttons="cancel" title="&windowTitle.label;"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
persist="screenX screenY"
onload = "Startup()"
ondialogcancel="return onClose();">
@ -35,13 +36,6 @@
<script type="application/x-javascript" src="chrome://editor/content/EdDictionary.js"/>
<broadcaster id="args" value=""/>
<spacer id="location" offsetX="10" offsetY="10" persist="offsetX offsetY"/>
<keyset id="keys">
<key keycode="VK_ENTER" oncommand="Close()"/>
<key keycode="VK_RETURN" oncommand="Close()"/>
<key keycode="VK_ESCAPE" oncommand="Close()"/>
</keyset>
<grid>
<columns><column style="width: 15em" flex="1"/><column flex="1"/></columns>
<rows>
@ -58,16 +52,14 @@
<spacer/>
</row>
<row>
<tree rows="8" class="list" id="DictionaryList" flex="1">
<treecolgroup><treecol flex="1"/></treecolgroup>
</tree>
<listbox rows="8" id="DictionaryList" flex="1"/>
<vbox flex="1">
<button id="ReplaceWord" oncommand="ReplaceWord()" label="&ReplaceButton.label;"/>
<spacer class="spacer"/>
<button id="RemoveWord" oncommand="RemoveWord()" label="&RemoveButton.label;"/>
<spacer class="spacer"/>
<spacer flex="1"/>
<button dlgtype="cancel" class="exit-dialog" id="close" label="&CloseButton.label;" default="true" oncommand="Close();"/>
<button dlgtype="cancel" class="exit-dialog" id="close" label="&CloseButton.label;" default="true" oncommand="onClose();"/>
</vbox>
</row>
</rows>

View File

@ -130,7 +130,7 @@
return this.selectedItems.length > 0 ? this.selectedItems[0] : null;
]]></getter>
<setter><![CDATA[
this.selectItem(item);
this.selectItem(val);
]]></setter>
</property>
@ -384,10 +384,13 @@
<method name="clearSelection">
<body>
<![CDATA[
for (var i = this.selectedItems.length-1; i >= 0; --i)
this.selectedItems[i].selected = false;
if (this.selectedItems)
{
for (var i = this.selectedItems.length-1; i >= 0; --i)
this.selectedItems[i].selected = false;
this.selectedItems.splice(0, this.selectedItems.length);
this.selectedItems.splice(0, this.selectedItems.length);
}
this._selectionStart = null;
this._fireOnSelect();
]]>
@ -768,6 +771,8 @@
<property name="value" onget="return this.getAttribute('value');"
onset="this.setAttribute('value', val); return val;"/>
<property name="label" onget="return this.getAttribute('label');"
onset="this.setAttribute('label', val); return val;"/>
<property name="selected" onget="return this.getAttribute('selected') == 'true';">
<setter><![CDATA[