



Hello. I'm trying to write an extension which contains a xul tree, and I want to implement a right-click context menu on the tree. I tried using the mozilla method described here:
http://developer.mozilla.org/en/docs/XUL:PopupGuide:ContextMenus
http://www.mozilla.org/xpfe/xptoolkit/popups.html
But it doesn't work. I tried assigning the popup to all manner of elements in my overlay and no matter how I click no menu appears.
My popup code is:
<popupset>
<menupopup id="kompile_component_popup">
<menuitem label="New component..."/>
<menuseparator/>
<menuitem label="Edit..."/>
<menuseparator/>
<menuitem label="&kompile.ui.label.debug;" autocheck="true"/>
<menu label="Sort">
<menupopup>
<menuitem label="Sort by Name" autocheck="true"/>
<menuitem label="Sort by Date" autocheck="true"/>
</menupopup>
</menu>
</menupopup>
</popupset>
An example of my element is:
<hbox context="kompile_component_popup">
...
</hbox>
Anybody have any ideas why it doesn't work? Thanks.
I just tested the above code and the popups appear correctly on the mouse right-click operation. Works for me in both Firefox and Komodo.
<!DOCTYPE window PUBLIC "-//MOZILLA//DTD XUL V1.0//EN" "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
<window id="yourapplication_window"
windowtype="YourApplication"
title="YourApplication"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
width="800"
height="600"
screenX="20"
screenY="20"
persist="screenX screenY width height"
>
<popupset>
<menupopup id="kompile_component_popup">
<menuitem label="New component..."/>
<menuseparator/>
<menuitem label="Edit..."/>
<menuseparator/>
<menuitem label="Something" autocheck="true"/>
<menu label="Sort">
<menupopup>
<menuitem label="Sort by Name" autocheck="true"/>
<menuitem label="Sort by Date" autocheck="true"/>
</menupopup>
</menu>
</menupopup>
</popupset>
<hbox flex="1" context="kompile_component_popup"/>
</window>
<?xml version="1.0"?> <!DOCTYPE window PUBLIC "-//MOZILLA//DTD XUL V1.0//EN" "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?> <window id="yourapplication_window" windowtype="YourApplication" title="YourApplication" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" width="800" height="600" screenX="20" screenY="20" persist="screenX screenY width height" > <popupset> <menupopup id="kompile_component_popup"> <menuitem label="New component..."/> <menuseparator/> <menuitem label="Edit..."/> <menuseparator/> <menuitem label="Something" autocheck="true"/> <menu label="Sort"> <menupopup> <menuitem label="Sort by Name" autocheck="true"/> <menuitem label="Sort by Date" autocheck="true"/> </menupopup> </menu> </menupopup> </popupset> <hbox flex="1" context="kompile_component_popup"/> </window>Ok, I fixed it. I had the popupset just inside my overlay tag, which I now realise won't work because the popup is not a alteration of an existing object. If I move it to be inside the my tabpanel then it works. I'm new to xul and it's just me making daft mistakes.