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.

338 lines
12 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-tree-DefaultSelectionModel'>/**
  19. </span> * @class Ext.tree.DefaultSelectionModel
  20. * @extends Ext.util.Observable
  21. * The default single selection for a TreePanel.
  22. */
  23. Ext.tree.DefaultSelectionModel = Ext.extend(Ext.util.Observable, {
  24. <span id='Ext-tree-DefaultSelectionModel-method-constructor'> constructor : function(config){
  25. </span> this.selNode = null;
  26. this.addEvents(
  27. <span id='Ext-tree-DefaultSelectionModel-event-selectionchange'> /**
  28. </span> * @event selectionchange
  29. * Fires when the selected node changes
  30. * @param {DefaultSelectionModel} this
  31. * @param {TreeNode} node the new selection
  32. */
  33. 'selectionchange',
  34. <span id='Ext-tree-DefaultSelectionModel-event-beforeselect'> /**
  35. </span> * @event beforeselect
  36. * Fires before the selected node changes, return false to cancel the change
  37. * @param {DefaultSelectionModel} this
  38. * @param {TreeNode} newNode the new selection
  39. * @param {TreeNode} oldNode the old selection
  40. */
  41. 'beforeselect'
  42. );
  43. Ext.apply(this, config);
  44. Ext.tree.DefaultSelectionModel.superclass.constructor.call(this);
  45. },
  46. <span id='Ext-tree-DefaultSelectionModel-method-init'> init : function(tree){
  47. </span> this.tree = tree;
  48. tree.mon(tree.getTreeEl(), 'keydown', this.onKeyDown, this);
  49. tree.on('click', this.onNodeClick, this);
  50. },
  51. <span id='Ext-tree-DefaultSelectionModel-method-onNodeClick'> onNodeClick : function(node, e){
  52. </span> this.select(node);
  53. },
  54. <span id='Ext-tree-DefaultSelectionModel-method-select'> /**
  55. </span> * Select a node.
  56. * @param {TreeNode} node The node to select
  57. * @return {TreeNode} The selected node
  58. */
  59. select : function(node, /* private*/ selectNextNode){
  60. // If node is hidden, select the next node in whatever direction was being moved in.
  61. if (!Ext.fly(node.ui.wrap).isVisible() &amp;&amp; selectNextNode) {
  62. return selectNextNode.call(this, node);
  63. }
  64. var last = this.selNode;
  65. if(node == last){
  66. node.ui.onSelectedChange(true);
  67. }else if(this.fireEvent('beforeselect', this, node, last) !== false){
  68. if(last &amp;&amp; last.ui){
  69. last.ui.onSelectedChange(false);
  70. }
  71. this.selNode = node;
  72. node.ui.onSelectedChange(true);
  73. this.fireEvent('selectionchange', this, node, last);
  74. }
  75. return node;
  76. },
  77. <span id='Ext-tree-DefaultSelectionModel-method-unselect'> /**
  78. </span> * Deselect a node.
  79. * @param {TreeNode} node The node to unselect
  80. * @param {Boolean} silent True to stop the selectionchange event from firing.
  81. */
  82. unselect : function(node, silent){
  83. if(this.selNode == node){
  84. this.clearSelections(silent);
  85. }
  86. },
  87. <span id='Ext-tree-DefaultSelectionModel-method-clearSelections'> /**
  88. </span> * Clear all selections
  89. * @param {Boolean} silent True to stop the selectionchange event from firing.
  90. */
  91. clearSelections : function(silent){
  92. var n = this.selNode;
  93. if(n){
  94. n.ui.onSelectedChange(false);
  95. this.selNode = null;
  96. if(silent !== true){
  97. this.fireEvent('selectionchange', this, null);
  98. }
  99. }
  100. return n;
  101. },
  102. <span id='Ext-tree-DefaultSelectionModel-method-getSelectedNode'> /**
  103. </span> * Get the selected node
  104. * @return {TreeNode} The selected node
  105. */
  106. getSelectedNode : function(){
  107. return this.selNode;
  108. },
  109. <span id='Ext-tree-DefaultSelectionModel-method-isSelected'> /**
  110. </span> * Returns true if the node is selected
  111. * @param {TreeNode} node The node to check
  112. * @return {Boolean}
  113. */
  114. isSelected : function(node){
  115. return this.selNode == node;
  116. },
  117. <span id='Ext-tree-DefaultSelectionModel-method-selectPrevious'> /**
  118. </span> * Selects the node above the selected node in the tree, intelligently walking the nodes
  119. * @return TreeNode The new selection
  120. */
  121. selectPrevious : function(/* private */ s){
  122. if(!(s = s || this.selNode || this.lastSelNode)){
  123. return null;
  124. }
  125. // Here we pass in the current function to select to indicate the direction we're moving
  126. var ps = s.previousSibling;
  127. if(ps){
  128. if(!ps.isExpanded() || ps.childNodes.length &lt; 1){
  129. return this.select(ps, this.selectPrevious);
  130. } else{
  131. var lc = ps.lastChild;
  132. while(lc &amp;&amp; lc.isExpanded() &amp;&amp; Ext.fly(lc.ui.wrap).isVisible() &amp;&amp; lc.childNodes.length &gt; 0){
  133. lc = lc.lastChild;
  134. }
  135. return this.select(lc, this.selectPrevious);
  136. }
  137. } else if(s.parentNode &amp;&amp; (this.tree.rootVisible || !s.parentNode.isRoot)){
  138. return this.select(s.parentNode, this.selectPrevious);
  139. }
  140. return null;
  141. },
  142. <span id='Ext-tree-DefaultSelectionModel-method-selectNext'> /**
  143. </span> * Selects the node above the selected node in the tree, intelligently walking the nodes
  144. * @return TreeNode The new selection
  145. */
  146. selectNext : function(/* private */ s){
  147. if(!(s = s || this.selNode || this.lastSelNode)){
  148. return null;
  149. }
  150. // Here we pass in the current function to select to indicate the direction we're moving
  151. if(s.firstChild &amp;&amp; s.isExpanded() &amp;&amp; Ext.fly(s.ui.wrap).isVisible()){
  152. return this.select(s.firstChild, this.selectNext);
  153. }else if(s.nextSibling){
  154. return this.select(s.nextSibling, this.selectNext);
  155. }else if(s.parentNode){
  156. var newS = null;
  157. s.parentNode.bubble(function(){
  158. if(this.nextSibling){
  159. newS = this.getOwnerTree().selModel.select(this.nextSibling, this.selectNext);
  160. return false;
  161. }
  162. });
  163. return newS;
  164. }
  165. return null;
  166. },
  167. <span id='Ext-tree-DefaultSelectionModel-method-onKeyDown'> onKeyDown : function(e){
  168. </span> var s = this.selNode || this.lastSelNode;
  169. // undesirable, but required
  170. var sm = this;
  171. if(!s){
  172. return;
  173. }
  174. var k = e.getKey();
  175. switch(k){
  176. case e.DOWN:
  177. e.stopEvent();
  178. this.selectNext();
  179. break;
  180. case e.UP:
  181. e.stopEvent();
  182. this.selectPrevious();
  183. break;
  184. case e.RIGHT:
  185. e.preventDefault();
  186. if(s.hasChildNodes()){
  187. if(!s.isExpanded()){
  188. s.expand();
  189. }else if(s.firstChild){
  190. this.select(s.firstChild, e);
  191. }
  192. }
  193. break;
  194. case e.LEFT:
  195. e.preventDefault();
  196. if(s.hasChildNodes() &amp;&amp; s.isExpanded()){
  197. s.collapse();
  198. }else if(s.parentNode &amp;&amp; (this.tree.rootVisible || s.parentNode != this.tree.getRootNode())){
  199. this.select(s.parentNode, e);
  200. }
  201. break;
  202. };
  203. }
  204. });
  205. <span id='Ext-tree-MultiSelectionModel'>/**
  206. </span> * @class Ext.tree.MultiSelectionModel
  207. * @extends Ext.util.Observable
  208. * Multi selection for a TreePanel.
  209. */
  210. Ext.tree.MultiSelectionModel = Ext.extend(Ext.util.Observable, {
  211. <span id='Ext-tree-MultiSelectionModel-method-constructor'> constructor : function(config){
  212. </span> this.selNodes = [];
  213. this.selMap = {};
  214. this.addEvents(
  215. <span id='Ext-tree-MultiSelectionModel-event-selectionchange'> /**
  216. </span> * @event selectionchange
  217. * Fires when the selected nodes change
  218. * @param {MultiSelectionModel} this
  219. * @param {Array} nodes Array of the selected nodes
  220. */
  221. 'selectionchange'
  222. );
  223. Ext.apply(this, config);
  224. Ext.tree.MultiSelectionModel.superclass.constructor.call(this);
  225. },
  226. <span id='Ext-tree-MultiSelectionModel-method-init'> init : function(tree){
  227. </span> this.tree = tree;
  228. tree.mon(tree.getTreeEl(), 'keydown', this.onKeyDown, this);
  229. tree.on('click', this.onNodeClick, this);
  230. },
  231. <span id='Ext-tree-MultiSelectionModel-method-onNodeClick'> onNodeClick : function(node, e){
  232. </span> if(e.ctrlKey &amp;&amp; this.isSelected(node)){
  233. this.unselect(node);
  234. }else{
  235. this.select(node, e, e.ctrlKey);
  236. }
  237. },
  238. <span id='Ext-tree-MultiSelectionModel-method-select'> /**
  239. </span> * Select a node.
  240. * @param {TreeNode} node The node to select
  241. * @param {EventObject} e (optional) An event associated with the selection
  242. * @param {Boolean} keepExisting (optional) True to retain existing selections
  243. * @return {TreeNode} The selected node
  244. */
  245. select : function(node, e, keepExisting){
  246. if(keepExisting !== true){
  247. this.clearSelections(true);
  248. }
  249. if(this.isSelected(node)){
  250. this.lastSelNode = node;
  251. return node;
  252. }
  253. this.selNodes.push(node);
  254. this.selMap[node.id] = node;
  255. this.lastSelNode = node;
  256. node.ui.onSelectedChange(true);
  257. this.fireEvent('selectionchange', this, this.selNodes);
  258. return node;
  259. },
  260. <span id='Ext-tree-MultiSelectionModel-method-unselect'> /**
  261. </span> * Deselect a node.
  262. * @param {TreeNode} node The node to unselect
  263. */
  264. unselect : function(node){
  265. if(this.selMap[node.id]){
  266. node.ui.onSelectedChange(false);
  267. var sn = this.selNodes;
  268. var index = sn.indexOf(node);
  269. if(index != -1){
  270. this.selNodes.splice(index, 1);
  271. }
  272. delete this.selMap[node.id];
  273. this.fireEvent('selectionchange', this, this.selNodes);
  274. }
  275. },
  276. <span id='Ext-tree-MultiSelectionModel-method-clearSelections'> /**
  277. </span> * Clear all selections
  278. */
  279. clearSelections : function(suppressEvent){
  280. var sn = this.selNodes;
  281. if(sn.length &gt; 0){
  282. for(var i = 0, len = sn.length; i &lt; len; i++){
  283. sn[i].ui.onSelectedChange(false);
  284. }
  285. this.selNodes = [];
  286. this.selMap = {};
  287. if(suppressEvent !== true){
  288. this.fireEvent('selectionchange', this, this.selNodes);
  289. }
  290. }
  291. },
  292. <span id='Ext-tree-MultiSelectionModel-method-isSelected'> /**
  293. </span> * Returns true if the node is selected
  294. * @param {TreeNode} node The node to check
  295. * @return {Boolean}
  296. */
  297. isSelected : function(node){
  298. return this.selMap[node.id] ? true : false;
  299. },
  300. <span id='Ext-tree-MultiSelectionModel-method-getSelectedNodes'> /**
  301. </span> * Returns an array of the selected nodes
  302. * @return {Array}
  303. */
  304. getSelectedNodes : function(){
  305. return this.selNodes.concat([]);
  306. },
  307. <span id='Ext-tree-MultiSelectionModel-property-onKeyDown'> onKeyDown : Ext.tree.DefaultSelectionModel.prototype.onKeyDown,
  308. </span>
  309. <span id='Ext-tree-MultiSelectionModel-property-selectNext'> selectNext : Ext.tree.DefaultSelectionModel.prototype.selectNext,
  310. </span>
  311. <span id='Ext-tree-MultiSelectionModel-property-selectPrevious'> selectPrevious : Ext.tree.DefaultSelectionModel.prototype.selectPrevious
  312. </span>});</pre>
  313. </body>
  314. </html>