Upgrade to ExtJS 3.1.0 - Released 12/16/2009
[extjs.git] / docs / source / TreeSelectionModel.html
index 7dd0738..58cc22b 100644 (file)
@@ -1,5 +1,6 @@
 <html>\r
 <head>\r
 <html>\r
 <head>\r
+  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    \r
   <title>The source code</title>\r
     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
   <title>The source code</title>\r
     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
@@ -20,7 +21,7 @@ Ext.tree.DefaultSelectionModel = function(config){
         * @param {DefaultSelectionModel} this\r
         * @param {TreeNode} node the new selection\r
         */\r
         * @param {DefaultSelectionModel} this\r
         * @param {TreeNode} node the new selection\r
         */\r
-       "selectionchange",\r
+       'selectionchange',\r
 \r
        <div id="event-Ext.tree.DefaultSelectionModel-beforeselect"></div>/**\r
         * @event beforeselect\r
 \r
        <div id="event-Ext.tree.DefaultSelectionModel-beforeselect"></div>/**\r
         * @event beforeselect\r
@@ -29,7 +30,7 @@ Ext.tree.DefaultSelectionModel = function(config){
         * @param {TreeNode} node the new selection\r
         * @param {TreeNode} node the old selection\r
         */\r
         * @param {TreeNode} node the new selection\r
         * @param {TreeNode} node the old selection\r
         */\r
-       "beforeselect"\r
+       'beforeselect'\r
    );\r
 \r
     Ext.apply(this, config);\r
    );\r
 \r
     Ext.apply(this, config);\r
@@ -39,8 +40,8 @@ Ext.tree.DefaultSelectionModel = function(config){
 Ext.extend(Ext.tree.DefaultSelectionModel, Ext.util.Observable, {\r
     init : function(tree){\r
         this.tree = tree;\r
 Ext.extend(Ext.tree.DefaultSelectionModel, Ext.util.Observable, {\r
     init : function(tree){\r
         this.tree = tree;\r
-        tree.getTreeEl().on("keydown", this.onKeyDown, this);\r
-        tree.on("click", this.onNodeClick, this);\r
+        tree.mon(tree.getTreeEl(), 'keydown', this.onKeyDown, this);\r
+        tree.on('click', this.onNodeClick, this);\r
     },\r
     \r
     onNodeClick : function(node, e){\r
     },\r
     \r
     onNodeClick : function(node, e){\r
@@ -52,17 +53,21 @@ Ext.extend(Ext.tree.DefaultSelectionModel, Ext.util.Observable, {
      * @param {TreeNode} node The node to select\r
      * @return {TreeNode} The selected node\r
      */\r
      * @param {TreeNode} node The node to select\r
      * @return {TreeNode} The selected node\r
      */\r
-    select : function(node){\r
+    select : function(node, /* private*/ selectNextNode){\r
+        // If node is hidden, select the next node in whatever direction was being moved in.\r
+        if (!Ext.fly(node.ui.wrap).isVisible() && selectNextNode) {\r
+            return selectNextNode.call(this, node);\r
+        }\r
         var last = this.selNode;\r
         if(node == last){\r
             node.ui.onSelectedChange(true);\r
         }else if(this.fireEvent('beforeselect', this, node, last) !== false){\r
         var last = this.selNode;\r
         if(node == last){\r
             node.ui.onSelectedChange(true);\r
         }else if(this.fireEvent('beforeselect', this, node, last) !== false){\r
-            if(last){\r
+            if(last && last.ui){\r
                 last.ui.onSelectedChange(false);\r
             }\r
             this.selNode = node;\r
             node.ui.onSelectedChange(true);\r
                 last.ui.onSelectedChange(false);\r
             }\r
             this.selNode = node;\r
             node.ui.onSelectedChange(true);\r
-            this.fireEvent("selectionchange", this, node, last);\r
+            this.fireEvent('selectionchange', this, node, last);\r
         }\r
         return node;\r
     },\r
         }\r
         return node;\r
     },\r
@@ -70,22 +75,26 @@ Ext.extend(Ext.tree.DefaultSelectionModel, Ext.util.Observable, {
     <div id="method-Ext.tree.DefaultSelectionModel-unselect"></div>/**\r
      * Deselect a node.\r
      * @param {TreeNode} node The node to unselect\r
     <div id="method-Ext.tree.DefaultSelectionModel-unselect"></div>/**\r
      * Deselect a node.\r
      * @param {TreeNode} node The node to unselect\r
+     * @param {Boolean} silent True to stop the selectionchange event from firing.\r
      */\r
      */\r
-    unselect : function(node){\r
+    unselect : function(node, silent){\r
         if(this.selNode == node){\r
         if(this.selNode == node){\r
-            this.clearSelections();\r
+            this.clearSelections(silent);\r
         }    \r
     },\r
     \r
     <div id="method-Ext.tree.DefaultSelectionModel-clearSelections"></div>/**\r
      * Clear all selections\r
         }    \r
     },\r
     \r
     <div id="method-Ext.tree.DefaultSelectionModel-clearSelections"></div>/**\r
      * Clear all selections\r
+     * @param {Boolean} silent True to stop the selectionchange event from firing.\r
      */\r
      */\r
-    clearSelections : function(){\r
+    clearSelections : function(silent){\r
         var n = this.selNode;\r
         if(n){\r
             n.ui.onSelectedChange(false);\r
             this.selNode = null;\r
         var n = this.selNode;\r
         if(n){\r
             n.ui.onSelectedChange(false);\r
             this.selNode = null;\r
-            this.fireEvent("selectionchange", this, null);\r
+            if(silent !== true){\r
+                this.fireEvent('selectionchange', this, null);\r
+            }\r
         }\r
         return n;\r
     },\r
         }\r
         return n;\r
     },\r
@@ -111,24 +120,24 @@ Ext.extend(Ext.tree.DefaultSelectionModel, Ext.util.Observable, {
      * Selects the node above the selected node in the tree, intelligently walking the nodes\r
      * @return TreeNode The new selection\r
      */\r
      * Selects the node above the selected node in the tree, intelligently walking the nodes\r
      * @return TreeNode The new selection\r
      */\r
-    selectPrevious : function(){\r
-        var s = this.selNode || this.lastSelNode;\r
-        if(!s){\r
+    selectPrevious : function(/* private */ s){\r
+        if(!(s = s || this.selNode || this.lastSelNode)){\r
             return null;\r
         }\r
             return null;\r
         }\r
+        // Here we pass in the current function to select to indicate the direction we're moving\r
         var ps = s.previousSibling;\r
         if(ps){\r
             if(!ps.isExpanded() || ps.childNodes.length < 1){\r
         var ps = s.previousSibling;\r
         if(ps){\r
             if(!ps.isExpanded() || ps.childNodes.length < 1){\r
-                return this.select(ps);\r
+                return this.select(ps, this.selectPrevious);\r
             } else{\r
                 var lc = ps.lastChild;\r
             } else{\r
                 var lc = ps.lastChild;\r
-                while(lc && lc.isExpanded() && lc.childNodes.length > 0){\r
+                while(lc && lc.isExpanded() && Ext.fly(lc.ui.wrap).isVisible() && lc.childNodes.length > 0){\r
                     lc = lc.lastChild;\r
                 }\r
                     lc = lc.lastChild;\r
                 }\r
-                return this.select(lc);\r
+                return this.select(lc, this.selectPrevious);\r
             }\r
         } else if(s.parentNode && (this.tree.rootVisible || !s.parentNode.isRoot)){\r
             }\r
         } else if(s.parentNode && (this.tree.rootVisible || !s.parentNode.isRoot)){\r
-            return this.select(s.parentNode);\r
+            return this.select(s.parentNode, this.selectPrevious);\r
         }\r
         return null;\r
     },\r
         }\r
         return null;\r
     },\r
@@ -137,20 +146,20 @@ Ext.extend(Ext.tree.DefaultSelectionModel, Ext.util.Observable, {
      * Selects the node above the selected node in the tree, intelligently walking the nodes\r
      * @return TreeNode The new selection\r
      */\r
      * Selects the node above the selected node in the tree, intelligently walking the nodes\r
      * @return TreeNode The new selection\r
      */\r
-    selectNext : function(){\r
-        var s = this.selNode || this.lastSelNode;\r
-        if(!s){\r
+    selectNext : function(/* private */ s){\r
+        if(!(s = s || this.selNode || this.lastSelNode)){\r
             return null;\r
         }\r
             return null;\r
         }\r
-        if(s.firstChild && s.isExpanded()){\r
-             return this.select(s.firstChild);\r
+        // Here we pass in the current function to select to indicate the direction we're moving\r
+        if(s.firstChild && s.isExpanded() && Ext.fly(s.ui.wrap).isVisible()){\r
+             return this.select(s.firstChild, this.selectNext);\r
          }else if(s.nextSibling){\r
          }else if(s.nextSibling){\r
-             return this.select(s.nextSibling);\r
+             return this.select(s.nextSibling, this.selectNext);\r
          }else if(s.parentNode){\r
             var newS = null;\r
             s.parentNode.bubble(function(){\r
                 if(this.nextSibling){\r
          }else if(s.parentNode){\r
             var newS = null;\r
             s.parentNode.bubble(function(){\r
                 if(this.nextSibling){\r
-                    newS = this.getOwnerTree().selModel.select(this.nextSibling);\r
+                    newS = this.getOwnerTree().selModel.select(this.nextSibling, this.selectNext);\r
                     return false;\r
                 }\r
             });\r
                     return false;\r
                 }\r
             });\r
@@ -213,7 +222,7 @@ Ext.tree.MultiSelectionModel = function(config){
         * @param {MultiSelectionModel} this\r
         * @param {Array} nodes Array of the selected nodes\r
         */\r
         * @param {MultiSelectionModel} this\r
         * @param {Array} nodes Array of the selected nodes\r
         */\r
-       "selectionchange"\r
+       'selectionchange'\r
    );\r
     Ext.apply(this, config);\r
     Ext.tree.MultiSelectionModel.superclass.constructor.call(this);\r
    );\r
     Ext.apply(this, config);\r
     Ext.tree.MultiSelectionModel.superclass.constructor.call(this);\r
@@ -222,8 +231,8 @@ Ext.tree.MultiSelectionModel = function(config){
 Ext.extend(Ext.tree.MultiSelectionModel, Ext.util.Observable, {\r
     init : function(tree){\r
         this.tree = tree;\r
 Ext.extend(Ext.tree.MultiSelectionModel, Ext.util.Observable, {\r
     init : function(tree){\r
         this.tree = tree;\r
-        tree.getTreeEl().on("keydown", this.onKeyDown, this);\r
-        tree.on("click", this.onNodeClick, this);\r
+        tree.mon(tree.getTreeEl(), 'keydown', this.onKeyDown, this);\r
+        tree.on('click', this.onNodeClick, this);\r
     },\r
     \r
     onNodeClick : function(node, e){\r
     },\r
     \r
     onNodeClick : function(node, e){\r
@@ -253,7 +262,7 @@ Ext.extend(Ext.tree.MultiSelectionModel, Ext.util.Observable, {
         this.selMap[node.id] = node;\r
         this.lastSelNode = node;\r
         node.ui.onSelectedChange(true);\r
         this.selMap[node.id] = node;\r
         this.lastSelNode = node;\r
         node.ui.onSelectedChange(true);\r
-        this.fireEvent("selectionchange", this, this.selNodes);\r
+        this.fireEvent('selectionchange', this, this.selNodes);\r
         return node;\r
     },\r
     \r
         return node;\r
     },\r
     \r
@@ -270,7 +279,7 @@ Ext.extend(Ext.tree.MultiSelectionModel, Ext.util.Observable, {
                 this.selNodes.splice(index, 1);\r
             }\r
             delete this.selMap[node.id];\r
                 this.selNodes.splice(index, 1);\r
             }\r
             delete this.selMap[node.id];\r
-            this.fireEvent("selectionchange", this, this.selNodes);\r
+            this.fireEvent('selectionchange', this, this.selNodes);\r
         }\r
     },\r
     \r
         }\r
     },\r
     \r
@@ -286,7 +295,7 @@ Ext.extend(Ext.tree.MultiSelectionModel, Ext.util.Observable, {
             this.selNodes = [];\r
             this.selMap = {};\r
             if(suppressEvent !== true){\r
             this.selNodes = [];\r
             this.selMap = {};\r
             if(suppressEvent !== true){\r
-                this.fireEvent("selectionchange", this, this.selNodes);\r
+                this.fireEvent('selectionchange', this, this.selNodes);\r
             }\r
         }\r
     },\r
             }\r
         }\r
     },\r