3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js"><div id="cls-Ext.tree.TreeEditor"></div>/**
9 * @class Ext.tree.TreeEditor
11 * Provides editor functionality for inline tree node editing. Any valid {@link Ext.form.Field} subclass can be used
12 * as the editor field.
14 * @param {TreePanel} tree
15 * @param {Object} fieldConfig (optional) Either a prebuilt {@link Ext.form.Field} instance or a Field config object
16 * that will be applied to the default field instance (defaults to a {@link Ext.form.TextField}).
17 * @param {Object} config (optional) A TreeEditor config object
19 Ext.tree.TreeEditor = function(tree, fc, config){
21 var field = fc.events ? fc : new Ext.form.TextField(fc);
22 Ext.tree.TreeEditor.superclass.constructor.call(this, field, config);
27 tree.on('render', this.initEditor, this);
29 this.initEditor(tree);
33 Ext.extend(Ext.tree.TreeEditor, Ext.Editor, {
34 <div id="cfg-Ext.tree.TreeEditor-alignment"></div>/**
35 * @cfg {String} alignment
36 * The position to align to (see {@link Ext.Element#alignTo} for more details, defaults to "l-l").
41 <div id="cfg-Ext.tree.TreeEditor-hideEl"></div>/**
42 * @cfg {Boolean} hideEl
43 * True to hide the bound element while the editor is displayed (defaults to false)
46 <div id="cfg-Ext.tree.TreeEditor-cls"></div>/**
48 * CSS class to apply to the editor (defaults to "x-small-editor x-tree-editor")
50 cls: "x-small-editor x-tree-editor",
51 <div id="cfg-Ext.tree.TreeEditor-shim"></div>/**
53 * True to shim the editor if selects/iframes could be displayed beneath it (defaults to false)
58 <div id="cfg-Ext.tree.TreeEditor-maxWidth"></div>/**
59 * @cfg {Number} maxWidth
60 * The maximum width in pixels of the editor field (defaults to 250). Note that if the maxWidth would exceed
61 * the containing tree element's size, it will be automatically limited for you to the container width, taking
62 * scroll and client offsets into account prior to each edit.
65 <div id="cfg-Ext.tree.TreeEditor-editDelay"></div>/**
66 * @cfg {Number} editDelay The number of milliseconds between clicks to register a double-click that will trigger
67 * editing on the current node (defaults to 350). If two clicks occur on the same node within this time span,
68 * the editor for the node will display, otherwise it will be processed as a regular click.
72 initEditor : function(tree){
73 tree.on('beforeclick', this.beforeNodeClick, this);
74 tree.on('dblclick', this.onNodeDblClick, this);
75 this.on('complete', this.updateNode, this);
76 this.on('beforestartedit', this.fitToTree, this);
77 this.on('startedit', this.bindScroll, this, {delay:10});
78 this.on('specialkey', this.onSpecialKey, this);
82 fitToTree : function(ed, el){
83 var td = this.tree.getTreeEl().dom, nd = el.dom;
84 if(td.scrollLeft > nd.offsetLeft){ // ensure the node left point is visible
85 td.scrollLeft = nd.offsetLeft;
89 (td.clientWidth > 20 ? td.clientWidth : td.offsetWidth) - Math.max(0, nd.offsetLeft-td.scrollLeft) - /*cushion*/5);
93 <div id="method-Ext.tree.TreeEditor-triggerEdit"></div>/**
94 * Edit the text of the passed {@link Ext.tree.TreeNode TreeNode}.
95 * @param node {Ext.tree.TreeNode} The TreeNode to edit. The TreeNode must be {@link Ext.tree.TreeNode#editable editable}.
97 triggerEdit : function(node, defer){
99 if(node.attributes.editable !== false){
100 <div id="prop-Ext.tree.TreeEditor-editNode"></div>/**
101 * The {@link Ext.tree.TreeNode TreeNode} this editor is bound to. Read-only.
102 * @type Ext.tree.TreeNode
105 this.editNode = node;
106 if(this.tree.autoScroll){
107 Ext.fly(node.ui.getEl()).scrollIntoView(this.tree.body);
109 var value = node.text || '';
110 if (!Ext.isGecko && Ext.isEmpty(node.text)){
111 node.setText(' ');
113 this.autoEditTimer = this.startEdit.defer(this.editDelay, this, [node.ui.textNode, value]);
119 bindScroll : function(){
120 this.tree.getTreeEl().on('scroll', this.cancelEdit, this);
124 beforeNodeClick : function(node, e){
125 clearTimeout(this.autoEditTimer);
126 if(this.tree.getSelectionModel().isSelected(node)){
128 return this.triggerEdit(node);
132 onNodeDblClick : function(node, e){
133 clearTimeout(this.autoEditTimer);
137 updateNode : function(ed, value){
138 this.tree.getTreeEl().un('scroll', this.cancelEdit, this);
139 this.editNode.setText(value);
144 Ext.tree.TreeEditor.superclass.onHide.call(this);
146 this.editNode.ui.focus.defer(50, this.editNode.ui);
151 onSpecialKey : function(field, e){
156 }else if(k == e.ENTER && !e.hasModifier()){