You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
4.5 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. /**
  16. * @class Ext.ux.TabCloseMenu
  17. * @extends Object
  18. * Plugin (ptype = 'tabclosemenu') for adding a close context menu to tabs. Note that the menu respects
  19. * the closable configuration on the tab. As such, commands like remove others and remove all will not
  20. * remove items that are not closable.
  21. *
  22. * @constructor
  23. * @param {Object} config The configuration options
  24. * @ptype tabclosemenu
  25. */
  26. Ext.ux.TabCloseMenu = Ext.extend(Object, {
  27. /**
  28. * @cfg {String} closeTabText
  29. * The text for closing the current tab. Defaults to <tt>'Close Tab'</tt>.
  30. */
  31. closeTabText: 'Close Tab',
  32. /**
  33. * @cfg {String} closeOtherTabsText
  34. * The text for closing all tabs except the current one. Defaults to <tt>'Close Other Tabs'</tt>.
  35. */
  36. closeOtherTabsText: 'Close Other Tabs',
  37. /**
  38. * @cfg {Boolean} showCloseAll
  39. * Indicates whether to show the 'Close All' option. Defaults to <tt>true</tt>.
  40. */
  41. showCloseAll: true,
  42. /**
  43. * @cfg {String} closeAllTabsText
  44. * <p>The text for closing all tabs. Defaults to <tt>'Close All Tabs'</tt>.
  45. */
  46. closeAllTabsText: 'Close All Tabs',
  47. constructor : function(config){
  48. Ext.apply(this, config || {});
  49. },
  50. //public
  51. init : function(tabs){
  52. this.tabs = tabs;
  53. tabs.on({
  54. scope: this,
  55. contextmenu: this.onContextMenu,
  56. destroy: this.destroy
  57. });
  58. },
  59. destroy : function(){
  60. Ext.destroy(this.menu);
  61. delete this.menu;
  62. delete this.tabs;
  63. delete this.active;
  64. },
  65. // private
  66. onContextMenu : function(tabs, item, e){
  67. this.active = item;
  68. var m = this.createMenu(),
  69. disableAll = true,
  70. disableOthers = true,
  71. closeAll = m.getComponent('closeall');
  72. m.getComponent('close').setDisabled(!item.closable);
  73. tabs.items.each(function(){
  74. if(this.closable){
  75. disableAll = false;
  76. if(this != item){
  77. disableOthers = false;
  78. return false;
  79. }
  80. }
  81. });
  82. m.getComponent('closeothers').setDisabled(disableOthers);
  83. if(closeAll){
  84. closeAll.setDisabled(disableAll);
  85. }
  86. e.stopEvent();
  87. m.showAt(e.getPoint());
  88. },
  89. createMenu : function(){
  90. if(!this.menu){
  91. var items = [{
  92. itemId: 'close',
  93. text: this.closeTabText,
  94. scope: this,
  95. handler: this.onClose
  96. }];
  97. if(this.showCloseAll){
  98. items.push('-');
  99. }
  100. items.push({
  101. itemId: 'closeothers',
  102. text: this.closeOtherTabsText,
  103. scope: this,
  104. handler: this.onCloseOthers
  105. });
  106. if(this.showCloseAll){
  107. items.push({
  108. itemId: 'closeall',
  109. text: this.closeAllTabsText,
  110. scope: this,
  111. handler: this.onCloseAll
  112. });
  113. }
  114. this.menu = new Ext.menu.Menu({
  115. items: items
  116. });
  117. }
  118. return this.menu;
  119. },
  120. onClose : function(){
  121. this.tabs.remove(this.active);
  122. },
  123. onCloseOthers : function(){
  124. this.doClose(true);
  125. },
  126. onCloseAll : function(){
  127. this.doClose(false);
  128. },
  129. doClose : function(excludeActive){
  130. var items = [];
  131. this.tabs.items.each(function(item){
  132. if(item.closable){
  133. if(!excludeActive || item != this.active){
  134. items.push(item);
  135. }
  136. }
  137. }, this);
  138. Ext.each(items, function(item){
  139. this.tabs.remove(item);
  140. }, this);
  141. }
  142. });
  143. Ext.preg('tabclosemenu', Ext.ux.TabCloseMenu);