Ensure the tree selection exists before trying to do things to it b=397788 r=jag
authorneil@parkwaycc.co.uk
Mon, 08 Oct 2007 05:10:51 -0700
changeset 6724 82d4133dd16dc55be11680d10937504d62b9cf77
parent 6723 99783a4bf16f3a3d7bd34e18a15537f0e9676aca
child 6725 975baec372f63316103aab4fa7a4ad87f38290a1
push idunknown
push userunknown
push dateunknown
reviewersjag
bugs397788
milestone1.9a9pre
Ensure the tree selection exists before trying to do things to it b=397788 r=jag
xpfe/components/autocomplete/resources/content/autocomplete.xml
--- a/xpfe/components/autocomplete/resources/content/autocomplete.xml
+++ b/xpfe/components/autocomplete/resources/content/autocomplete.xml
@@ -1436,16 +1436,21 @@
       <field name="treebody">
         document.getAnonymousElementByAttribute(this, "anonid", "treebody");
       </field>
 
       <field name="view">
         null
       </field>
 
+      <!-- Setting tree.view doesn't always immediately create a selection,
+           so we ensure the selection by asking the tree for the view. Note:
+           this.view.selection is quicker if we know the selection exists. -->
+      <property name="selection" onget="return this.tree.view.selection;"/>
+
      <property name="pageCount"
                onget="return this.tree.treeBoxObject.getPageLength();"/>
 
      <field name="mLastRows">0</field>
 
       <method name="initialize">
         <body><![CDATA[
         this.showCommentColumn = this.textbox.showCommentColumn;
@@ -1476,17 +1481,17 @@
               this.tree.removeAttribute("collapsed");
             this.tree.setAttribute("height", height);
           }
         ]]></body>
       </method>
 
       <method name="clearSelection">
         <body>
-          this.view.selection.clearSelection();
+          this.selection.clearSelection();
         </body>
       </method>
 
       <method name="selectBy">
         <parameter name="aReverse"/>
         <parameter name="aPage"/>
         <body><![CDATA[
           try {
@@ -1533,25 +1538,25 @@
       <!-- This property is meant to be overriden by bindings extending
            this one.  When the user selects an item from the list by
            hitting enter or clicking, this method can set the value
            of the textbox to a different value if it wants to. -->
       <property name="overrideValue" readonly="true" onget="return null;"/>
 
       <property name="selectedIndex">
         <getter>
-          if (!this.view || !this.view.selection.count)
+          if (!this.view || !this.selection.count)
             return -1;
           var start = {}, end = {};
           this.view.selection.getRangeAt(0, start, end);
           return start.value;
         </getter>
         <setter>
           if (this.view) {
-            this.view.selection.select(val);
+            this.selection.select(val);
             if (val >= 0) {
               this.view.selection.currentIndex = -1;
               this.tree.treeBoxObject.ensureRowIsVisible(val);
             }
           }
           return val;
         </setter>
       </property>