1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
</head>
<body onload="prettyPrint();">
<pre class="prettyprint lang-js">/*!
* Ext JS Library 3.3.1
* Copyright(c) 2006-2010 Sencha Inc.
* licensing@sencha.com
* http://www.sencha.com/license
*/
<div id="cls-Ext.ux.TabCloseMenu"></div>/**
* @class Ext.ux.TabCloseMenu
* @extends Object
* Plugin (ptype = 'tabclosemenu') for adding a close context menu to tabs. Note that the menu respects
* the closable configuration on the tab. As such, commands like remove others and remove all will not
* remove items that are not closable.
*
* @constructor
* @param {Object} config The configuration options
* @ptype tabclosemenu
*/
Ext.ux.TabCloseMenu = Ext.extend(Object, {
<div id="cfg-Ext.ux.TabCloseMenu-closeTabText"></div>/**
* @cfg {String} closeTabText
* The text for closing the current tab. Defaults to <tt>'Close Tab'</tt>.
*/
closeTabText: 'Close Tab',
<div id="cfg-Ext.ux.TabCloseMenu-closeOtherTabsText"></div>/**
* @cfg {String} closeOtherTabsText
* The text for closing all tabs except the current one. Defaults to <tt>'Close Other Tabs'</tt>.
*/
closeOtherTabsText: 'Close Other Tabs',
<div id="cfg-Ext.ux.TabCloseMenu-showCloseAll"></div>/**
* @cfg {Boolean} showCloseAll
* Indicates whether to show the 'Close All' option. Defaults to <tt>true</tt>.
*/
showCloseAll: true,
<div id="cfg-Ext.ux.TabCloseMenu-closeAllTabsText"></div>/**
* @cfg {String} closeAllTabsText
* <p>The text for closing all tabs. Defaults to <tt>'Close All Tabs'</tt>.
*/
closeAllTabsText: 'Close All Tabs',
constructor : function(config){
Ext.apply(this, config || {});
},
//public
init : function(tabs){
this.tabs = tabs;
tabs.on({
scope: this,
contextmenu: this.onContextMenu,
destroy: this.destroy
});
},
destroy : function(){
Ext.destroy(this.menu);
delete this.menu;
delete this.tabs;
delete this.active;
},
// private
onContextMenu : function(tabs, item, e){
this.active = item;
var m = this.createMenu(),
disableAll = true,
disableOthers = true,
closeAll = m.getComponent('closeall');
m.getComponent('close').setDisabled(!item.closable);
tabs.items.each(function(){
if(this.closable){
disableAll = false;
if(this != item){
disableOthers = false;
return false;
}
}
});
m.getComponent('closeothers').setDisabled(disableOthers);
if(closeAll){
closeAll.setDisabled(disableAll);
}
e.stopEvent();
m.showAt(e.getPoint());
},
createMenu : function(){
if(!this.menu){
var items = [{
itemId: 'close',
text: this.closeTabText,
scope: this,
handler: this.onClose
}];
if(this.showCloseAll){
items.push('-');
}
items.push({
itemId: 'closeothers',
text: this.closeOtherTabsText,
scope: this,
handler: this.onCloseOthers
});
if(this.showCloseAll){
items.push({
itemId: 'closeall',
text: this.closeAllTabsText,
scope: this,
handler: this.onCloseAll
});
}
this.menu = new Ext.menu.Menu({
items: items
});
}
return this.menu;
},
onClose : function(){
this.tabs.remove(this.active);
},
onCloseOthers : function(){
this.doClose(true);
},
onCloseAll : function(){
this.doClose(false);
},
doClose : function(excludeActive){
var items = [];
this.tabs.items.each(function(item){
if(item.closable){
if(!excludeActive || item != this.active){
items.push(item);
}
}
}, this);
Ext.each(items, function(item){
this.tabs.remove(item);
}, this);
}
});
Ext.preg('tabclosemenu', Ext.ux.TabCloseMenu);</pre>
</body>
</html>
|