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.

190 lines
6.8 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-TreeEditor-method-constructor'><span id='Ext-tree-TreeEditor'>/**
  19. </span></span> * @class Ext.tree.TreeEditor
  20. * @extends Ext.Editor
  21. * Provides editor functionality for inline tree node editing. Any valid {@link Ext.form.Field} subclass can be used
  22. * as the editor field.
  23. * @constructor
  24. * @param {TreePanel} tree
  25. * @param {Object} fieldConfig (optional) Either a prebuilt {@link Ext.form.Field} instance or a Field config object
  26. * that will be applied to the default field instance (defaults to a {@link Ext.form.TextField}).
  27. * @param {Object} config (optional) A TreeEditor config object
  28. */
  29. Ext.tree.TreeEditor = function(tree, fc, config){
  30. fc = fc || {};
  31. var field = fc.events ? fc : new Ext.form.TextField(fc);
  32. Ext.tree.TreeEditor.superclass.constructor.call(this, field, config);
  33. this.tree = tree;
  34. if(!tree.rendered){
  35. tree.on('render', this.initEditor, this);
  36. }else{
  37. this.initEditor(tree);
  38. }
  39. };
  40. Ext.extend(Ext.tree.TreeEditor, Ext.Editor, {
  41. <span id='Ext-tree-TreeEditor-cfg-alignment'> /**
  42. </span> * @cfg {String} alignment
  43. * The position to align to (see {@link Ext.Element#alignTo} for more details, defaults to &quot;l-l&quot;).
  44. */
  45. alignment: &quot;l-l&quot;,
  46. // inherit
  47. autoSize: false,
  48. <span id='Ext-tree-TreeEditor-cfg-hideEl'> /**
  49. </span> * @cfg {Boolean} hideEl
  50. * True to hide the bound element while the editor is displayed (defaults to false)
  51. */
  52. hideEl : false,
  53. <span id='Ext-tree-TreeEditor-cfg-cls'> /**
  54. </span> * @cfg {String} cls
  55. * CSS class to apply to the editor (defaults to &quot;x-small-editor x-tree-editor&quot;)
  56. */
  57. cls: &quot;x-small-editor x-tree-editor&quot;,
  58. <span id='Ext-tree-TreeEditor-cfg-shim'> /**
  59. </span> * @cfg {Boolean} shim
  60. * True to shim the editor if selects/iframes could be displayed beneath it (defaults to false)
  61. */
  62. shim:false,
  63. // inherit
  64. shadow:&quot;frame&quot;,
  65. <span id='Ext-tree-TreeEditor-cfg-maxWidth'> /**
  66. </span> * @cfg {Number} maxWidth
  67. * The maximum width in pixels of the editor field (defaults to 250). Note that if the maxWidth would exceed
  68. * the containing tree element's size, it will be automatically limited for you to the container width, taking
  69. * scroll and client offsets into account prior to each edit.
  70. */
  71. maxWidth: 250,
  72. <span id='Ext-tree-TreeEditor-cfg-editDelay'> /**
  73. </span> * @cfg {Number} editDelay The number of milliseconds between clicks to register a double-click that will trigger
  74. * editing on the current node (defaults to 350). If two clicks occur on the same node within this time span,
  75. * the editor for the node will display, otherwise it will be processed as a regular click.
  76. */
  77. editDelay : 350,
  78. initEditor : function(tree){
  79. tree.on({
  80. scope : this,
  81. beforeclick: this.beforeNodeClick,
  82. dblclick : this.onNodeDblClick
  83. });
  84. this.on({
  85. scope : this,
  86. complete : this.updateNode,
  87. beforestartedit: this.fitToTree,
  88. specialkey : this.onSpecialKey
  89. });
  90. this.on('startedit', this.bindScroll, this, {delay:10});
  91. },
  92. // private
  93. fitToTree : function(ed, el){
  94. var td = this.tree.getTreeEl().dom, nd = el.dom;
  95. if(td.scrollLeft &gt; nd.offsetLeft){ // ensure the node left point is visible
  96. td.scrollLeft = nd.offsetLeft;
  97. }
  98. var w = Math.min(
  99. this.maxWidth,
  100. (td.clientWidth &gt; 20 ? td.clientWidth : td.offsetWidth) - Math.max(0, nd.offsetLeft-td.scrollLeft) - /*cushion*/5);
  101. this.setSize(w, '');
  102. },
  103. <span id='Ext-tree-TreeEditor-method-triggerEdit'> /**
  104. </span> * Edit the text of the passed {@link Ext.tree.TreeNode TreeNode}.
  105. * @param node {Ext.tree.TreeNode} The TreeNode to edit. The TreeNode must be {@link Ext.tree.TreeNode#editable editable}.
  106. */
  107. triggerEdit : function(node, defer){
  108. this.completeEdit();
  109. if(node.attributes.editable !== false){
  110. <span id='Ext-tree-TreeEditor-property-editNode'> /**
  111. </span> * The {@link Ext.tree.TreeNode TreeNode} this editor is bound to. Read-only.
  112. * @type Ext.tree.TreeNode
  113. * @property editNode
  114. */
  115. this.editNode = node;
  116. if(this.tree.autoScroll){
  117. Ext.fly(node.ui.getEl()).scrollIntoView(this.tree.body);
  118. }
  119. var value = node.text || '';
  120. if (!Ext.isGecko &amp;&amp; Ext.isEmpty(node.text)){
  121. node.setText('&amp;#160;');
  122. }
  123. this.autoEditTimer = this.startEdit.defer(this.editDelay, this, [node.ui.textNode, value]);
  124. return false;
  125. }
  126. },
  127. // private
  128. bindScroll : function(){
  129. this.tree.getTreeEl().on('scroll', this.cancelEdit, this);
  130. },
  131. // private
  132. beforeNodeClick : function(node, e){
  133. clearTimeout(this.autoEditTimer);
  134. if(this.tree.getSelectionModel().isSelected(node)){
  135. e.stopEvent();
  136. return this.triggerEdit(node);
  137. }
  138. },
  139. onNodeDblClick : function(node, e){
  140. clearTimeout(this.autoEditTimer);
  141. },
  142. // private
  143. updateNode : function(ed, value){
  144. this.tree.getTreeEl().un('scroll', this.cancelEdit, this);
  145. this.editNode.setText(value);
  146. },
  147. // private
  148. onHide : function(){
  149. Ext.tree.TreeEditor.superclass.onHide.call(this);
  150. if(this.editNode){
  151. this.editNode.ui.focus.defer(50, this.editNode.ui);
  152. }
  153. },
  154. // private
  155. onSpecialKey : function(field, e){
  156. var k = e.getKey();
  157. if(k == e.ESC){
  158. e.stopEvent();
  159. this.cancelEdit();
  160. }else if(k == e.ENTER &amp;&amp; !e.hasModifier()){
  161. e.stopEvent();
  162. this.completeEdit();
  163. }
  164. },
  165. onDestroy : function(){
  166. clearTimeout(this.autoEditTimer);
  167. Ext.tree.TreeEditor.superclass.onDestroy.call(this);
  168. var tree = this.tree;
  169. tree.un('beforeclick', this.beforeNodeClick, this);
  170. tree.un('dblclick', this.onNodeDblClick, this);
  171. }
  172. });</pre>
  173. </body>
  174. </html>