Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Submenus in extensions (toolbars)

1 view
Skip to first unread message

Ian A. Mason

unread,
Apr 8, 2008, 2:21:16 PM4/8/08
to
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)

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){ }

arc

unread,
Apr 9, 2008, 8:44:02 PM4/9/08
to
On Apr 8, 12:21 pm, "Ian A. Mason" <ian.alistair.ma...@gmail.com>
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.

<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>

Eric H. Jung

unread,
Apr 9, 2008, 10:12:53 PM4/9/08
to dev-ext...@lists.mozilla.org
Multi-level menupopups on toolbar buttons do cause crashing. The workaround is to count popupshowing and popuphiding events when the sub <menupopup/> is triggered. Build the sub-menupopup dynamically (in script) when the first popupshowing event occurs. This is documented somewhere, but I cannot recall where.

----- 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

Ian A. Mason

unread,
Apr 9, 2008, 11:55:33 PM4/9/08
to
Eric,

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

Ian A. Mason

unread,
Apr 10, 2008, 12:00:18 AM4/10/08
to
Alas Tony I wish I were so lucky. No it is definitely
caused by the dynamic construction of the
sumenu. I have an extension that does nothing but
make one button dropdown with the dreaded nesting.
Crashes my (2.*) browser (on Linux) every time without
fail (selecting the submenu). On windows it doesn't
crash the browser, but does make it sick enough
that I have to kill it from the task manager, even 3b5.

Ian A. Mason

unread,
Apr 10, 2008, 1:26:45 PM4/10/08
to
Eric, I am now one happy chappy! Thanks.

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!

Ian A. Mason

unread,
Apr 11, 2008, 1:00:54 PM4/11/08
to
For anyone else who finds themselves is a similar situation:

http://jlambda.com/~iam/submenu_bug/

0 new messages