On Feb 21, 11:13 pm, Neil <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> >On Feb 21, 4:50 pm, Neil wrote:
>
> >> If you're providing your own XUL window then you need to include the
> >> inlineSpellCheckUI.js object and integrate itwith your context menu.
>
> >Thanks. So I essentially need to copy the browser's context menu
> >implementation in my code?
>
> No, the inline spell check ui works with any context menu, for instance
> the one for chrome textboxes, the Thunderbird compose window, or the
> three in SeaMonkey.
Thanks.
I think I have it more or less sorted now. However the suggestions
list is growing every time I right-click on a misspelled word.
A bit of debug seems to show that there is a correct attempt to remove
the items from the list in onpopuphiding, but the onpopupshowing code
is being called twice. A call to 'event.stopPropagation()' didn't seem
to help.
Here's my code:
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<!DOCTYPE windows [
<!ENTITY % textcontextDTD SYSTEM "chrome://global/locale/
textcontext.dtd" >
%textcontextDTD;
]>
<window
xmlns="http://www.mozilla.org/keymaster/gatekeeper/
there.is.only.xul"
onload="onload();"
width="500px" height="300px"
title="editor test">
<script type="application/x-javascript" src="chrome://global/
content/strres.js"/>
<script type="application/x-javascript" src="chrome://global/
content/globalOverlay.js"/>
<script type="application/x-javascript" src="chrome://global/
content/inlineSpellCheckUI.js"/>
<script type="application/x-javascript">
<![CDATA[
function onload ()
{
try {
var iframe = document.getElementById ("edit-
frame");
iframe.contentWindow.document.designMode = "on";
var myIframeEditor = document.getElementById
("edit-frame").contentWindow
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShell)
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIEditingSession)
.getEditorForWindow(iframe.contentWindow);
InlineSpellCheckerUI.init (myIframeEditor);
InlineSpellCheckerUI.enabled = true;
} catch (e) {
window.alert (e);
}
}
function _setMenuItemVisibility (id, visible)
{
document.getElementById(id).hidden = ! visible;
}
function _doPopupItemDisabling ()
{
if (InlineSpellCheckerUI) {
InlineSpellCheckerUI.clearSuggestionsFromMenu();
InlineSpellCheckerUI.clearDictionaryListFromMenu();
}
}
function _doPopupItemEnablingSpell (popupNode, evt)
{
var logger = Components.classes['@mozilla.org/
consoleservice;
1'].getService(Components.interfaces.nsIConsoleService);
if (!InlineSpellCheckerUI || !
InlineSpellCheckerUI.canSpellCheck) {
_setMenuItemVisibility("spell-no-suggestions",
false);
_setMenuItemVisibility("spell-check-enabled",
false);
_setMenuItemVisibility("spell-check-separator",
false);
_setMenuItemVisibility("spell-add-to-dictionary",
false);
_setMenuItemVisibility("spell-suggestions-
separator", false);
_setMenuItemVisibility("spell-dictionaries",
false);
return;
}
try {
InlineSpellCheckerUI.initFromEvent(document.popupRangeParent,
document.popupRangeOffset);
var enabled = InlineSpellCheckerUI.enabled;
document.getElementById("spell-check-
enabled").setAttribute("checked", enabled);
var overMisspelling =
InlineSpellCheckerUI.overMisspelling;
_setMenuItemVisibility("spell-add-to-dictionary",
overMisspelling);
_setMenuItemVisibility("spell-suggestions-
separator", overMisspelling);
// suggestion list
var numsug =
InlineSpellCheckerUI.addSuggestionsToMenu(popupNode,
document.getElementById("spell-no-suggestions"), 5);
logger.logStringMessage ("Got " + numsug + "
suggestions");
_setMenuItemVisibility("spell-no-suggestions",
overMisspelling && numsug == 0);
// dictionary list
var numdicts =
InlineSpellCheckerUI.addDictionaryListToMenu
(document.getElementById("spell-dictionaries-
menu"), null);
_setMenuItemVisibility("spell-dictionaries",
enabled && numdicts > 1);
} catch (e) {
window.alert (e);
}
}
]]>
</script>
<popupset>
<popup id="editorPopup"
onpopupshowing="_doPopupItemEnablingSpell(this,
event);"
onpopuphiding="_doPopupItemDisabling(this);"
>
<menuitem label="&spellNoSuggestions.label;" id="spell-
no-suggestions" disabled="true"/>
<menuitem label="&spellAddToDictionary.label;"
accesskey="&spellAddToDictionary.accesskey;" id="spell-add-to-
dictionary"
oncommand="InlineSpellCheckerUI.addToDictionary();"/>
<menuseparator id="spell-suggestions-separator"/>
<menuseparator/>
<menuitem label="&spellEnable.label;" type="checkbox"
accesskey="&spellEnable.accesskey;" id="spell-check-enabled"
oncommand="InlineSpellCheckerUI.toggleEnabled();"/>
<menu label="&spellDictionaries.label;"
accesskey="&spellDictionaries.accesskey;" id="spell-dictionaries">
<menupopup id="spell-dictionaries-menu"
onpopupshowing="event.stopPropagation();"
onpopuphiding="event.stopPropagation();"/>
</menu>
</popup>
</popupset>
<iframe id="edit-frame" flex="1" context="editorPopup" />
</window>
Matthew
_______________________________________________
dev-tech-editor mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-editor