[Project_owners] Adding to context menu of tabs

Bradley Rintoul brintoul at sbcglobal.net
Mon Feb 28 07:36:26 EST 2005


Neil wrote:

> Bradley Rintoul wrote:
>
>> I'm trying to add a menuitem to the tabbrowser's tab's context menu 
>> (which by default contains New Tab, Reload Tab, etc..) and I've found 
>> the XBL bindings where it needs to be done, I think, but I lack the 
>> knowledge/skill to add my menuitem.  The area looks like this in 
>> tabbrowser.xml:
>>
>>  <binding id="tabbrowser">
>>   <content>
>>      <xul:stringbundle 
>> src="chrome://global/locale/tabbrowser.properties"/>
>>      <xul:tabbox flex="1" eventnode="document" 
>> xbl:inherits="handleCtrlPageUpDown"
>>                  onselect="if (!('updateCurrentBrowser' in 
>> this.parentNode) || event.target.localName != 'tabpanels') return; 
>> this.parentNode.updateCurrentBrowser();">
>>        <xul:hbox class="tabbrowser-strip chromeclass-toolbar" 
>> collapsed="true" tooltip="_child" context="_child">
>>          <xul:tooltip onpopupshowing="event.preventBubble(); if 
>> (document.tooltipNode.hasAttribute('label')) { 
>> this.setAttribute('label', 
>> document.tooltipNode.getAttribute('label')); return true; } return 
>> false;"/>
>>          <xul:menupopup 
>> onpopupshowing="this.parentNode.parentNode.parentNode.updatePopupMenu(this);"> 
>>
>>            <xul:menuitem label="&newTab.label;" 
>> accesskey="&newTab.accesskey;"
>>                          xbl:inherits="oncommand=onnewtab"/>
>>            <xul:menuseparator/>
>>            <xul:menuitem label="&reloadTab.label;" 
>> accesskey="&reloadTab.accesskey;"
>>                          oncommand="var tabbrowser = 
>> this.parentNode.parentNode.parentNode.parentNode;
>>                                     
>> tabbrowser.reloadTab(tabbrowser.mContextTab);"/>
>>           [SNIP]
>>
>> So, where I want to add the menuitem is underneath quite a few 
>> elements under the binding element.  I'm not that up on the XBL spec 
>> and inheritance/extending, so I don't know how to attack this thing.
>
>
> While you can do this you'll conflict with any other extension trying 
> to do this, but here goes:
> Create your own XBL binding extending the default one.
> Copy the entire <contents> section and add the menuitem where you want.
> Add methods as necessary for the new menuitem.
> Extending a method is tricky, so if you need to update the state of 
> your menuitem change the onpopupshowing to call a new method and call 
> the old method from the new method.
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org
> http://mozdev.org/mailman/listinfo/project_owners
>
I guess I'll bail on the idea, then...  I'll try to do it the way 
Tabbrowser Preference does...  Does this seem like a shortcoming in 
XBL?  I have no idea how it could be worked around, but I encountered 
this in my other extension and worked out a solution with someone that 
conflicted with mine.  In that case, it was just fixing a behavioral 
problem, not adding to the content, so maybe it was easier to deal with.


More information about the Project_owners mailing list