4 * Copyright(c) 2006-2007, Ext JS, LLC.
6 * Originally Released Under LGPL - original licence link has changed is not relivant.
9 * <script type="text/javascript">
12 * @class Roo.tree.TreeEditor
14 * Provides editor functionality for inline tree node editing. Any valid {@link Roo.form.Field} can be used
15 * as the editor field.
17 * @param {TreePanel} tree
18 * @param {Object} config Either a prebuilt {@link Roo.form.Field} instance or a Field config object
20 Roo.tree.TreeEditor = function(tree, config){
21 config = config || {};
22 var field = config.events ? config : new Roo.form.TextField(config);
23 Roo.tree.TreeEditor.superclass.constructor.call(this, field);
27 tree.on('beforeclick', this.beforeNodeClick, this);
28 tree.getTreeEl().on('mousedown', this.hide, this);
29 this.on('complete', this.updateNode, this);
30 this.on('beforestartedit', this.fitToTree, this);
31 this.on('startedit', this.bindScroll, this, {delay:10});
32 this.on('specialkey', this.onSpecialKey, this);
35 Roo.extend(Roo.tree.TreeEditor, Roo.Editor, {
37 * @cfg {String} alignment
38 * The position to align to (see {@link Roo.Element#alignTo} for more details, defaults to "l-l").
44 * @cfg {Boolean} hideEl
45 * True to hide the bound element while the editor is displayed (defaults to false)
50 * CSS class to apply to the editor (defaults to "x-small-editor x-tree-editor")
52 cls: "x-small-editor x-tree-editor",
55 * True to shim the editor if selects/iframes could be displayed beneath it (defaults to false)
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.
71 fitToTree : function(ed, el){
72 var td = this.tree.getTreeEl().dom, nd = el.dom;
73 if(td.scrollLeft > nd.offsetLeft){ // ensure the node left point is visible
74 td.scrollLeft = nd.offsetLeft;
78 (td.clientWidth > 20 ? td.clientWidth : td.offsetWidth) - Math.max(0, nd.offsetLeft-td.scrollLeft) - /*cushion*/5);
83 triggerEdit : function(node){
86 this.startEdit(node.ui.textNode, node.text);
90 bindScroll : function(){
91 this.tree.getTreeEl().on('scroll', this.cancelEdit, this);
95 beforeNodeClick : function(node, e){
96 var sinceLast = (this.lastClick ? this.lastClick.getElapsed() : 0);
97 this.lastClick = new Date();
98 if(sinceLast > this.editDelay && this.tree.getSelectionModel().isSelected(node)){
100 this.triggerEdit(node);
106 updateNode : function(ed, value){
107 this.tree.getTreeEl().un('scroll', this.cancelEdit, this);
108 this.editNode.setText(value);
113 Roo.tree.TreeEditor.superclass.onHide.call(this);
115 this.editNode.ui.focus();
120 onSpecialKey : function(field, e){
125 }else if(k == e.ENTER && !e.hasModifier()){