This is as close as I have come (it has a submenu, but selecting it
crashes the browser)
const XULNS = 'http://www.mozilla.org/keymaster/gatekeeper/
there.is.only.xul';
function populateEventsMenu(event){
try {
var menu = document.getElementById('btn_popup');
removeAllChildren(menu);
for(var j = 0; j < 5; j++){
if(j != 3){
menu.appendChild(createMenuItem("Tab #" + j, j, dummy));
} else {
var submenu = document.createElementNS(XULNS, "menu");
var submenupopup = document.createElementNS(XULNS,
"menupopup");
submenu.setAttribute("label", "Tab #" + j);
submenu.appendChild(submenupopup);
var first = createMenuItem("First item", 7, dummy);
var last = createMenuItem("Last item", 8, dummy);
submenupopup.appendChild(last);
menu.appendChild(submenu);
}
}
} catch(err){
}
}
function createMenuItem(label, value, listener){
var item = document.createElementNS(XULNS, "menuitem");
item.setAttribute("label", label);
item.setAttribute("class", "menuitem-iconic");
item.addEventListener('command', listener, true);
item.setAttribute("value", value);
return item;
}
function dummy(event){ }
Since no one else has replied with anything definitively helpful, I
can offer only some mild assurance:
The structure of what you are doing matches my understanding of how to
to piece together menu/menupopup/menuitem elements (see a known
working structure below). The bug must lie somewhere in the guts of
the rest of your app-specific logic.
<menu>
....
<menu label="&sh.contextmenu.title;"
<menupopup class="menuitem-iconic shContextMenu" >
<menuitem label="&sh.contextmenu.markimage;"
oncommand="SHPI_markAsImage(event);"/>
<menuseparator/>
<menuitem label="&sh.contextmenu.clearmarks;"
oncommand="SHPI_clearAllMarks(event);"/>
</menupopup>
</menu>
...
<menu>
----- Original Message ----
> From: arc <tony.ca...@gmail.com>
> To: dev-ext...@lists.mozilla.org
> Sent: Wednesday, April 9, 2008 8:44:02 PM
> Subject: Re: Submenus in extensions (toolbars)
>
> On Apr 8, 12:21 pm, "Ian A. Mason"
> wrote:
> > Can someone point me to a snippet that constructs a submenu of a menu
> > for a toolbar extension. I've been busy crashing my browser all this
> > morning
> > trying to get what should be a simple task done.
> >
> > This is as close as I have come (it has a submenu, but selecting it
> > crashes the browser)
>
> Since no one else has replied with anything definitively helpful, I
> can offer only some mild assurance:
>
> The structure of what you are doing matches my understanding of how to
> to piece together menu/menupopup/menuitem elements (see a known
> working structure below). The bug must lie somewhere in the guts of
> the rest of your app-specific logic.
>
>
> ....
>
>
>
> oncommand="SHPI_markAsImage(event);"/>
>
>
> oncommand="SHPI_clearAllMarks(event);"/>
>
>
> ...
>
> _______________________________________________
> dev-extensions mailing list
> dev-ext...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-extensions
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Thanks for the hint, if the (link to) details comes back to you
I'd be very grateful. But just knowing that there is a work
around will encourage me. So I notice bad behaviour
(but not crashing) even in 3 beta 5, and it seems like a thread
gets hung that keeps the browser process from shutting
down smoothly.
Thanks, Ian.
> > dev-extensi...@lists.mozilla.org
The actual fix was a bit simpler, but nevertheless, the idea is the
same.
After googling your hint I found:
http://developer.mozilla.org/en/docs/XUL:PopupGuide:PopupEvents
and read it carefully. Most importantly:
"When using nested submenus, make sure to check in the popupshowing
event that the event corresponds to the right popup. This is because
the popup events bubble so the parent menu will recieve a popupshowing
event whenever it opens, or any submenus open."
And now my submenus work and I can get back to doing
something productive! 2.5 days on the little mystery!