PDA

View Full Version : tabpanel menu with close and select other tabitems



mdissel
19 Jun 2008, 6:36 AM
Here's a modified sample of the examples\tabs\TabCloseMenu.js that also add menuitems for each tab to quickly select another tab.



// Very simple plugin for adding a close context menu to tabs

Ext.ux.TabCloseMenu = function(){
var tabs, menu, ctxItem;
this.init = function(tp){
tabs = tp;
tabs.on('contextmenu', onContextMenu);
}

function onContextMenu(ts, item, e){
if(!menu){ // create context menu on first right click
menu = new Ext.menu.Menu([{
id: tabs.id + '-close',
text: 'Close Tab',
handler : function(){
tabs.remove(ctxItem);
}
},{
id: tabs.id + '-close-others',
text: 'Close Other Tabs',
handler : function(){
tabs.items.each(function(item){
if(item.closable && item != ctxItem){
tabs.remove(item);
}
});
}
}]);
}
ctxItem = item;
for (var x = menu.items.length -1 ; x >= 2 ; x--){
menu.remove(menu.items.get(x));
}
menu.addSeparator();
var x = -1;
var items = menu.items;
tabs.items.each(function(current, index, length){
menu.add(
new Ext.menu.CheckItem({
group:'tabs',
text:this.title,
tabIndex:index,
checked: this == tabs.getActiveTab(),
handler: function(){
tabs.activate(tabs.items.get(this.tabIndex));
}
})
);
});
items.get(tabs.id + '-close').setDisabled(!item.closable);
var disableOthers = true;
tabs.items.each(function(){
if(this != item && this.closable){
disableOthers = false;
return false;
}
});
items.get(tabs.id + '-close-others').setDisabled(disableOthers);

menu.showAt(e.getPoint());
}
};

JamesC
19 Jun 2008, 9:21 AM
Nice work, but why would a user right click on a tab to then click to activate another - it is easier just to click on the tab they require!

mdissel
19 Jun 2008, 9:39 AM
Not when there are more tabs then visible, for example when using enableTabScroll:true...

JamesC
19 Jun 2008, 12:53 PM
Fair comment!

dellerbie
23 Sep 2008, 11:20 AM
Does anyone know of a plugin that adds an arrow (or some other icon) to the tabs and when clicked, it shows a menu?

If not, I would like to write something like this myself, but I'm not sure how to start.

Any ideas?

Ceeke
21 Oct 2008, 2:09 AM
dellerbie take a look at this:
http://www.freewebs.com/exttabpanelddmenu/

Scorpie
21 Oct 2008, 2:11 AM
Nice plugin :)