mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-26 14:46:02 +00:00
Bug 213477 Right click menus don't hide or disable items when they should r=brade sr=rbs
This commit is contained in:
parent
4b9efa09b4
commit
b3861ff905
@ -27,15 +27,6 @@ function EditorFillContextMenu(event, contextMenuNode)
|
||||
if ( event.target != contextMenuNode )
|
||||
return;
|
||||
|
||||
goUpdateCommand("cmd_undo");
|
||||
goUpdateCommand("cmd_redo");
|
||||
goUpdateCommand("cmd_cut");
|
||||
goUpdateCommand("cmd_copy");
|
||||
goUpdateCommand("cmd_paste");
|
||||
goUpdateCommand("cmd_pasteNoFormatting");
|
||||
goUpdateCommand("cmd_delete");
|
||||
goUpdateCommand("cmd_link");
|
||||
|
||||
// Setup object property menuitem
|
||||
var objectName = InitObjectPropertiesMenuitem("objectProperties_cm");
|
||||
var isInLink = objectName == "href";
|
||||
@ -46,12 +37,6 @@ function EditorFillContextMenu(event, contextMenuNode)
|
||||
isInLink = GetCurrentEditor().getElementOrParentByTagName("href", GetObjectForProperties());
|
||||
} catch (e) {}
|
||||
|
||||
// Disable "Create Link" if in a link
|
||||
SetElementEnabledById("createLink_cm", !isInLink);
|
||||
|
||||
// Enable "Edit link in new Composer" if in a link
|
||||
SetElementEnabledById("editLink_cm", isInLink);
|
||||
|
||||
InitRemoveStylesMenuitems("removeStylesMenuitem_cm", "removeLinksMenuitem_cm", "removeNamedAnchorsMenuitem_cm");
|
||||
|
||||
var inCell = IsInTableCell();
|
||||
@ -67,9 +52,16 @@ function EditorFillContextMenu(event, contextMenuNode)
|
||||
{
|
||||
var count = children.length;
|
||||
for (var i = 0; i < count; i++)
|
||||
HideDisabledItem(children.item(i));
|
||||
HideDisabledItem(children[i]);
|
||||
}
|
||||
|
||||
// The above loop will always show all separators and the next two items
|
||||
// Hide "Create Link" if in a link
|
||||
ShowMenuItem("createLink_cm", !isInLink);
|
||||
|
||||
// Hide "Edit link in new Composer" unless in a link
|
||||
ShowMenuItem("editLink_cm", isInLink);
|
||||
|
||||
// Remove separators if all items in immediate group above are hidden
|
||||
// A bit complicated to account if multiple groups are completely hidden!
|
||||
var haveUndo =
|
||||
@ -112,61 +104,40 @@ function EditorFillContextMenu(event, contextMenuNode)
|
||||
ShowMenuItem("tableDeleteMenu_cm", inCell);
|
||||
}
|
||||
|
||||
function EditorCleanupContextMenu( event, contextMenuNode )
|
||||
function IsItemOrCommandEnabled( item )
|
||||
{
|
||||
if ( event.target != contextMenuNode )
|
||||
return;
|
||||
|
||||
var children = contextMenuNode.childNodes;
|
||||
if (children)
|
||||
{
|
||||
var count = children.length;
|
||||
for (var i = 0; i < count; i++)
|
||||
ShowHiddenItemOnCleanup(children.item(i));
|
||||
var command = item.getAttribute("command");
|
||||
if (command) {
|
||||
// If possible, query the command controller directly
|
||||
var controller = document.commandDispatcher.getControllerForCommand(command);
|
||||
if (controller)
|
||||
return controller.isCommandEnabled(command);
|
||||
}
|
||||
|
||||
// Fall back on the inefficient observed disabled attribute
|
||||
return item.getAttribute("disabled") != "true";
|
||||
}
|
||||
|
||||
function HideDisabledItem( item )
|
||||
{
|
||||
if (!item) return false;
|
||||
|
||||
var enabled = (item.getAttribute('disabled') !="true");
|
||||
item.setAttribute("hidden", enabled ? "" : "true");
|
||||
item.setAttribute("contexthidden", enabled ? "" : "true");
|
||||
return enabled;
|
||||
}
|
||||
|
||||
function ShowHiddenItemOnCleanup( item )
|
||||
{
|
||||
if (!item) return false;
|
||||
|
||||
var isHidden = (item.getAttribute("contexthidden") == "true");
|
||||
if (isHidden)
|
||||
{
|
||||
item.removeAttribute("hidden");
|
||||
item.removeAttribute("contexthidden");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
item.hidden = !IsItemOrCommandEnabled(item);
|
||||
}
|
||||
|
||||
function ShowMenuItem(id, showItem)
|
||||
{
|
||||
var item = document.getElementById(id);
|
||||
if (item)
|
||||
if (item && !showItem)
|
||||
{
|
||||
item.setAttribute("hidden", showItem ? "" : "true");
|
||||
item.setAttribute("contexthidden", showItem ? "" : "true");
|
||||
item.hidden = true;
|
||||
}
|
||||
else
|
||||
dump("ShowMenuItem: item id="+id+" not found\n");
|
||||
// else HideDisabledItem showed the item anyway
|
||||
}
|
||||
|
||||
function IsMenuItemShowing(menuID)
|
||||
{
|
||||
var item = document.getElementById(menuID);
|
||||
if(item)
|
||||
return(item.getAttribute("contexthidden") != "true");
|
||||
if (item)
|
||||
return !item.hidden;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -34,42 +34,33 @@
|
||||
<popupset id="editorContentContextSet">
|
||||
<popup id="editorContentContext"
|
||||
onpopupshowing="EditorFillContextMenu(event, this);">
|
||||
<menuitem id="menu_undo_cm" label="&undoCmd.label;" accesskey="&undo.accesskey;"
|
||||
observes="cmd_undo" oncommand="goDoCommand('cmd_undo')"/>
|
||||
<menuitem id="menu_redo_cm" label="&redoCmd.label;" accesskey="&redo.accesskey;"
|
||||
observes="cmd_redo" oncommand="goDoCommand('cmd_redo')"/>
|
||||
<menuitem id="menu_undo_cm" label="&undoCmd.label;" accesskey="&undo.accesskey;" command="cmd_undo"/>
|
||||
<menuitem id="menu_redo_cm" label="&redoCmd.label;" accesskey="&redo.accesskey;" command="cmd_redo"/>
|
||||
<menuseparator id="undoredo-separator"/>
|
||||
|
||||
<!-- In these commands, the "observes" is needed for proper command disabling,
|
||||
but the "oncommand" is still needed since we can't get it from global overlay -->
|
||||
<menuitem id="menu_cut_cm" label="&cutCmd.label;" accesskey="&cut.accesskey;"
|
||||
observes="cmd_cut" oncommand="goDoCommand('cmd_cut')"/>
|
||||
<menuitem id="menu_copy_cm" label="©Cmd.label;" accesskey="©.accesskey;"
|
||||
observes="cmd_copy" oncommand="goDoCommand('cmd_copy')"/>
|
||||
<menuitem id="menu_paste_cm" label="&pasteCmd.label;" accesskey="&paste.accesskey;"
|
||||
observes="cmd_paste" oncommand="goDoCommand('cmd_paste')"/>
|
||||
<menuitem id="menu_pasteNoFormatting_cm" observes="cmd_pasteNoFormatting"/>
|
||||
<menuitem id="menu_delete_cm" label="&deleteCmd.label;" accesskey="&delete.accesskey;"
|
||||
observes="cmd_delete" oncommand="goDoCommand('cmd_delete')"/>
|
||||
<menuitem id="menu_cut_cm" label="&cutCmd.label;" accesskey="&cut.accesskey;" command="cmd_cut"/>
|
||||
<menuitem id="menu_copy_cm" label="©Cmd.label;" accesskey="©.accesskey;" command="cmd_copy"/>
|
||||
<menuitem id="menu_paste_cm" label="&pasteCmd.label;" accesskey="&paste.accesskey;" command="cmd_paste"/>
|
||||
<menuitem id="menu_pasteNoFormatting_cm" command="cmd_pasteNoFormatting"/>
|
||||
<menuitem id="menu_delete_cm" label="&deleteCmd.label;" accesskey="&delete.accesskey;" command="cmd_delete"/>
|
||||
<menuseparator id="edit-separator"/>
|
||||
<menuitem id="menu_selectAll_cm" label="&selectAllCmd.label;" accesskey="&selectall.accesskey;"
|
||||
observes="cmd_selectAll" oncommand="goDoCommand('cmd_selectAll')"/>
|
||||
<menuitem id="menu_selectAll_cm" label="&selectAllCmd.label;" accesskey="&selectall.accesskey;" command="cmd_selectAll"/>
|
||||
<menuseparator id="selectAll-separator"/>
|
||||
|
||||
<!-- label and accesskey set at runtime from strings -->
|
||||
<menuitem id="removeStylesMenuitem_cm"
|
||||
observes="cmd_removeStyles"/>
|
||||
<menuitem id="createLink_cm" label="&createLinkCmd.label;" accesskey="&createlink.accesskey;"
|
||||
observes="cmd_link" />
|
||||
<menuitem id="createLink_cm" label="&createLinkCmd.label;" accesskey="&createlink.accesskey;" command="cmd_link"/>
|
||||
<!-- label and accesskey set at runtime from strings -->
|
||||
<menuitem id="removeLinksMenuitem_cm" observes="cmd_removeLinks"/>
|
||||
<menuitem id="removeNamedAnchorsMenuitem_cm" label="&formatRemoveNamedAnchors.label;"
|
||||
accesskey="&formatRemoveNamedAnchors.accesskey;"
|
||||
observes="cmd_removeNamedAnchors"/>
|
||||
<menuseparator id="styles-separator"/>
|
||||
|
||||
<!-- label and accesskey are set in InitObjectProperties -->
|
||||
<menuitem id="objectProperties_cm" observes="cmd_objectProperties"/>
|
||||
<menuitem id="editLink_cm" label="&editLinkCmd.label;" accesskey="&editlink.accesskey;" observes="cmd_editLink"/>
|
||||
<menuitem id="editLink_cm" label="&editLinkCmd.label;" accesskey="&editlink.accesskey;" command="cmd_editLink"/>
|
||||
<menuseparator id="property-separator"/>
|
||||
|
||||
<!-- Can't get submenus to load from a shared overlay -->
|
||||
|
Loading…
x
Reference in New Issue
Block a user