3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.tree.TreeEditor"></div>/**
10 * @class Ext.tree.TreeEditor
12 * Provides editor functionality for inline tree node editing. Any valid {@link Ext.form.Field} subclass can be used
13 * as the editor field.
15 * @param {TreePanel} tree
16 * @param {Object} fieldConfig (optional) Either a prebuilt {@link Ext.form.Field} instance or a Field config object
17 * that will be applied to the default field instance (defaults to a {@link Ext.form.TextField}).
18 * @param {Object} config (optional) A TreeEditor config object
20 Ext.tree.TreeEditor = function(tree, fc, config){
22 var field = fc.events ? fc : new Ext.form.TextField(fc);
24 Ext.tree.TreeEditor.superclass.constructor.call(this, field, config);
29 tree.on('render', this.initEditor, this);
31 this.initEditor(tree);
35 Ext.extend(Ext.tree.TreeEditor, Ext.Editor, {
36 <div id="cfg-Ext.tree.TreeEditor-alignment"></div>/**
37 * @cfg {String} alignment
38 * The position to align to (see {@link Ext.Element#alignTo} for more details, defaults to "l-l").
43 <div id="cfg-Ext.tree.TreeEditor-hideEl"></div>/**
44 * @cfg {Boolean} hideEl
45 * True to hide the bound element while the editor is displayed (defaults to false)
48 <div id="cfg-Ext.tree.TreeEditor-cls"></div>/**
50 * CSS class to apply to the editor (defaults to "x-small-editor x-tree-editor")
52 cls: "x-small-editor x-tree-editor",
53 <div id="cfg-Ext.tree.TreeEditor-shim"></div>/**
55 * True to shim the editor if selects/iframes could be displayed beneath it (defaults to false)
60 <div id="cfg-Ext.tree.TreeEditor-maxWidth"></div>/**
61 * @cfg {Number} maxWidth
62 * The maximum width in pixels of the editor field (defaults to 250). Note that if the maxWidth would exceed
63 * the containing tree element's size, it will be automatically limited for you to the container width, taking
64 * scroll and client offsets into account prior to each edit.
67 <div id="cfg-Ext.tree.TreeEditor-editDelay"></div>/**
68 * @cfg {Number} editDelay The number of milliseconds between clicks to register a double-click that will trigger
69 * editing on the current node (defaults to 350). If two clicks occur on the same node within this time span,
70 * the editor for the node will display, otherwise it will be processed as a regular click.
74 initEditor : function(tree){
77 beforeclick: this.beforeNodeClick,
78 dblclick : this.onNodeDblClick
83 complete : this.updateNode,
84 beforestartedit: this.fitToTree,
85 specialkey : this.onSpecialKey
88 this.on('startedit', this.bindScroll, this, {delay:10});
92 fitToTree : function(ed, el){
93 var td = this.tree.getTreeEl().dom, nd = el.dom;
94 if(td.scrollLeft > nd.offsetLeft){ // ensure the node left point is visible
95 td.scrollLeft = nd.offsetLeft;
99 (td.clientWidth > 20 ? td.clientWidth : td.offsetWidth) - Math.max(0, nd.offsetLeft-td.scrollLeft) - /*cushion*/5);
103 <div id="method-Ext.tree.TreeEditor-triggerEdit"></div>/**
104 * 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}.
107 triggerEdit : function(node, defer){
109 if(node.attributes.editable !== false){
110 <div id="prop-Ext.tree.TreeEditor-editNode"></div>/**
111 * The {@link Ext.tree.TreeNode TreeNode} this editor is bound to. Read-only.
112 * @type Ext.tree.TreeNode
115 this.editNode = node;
116 if(this.tree.autoScroll){
117 Ext.fly(node.ui.getEl()).scrollIntoView(this.tree.body);
119 var value = node.text || '';
120 if (!Ext.isGecko && Ext.isEmpty(node.text)){
121 node.setText(' ');
123 this.autoEditTimer = this.startEdit.defer(this.editDelay, this, [node.ui.textNode, value]);
129 bindScroll : function(){
130 this.tree.getTreeEl().on('scroll', this.cancelEdit, this);
134 beforeNodeClick : function(node, e){
135 clearTimeout(this.autoEditTimer);
136 if(this.tree.getSelectionModel().isSelected(node)){
138 return this.triggerEdit(node);
142 onNodeDblClick : function(node, e){
143 clearTimeout(this.autoEditTimer);
147 updateNode : function(ed, value){
148 this.tree.getTreeEl().un('scroll', this.cancelEdit, this);
149 this.editNode.setText(value);
154 Ext.tree.TreeEditor.superclass.onHide.call(this);
156 this.editNode.ui.focus.defer(50, this.editNode.ui);
161 onSpecialKey : function(field, e){
166 }else if(k == e.ENTER && !e.hasModifier()){
172 onDestroy : function(){
173 clearTimeout(this.autoEditTimer);
174 Ext.tree.TreeEditor.superclass.onDestroy.call(this);
175 var tree = this.tree;
176 tree.un('beforeclick', this.beforeNodeClick, this);
177 tree.un('dblclick', this.onNodeDblClick, this);