PDA

View Full Version : [FIXED-618] Ext.ux.TabCloseMenu: improvements and fixes (patch)



uwolfer
22 Feb 2010, 8:15 AM
I have done some work in Ext.ux.TabCloseMenu:

new feature: new menu item to close all closable tabs
new feature: ability to translate the plugin (via overrides, as usual)
major code and documentation cleanups




/*!
* Ext JS Library 3.1.1
* Copyright(c) 2006-2010 Ext JS, LLC
* [email protected]
* http://www.extjs.com/license
*/
/**
* @class Ext.ux.TabCloseMenu
* @extends Object
* Plugin (ptype = 'tabclosemenu') for adding a close context menu to tabs.
*
* @ptype tabclosemenu
*/
Ext.ux.TabCloseMenu = Ext.extend(Object, {
// private
menu: null,
// private
ctxItem: null,

/**
* @cfg {String} closeTabText
* <p>The context menu item text to close the current tab. Default is 'Close Tab'</p>
*/
closeTabText: 'Close Tab',

/**
* @cfg {String} closeOtherTabsText
* <p>The context menu item text to close all tabs, but not the current one. Default is 'Close Other Tabs'</p>
*/
closeOtherTabsText: 'Close Other Tabs',

/**
* @cfg {String} closeAllTabsText
* <p>The context menu item text to close all tabs. Default is 'Close All Tabs'</p>
*/
closeAllTabsText: 'Close All Tabs',

//public
init: function(tabs) {
tabs.on('contextmenu', this.onContextMenu, this);
},

// private
onContextMenu: function(tabs, item, e) {
if (!this.menu) { // create context menu on first right click
this.menu = new Ext.menu.Menu({
items: [{
id: tabs.id + '-close',
text: this.closeTabText,
handler: function() {
tabs.remove(this.ctxItem);
},
scope: this
},
{
id: tabs.id + '-close-others',
text: this.closeOtherTabsText,
handler: function() {
tabs.items.each(function(item) {
if (item.closable && item !== this.ctxItem) {
tabs.remove(item);
}
},
this);
},
scope: this
},
{
id: tabs.id + '-close-all',
text: this.closeAllTabsText,
handler: function() {
tabs.items.each(function(item) {
if (item.closable) {
tabs.remove(item);
}
});
},
scope: this
}]
});
}
this.ctxItem = item;
var items = this.menu.items;
items.get(tabs.id + '-close').setDisabled(!item.closable);
var disableOthers = true;
var disableAll = true;
tabs.items.each(function() {
if (this.closable) {
disableAll = false;
if (this !== item) {
disableOthers = false;
return false;
}
}
});
items.get(tabs.id + '-close-others').setDisabled(disableOthers);
items.get(tabs.id + '-close-all').setDisabled(disableAll);
e.stopEvent();
this.menu.showAt(e.getPoint());
}
});

Ext.preg('tabclosemenu', Ext.ux.TabCloseMenu);


(Btw, why don't you allow .js file uploads...? ;) )

Jamie Avins
22 Feb 2010, 9:22 AM
We will take a look at it for the next minor revision.

mystix
22 Feb 2010, 10:03 AM
Btw, why don't you allow .js file uploads...? ;)

why don't you just paste your code in between a pair of
tags? ;)
(so ppl like me can read it without having to download stuff)

evant
24 Feb 2010, 1:48 AM
This is in SVN, will be part of 3.2.