home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2005 October / Gamestar_77_2005-10_dvd.iso / Programy / nsb-install-8-0.exe / chrome / toolkit.jar / content / mozapps / autofill / advancedViewBindings.xml < prev    next >
Extensible Markup Language  |  2005-07-29  |  5KB  |  164 lines

  1. <?xml version="1.0"?>
  2.  
  3. <bindings id="treeEditBindings"
  4.    xmlns="http://www.mozilla.org/xbl"
  5.    xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  6.  
  7.   <binding id="edittree" extends="chrome://global/content/bindings/tree.xml#tree">
  8.     <content>
  9.       <children includes="treecols"/>
  10.       <xul:stack flex="1">
  11.         <xul:treerows class="tree-rows" flex="1">
  12.           <children/>
  13.         </xul:treerows>
  14.  
  15.         <xul:textbox ileattr="text" left="0" top="0" hidden="true"/>
  16.       </xul:stack>
  17.     </content>
  18.     <implementation>
  19.       <field name="_editOriginalValue">0</field>
  20.       <field name="_editRow">-1</field>
  21.       <field name="_editCol">null</field>
  22.  
  23.       <field name="onAccept">null</field>
  24.       <method name="setEditMode">
  25.         <parameter name="x"/>
  26.         <parameter name="y"/>
  27.         <parameter name="val"/>
  28.         <body>
  29.         <![CDATA[
  30.           var txt = document.getAnonymousElementByAttribute(this, "ileattr", "text");
  31.           if (val){
  32.             if (x < 0) return;
  33.  
  34.             var originalValue = this.view.getCellText(x,y);
  35.             var cellnode = this.getCellNodeAt(x,y);
  36.             if (!(cellnode || this.view.isEditable(x,y))) return;
  37.  
  38.             if (this._editRow >= 0) this._assignValueToCell(txt.value,true);
  39.  
  40.             if (cellnode && cellnode.getAttribute("readonly")) return;
  41.             txt.removeAttribute("hidden");
  42.  
  43.             var treeBox = this.treeBoxObject;
  44.             var outx = {}, outy = {}, outwidth = {}, outheight = {};
  45.             var coords = treeBox.getCoordsForCellItem(x,y,"text",outx,outy,outwidth,outheight);
  46.  
  47.             this._editRow = x;
  48.             this._editCol = y;
  49.  
  50.             txt.setAttribute("left",outx.value-3);
  51.             txt.setAttribute("top",outy.value-3);
  52.             txt.setAttribute("height",outheight.value);
  53.  
  54.             var coords = treeBox.getCoordsForCellItem(x,y,"cell",outx,outy,outwidth,outheight);
  55.             txt.setAttribute("width",outwidth.value - outy.value);
  56.  
  57.             this._editOriginalValue = originalValue;
  58.             if (cellnode) cellnode.setAttribute("label","");
  59.             this.view.setCellText(x,y,"");
  60.  
  61.             txt.value = originalValue;
  62.             txt.select();
  63.             this.setAttribute("editing","true");
  64.  
  65.             txt.addEventListener("keydown", this.fieldKeyDown, false);
  66.             txt.addEventListener("blur", this.fieldChange, true);
  67.           }
  68.           else {
  69.             this.removeAttribute("editing");
  70.  
  71.             txt.setAttribute("hidden","true");
  72.             txt.removeEventListener("keydown", this.fieldKeyDown, false);
  73.             txt.removeEventListener("blur", this.fieldChange, true);
  74.             txt.blur();
  75.           }
  76.         ]]>
  77.         </body>
  78.  
  79.       </method>
  80.       <method name="getCellNodeAt">
  81.         <parameter name="row"/>
  82.         <parameter name="col"/>
  83.         <body>
  84.           var view;
  85.           try {
  86.             view = this.contentView;
  87.           } catch (ex){}
  88.           if (view){
  89.             var elem = view.getItemAtIndex(row);
  90.             if (elem){
  91.               var pos = ((document.getElementById(col).ordinal - 1) >> 1);
  92.               return elem.firstChild.childNodes[pos];
  93.             }
  94.           }
  95.           return null;
  96.         </body>
  97.       </method>
  98.       <method name="fieldKeyDown">
  99.  
  100.         <parameter name="aEvent"/>
  101.         <body>
  102.         <![CDATA[
  103.           var tree = aEvent.target;
  104.           while (tree && tree.tagName != "tree") tree = tree.parentNode;
  105.           if (aEvent.keyCode == 13){
  106.             tree._assignValueToCell(this.value,true);
  107.           }
  108.           if (aEvent.keyCode == 27){
  109.             tree._assignValueToCell(tree._editOriginalValue,false);
  110.           }
  111.           aEvent.preventBubble();
  112.         ]]>
  113.         </body>
  114.       </method>
  115.       <method name="_assignValueToCell">
  116.         <parameter name="value"/>
  117.         <parameter name="acceptMode"/>
  118.         <body>
  119.  
  120.         <![CDATA[
  121.           if (this._editRow == -1) return;
  122.           if (acceptMode && this.onAccept &&
  123.               this.onAccept(this._editRow,this._editCol,this._editOriginalValue,value))
  124.             return;
  125.  
  126.           var cellnode = this.getCellNodeAt(this._editRow,this._editCol);
  127.           if (cellnode) cellnode.setAttribute("label",value);
  128.           this.view.setCellText(this._editRow,this._editCol,value);
  129.           this.treeBoxObject.invalidateCell(this._editRow,this._editCol);
  130.           this._editRow = -1;
  131.           this._editCol = null;
  132.  
  133.           this.setEditMode("normal");
  134.         ]]>
  135.         </body>
  136.       </method>
  137.       <method name="fieldChange">
  138.         <parameter name="aEvent"/>
  139.         <body>
  140.         <![CDATA[
  141.           var tree = aEvent.target;
  142.           while (tree && tree.tagName != "tree") tree = tree.parentNode;
  143.           tree._assignValueToCell(this.value,true);
  144.         ]]>
  145.         </body>
  146.       </method>
  147.  
  148.     </implementation>
  149.     <handlers>
  150.       <handler event="dblclick">
  151.         var treeBox = this.treeBoxObject;
  152.         var row = {};
  153.         var col = {};
  154.         var obj = {};
  155.         treeBox.getCellAt(event.clientX,event.clientY,row,col,obj);
  156.         var txtnode = document.getAnonymousElementByAttribute(this, "ileattr", "text");
  157.         if (txtnode.hasAttribute('hidden'))
  158.             this.setEditMode(row.value,col.value,true);
  159.       </handler>
  160.     </handlers>
  161.   </binding>
  162.  
  163. </bindings>
  164.