support more detectItem mechanisms
authorca
Thu, 09 Apr 1998 13:37:54 +0200
changeset 849 f7d8363fc24f
parent 848 29f1947578b8
child 850 70c2c0e9318f
support more detectItem mechanisms
SelInTree.st
SelectionInTree.st
TreeItem.st
--- a/SelInTree.st	Thu Apr 09 13:37:00 1998 +0200
+++ b/SelInTree.st	Thu Apr 09 13:37:54 1998 +0200
@@ -367,6 +367,33 @@
     self changed:#list.
 ! !
 
+!SelectionInTree methodsFor:'searching'!
+
+detectItem:aOneArgBlock
+    "detect an item the evaluation of the block returns true. The
+     argument to the block is the item.
+    "
+    root notNil ifTrue:[
+        ^ root detectChild:aOneArgBlock
+    ].
+    ^ nil
+
+
+!
+
+detectItem:aTwoArgBlock arguments:aListOfArgs
+    "detect an item the evaluation of the block returns true. The
+     first argument to the block is the item, the second argument
+     the value derived from the argument list at an index
+    "
+    root notNil ifTrue:[
+        ^ root detectChild:aTwoArgBlock arguments:aListOfArgs index:1
+    ].
+    ^ nil
+
+
+! !
+
 !SelectionInTree methodsFor:'selection'!
 
 selection
@@ -495,5 +522,5 @@
 !SelectionInTree class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/Attic/SelInTree.st,v 1.11 1998-04-07 15:12:15 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/Attic/SelInTree.st,v 1.12 1998-04-09 11:37:54 ca Exp $'
 ! !
--- a/SelectionInTree.st	Thu Apr 09 13:37:00 1998 +0200
+++ b/SelectionInTree.st	Thu Apr 09 13:37:54 1998 +0200
@@ -367,6 +367,33 @@
     self changed:#list.
 ! !
 
+!SelectionInTree methodsFor:'searching'!
+
+detectItem:aOneArgBlock
+    "detect an item the evaluation of the block returns true. The
+     argument to the block is the item.
+    "
+    root notNil ifTrue:[
+        ^ root detectChild:aOneArgBlock
+    ].
+    ^ nil
+
+
+!
+
+detectItem:aTwoArgBlock arguments:aListOfArgs
+    "detect an item the evaluation of the block returns true. The
+     first argument to the block is the item, the second argument
+     the value derived from the argument list at an index
+    "
+    root notNil ifTrue:[
+        ^ root detectChild:aTwoArgBlock arguments:aListOfArgs index:1
+    ].
+    ^ nil
+
+
+! !
+
 !SelectionInTree methodsFor:'selection'!
 
 selection
@@ -495,5 +522,5 @@
 !SelectionInTree class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTree.st,v 1.11 1998-04-07 15:12:15 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTree.st,v 1.12 1998-04-09 11:37:54 ca Exp $'
 ! !
--- a/TreeItem.st	Thu Apr 09 13:37:00 1998 +0200
+++ b/TreeItem.st	Thu Apr 09 13:37:54 1998 +0200
@@ -682,7 +682,7 @@
         readChildren ifTrue:[
             self children
         ].
-        (size := self children size) ~~ 0 ifTrue:[
+        (size := children size) ~~ 0 ifTrue:[
             idx := 1.
             size timesRepeat:[
                 aList add:(item := children at:idx).
@@ -811,6 +811,45 @@
 
 !
 
+detectChild:aTwoArgBlock arguments:args
+    "detect a child the evaluation of the block returns true. The
+     first argument to the block is the item, the second argument
+     the value derived from the argument list at 1 ...
+    "
+    ^ self detectChild:aTwoArgBlock arguments:args index:1
+!
+
+detectChild:aTwoArgBlock arguments:args index:idxArgs
+    "detect a child the evaluation of the block returns true. The
+     first argument to the block is the item, the second argument
+     the value derived from the argument list at an index
+    "
+    |num node|
+
+    (num := args size) >= idxArgs ifTrue:[
+        (aTwoArgBlock value:self value:(args at:idxArgs)) ifFalse:[
+            ^ nil
+        ].
+
+        idxArgs == num ifTrue:[
+            ^ self
+        ].
+
+        self children notEmpty ifTrue:[
+            num := idxArgs + 1.
+
+            children do:[:aChild|
+                node := aChild detectChild:aTwoArgBlock arguments:args index:num.
+
+                node notNil ifTrue:[
+                    ^ node
+                ]
+            ]
+        ]
+    ].
+    ^ nil
+!
+
 indexOfChild:aChild
     "get index of a child or 0
     "
@@ -843,5 +882,5 @@
 !TreeItem class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/TreeItem.st,v 1.21 1998-04-08 05:35:02 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/TreeItem.st,v 1.22 1998-04-09 11:37:29 ca Exp $'
 ! !