[Project_owners] Re: How to disable the context menu for <treecol>

Michael Vincent van Rantwijk some at universum.org
Wed May 25 16:19:26 EDT 2005

Neil wrote:
> Michael Vincent van Rantwijk wrote:
>> We're using several trees and I want to disable the context menu for 
>> treecols, but I don't know how to do this. I've looked on 
>> xulplanet.com but had no luck.
>> I used a dump() in 'onpopupshowing' with 'event.target.localName' and 
>> 'event.originalTarget.localName' but they both showed up as being the 
>> 'menupopup' so that can't be used.
> FYI you were thinking of document.popupNode which will be the tree when 
> using the keyboard context menu key and the treecols or treechildren 
> when using the mouse.

Yes, it was 'document.popupNode' I was looking for, thanks.

> The alternative of <treecols oncontextmenu="event.preventDefault();"/> 
> is technically superior for chrome, but won't work for content.

Hm, Mozilla's XBL tree binding sucks, because it should have default 
tooltips without additional <tooltip> and JS code. Btw, this is what we 
use to workaround this bug;

<tree id="... tooltip="TreeTooltip" context="_child"...
<menupopup onpopupshowing="initContextMenu(event);">
<tooltip id="TreeTooltip" onpopupshowing="initTreeTooltip(event);">
  <label hidden="true" value="Click here to sort this column"/>
  <label hidden="true" value="Click here to show/hide a column"/>
  <label hidden="true" value="Drag left/right to resize column"/>
  <label hidden="true" value="Right-click to open context menu"/>
<treecols oncontextmenu="event.preventDefault();">
  <treecol ...

     function initTreeTooltip(aEvent)
       var node = document.tooltipNode;
       var nodeName = node.localName;
       var tooltipNode = aEvent.target;

       if (nodeName == "tree" || nodeName.match("menu"))
       tooltipNode.firstChild.hidden = (!node.hasAttribute("sort") || 
nodeName != 'treecol');
       tooltipNode.childNodes[1].hidden = (nodeName != 'treecols');
       tooltipNode.childNodes[2].hidden = (nodeName != 'splitter');
       tooltipNode.lastChild.hidden = (nodeName != 'treechildren');

     function initXPIContextMenu(aEvent)

More information about the Project_owners mailing list