2 * @class Ext.ux.TabCloseMenu
3 * Plugin (ptype = 'tabclosemenu') for adding a close context menu to tabs. Note that the menu respects
4 * the closable configuration on the tab. As such, commands like remove others and remove all will not
5 * remove items that are not closable.
8 * @param {Object} config The configuration options
11 Ext.define('Ext.tab.TabCloseMenu', {
12 alias: 'plugin.tabclosemenu',
13 alternateClassName: 'Ext.ux.TabCloseMenu',
16 observable: 'Ext.util.Observable'
20 * @cfg {String} closeTabText
21 * The text for closing the current tab. Defaults to <tt>'Close Tab'</tt>.
23 closeTabText: 'Close Tab',
26 * @cfg {Boolean} showCloseOthers
27 * Indicates whether to show the 'Close Others' option. Defaults to <tt>true</tt>.
29 showCloseOthers: true,
32 * @cfg {String} closeOtherTabsText
33 * The text for closing all tabs except the current one. Defaults to <tt>'Close Other Tabs'</tt>.
35 closeOthersTabsText: 'Close Other Tabs',
38 * @cfg {Boolean} showCloseAll
39 * Indicates whether to show the 'Close All' option. Defaults to <tt>true</tt>.
44 * @cfg {String} closeAllTabsText
45 * <p>The text for closing all tabs. Defaults to <tt>'Close All Tabs'</tt>.
47 closeAllTabsText: 'Close All Tabs',
50 * @cfg {Array} extraItemsHead
51 * An array of additional context menu items to add to the front of the context menu.
56 * @cfg {Array} extraItemsTail
57 * An array of additional context menu items to add to the end of the context menu.
62 constructor: function (config) {
67 this.mixins.observable.constructor.call(this, config);
70 init : function(tabpanel){
71 this.tabPanel = tabpanel;
72 this.tabBar = tabpanel.down("tabbar");
74 this.mon(this.tabPanel, {
76 afterlayout: this.onAfterLayout,
81 onAfterLayout: function() {
82 this.mon(this.tabBar.el, {
84 contextmenu: this.onContextMenu,
89 onBeforeDestroy : function(){
90 Ext.destroy(this.menu);
91 this.callParent(arguments);
95 onContextMenu : function(event, target){
97 menu = me.createMenu(),
100 tab = me.tabBar.getChildByElement(target),
101 index = me.tabBar.items.indexOf(tab);
103 me.item = me.tabPanel.getComponent(index);
104 menu.child('*[text="' + me.closeTabText + '"]').setDisabled(!me.item.closable);
106 if (me.showCloseAll || me.showCloseOthers) {
107 me.tabPanel.items.each(function(item) {
110 if (item != me.item) {
111 disableOthers = false;
118 if (me.showCloseAll) {
119 menu.child('*[text="' + me.closeAllTabsText + '"]').setDisabled(disableAll);
122 if (me.showCloseOthers) {
123 menu.child('*[text="' + me.closeOthersTabsText + '"]').setDisabled(disableOthers);
127 event.preventDefault();
128 me.fireEvent('beforemenu', menu, me.item, me);
130 menu.showAt(event.getXY());
133 createMenu : function() {
138 text: me.closeTabText,
143 if (me.showCloseAll || me.showCloseOthers) {
147 if (me.showCloseOthers) {
149 text: me.closeOthersTabsText,
151 handler: me.onCloseOthers
155 if (me.showCloseAll) {
157 text: me.closeAllTabsText,
159 handler: me.onCloseAll
163 if (me.extraItemsHead) {
164 items = me.extraItemsHead.concat(items);
167 if (me.extraItemsTail) {
168 items = items.concat(me.extraItemsTail);
171 me.menu = Ext.create('Ext.menu.Menu', {
183 onHideMenu: function () {
187 me.fireEvent('aftermenu', me.menu, me);
190 onClose : function(){
191 this.tabPanel.remove(this.item);
194 onCloseOthers : function(){
198 onCloseAll : function(){
202 doClose : function(excludeActive){
205 this.tabPanel.items.each(function(item){
207 if(!excludeActive || item != this.item){
213 Ext.each(items, function(item){
214 this.tabPanel.remove(item);