ListSelectionBox.st
changeset 4298 331907254f82
parent 4166 b47c8508abbe
child 4407 a4965694f42d
--- a/ListSelectionBox.st	Wed Aug 03 11:01:48 2011 +0200
+++ b/ListSelectionBox.st	Wed Aug 03 13:50:06 2011 +0200
@@ -12,7 +12,7 @@
 "{ Package: 'stx:libwidg' }"
 
 EnterBox subclass:#ListSelectionBox
-	instanceVariableNames:'selectionList selectionChangeCallback useIndex'
+	instanceVariableNames:'list selectionList selectionChangeCallback useIndex searchJob'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Views-DialogBoxes'
@@ -186,7 +186,10 @@
 list:aList
     "set the list to be displayed in selection list"
 
+    list := aList.
     selectionList list:aList
+
+    "Modified: / 03-08-2011 / 12:30:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 selectionChangeCallback:aBlock
@@ -248,6 +251,26 @@
 
 !ListSelectionBox methodsFor:'initialization'!
 
+beLiveSearchBox
+
+    enterField delegate:(
+        KeyboardForwarder 
+            toView:selectionList 
+            condition:[:type :key :view|(key == #CursorUp) or:[key == #CursorDown]]
+            filter:[:key | (key == #CursorUp) or:[key == #CursorDown]]
+        ).
+
+    searchJob := BackgroundJob 
+                named: 'List Selection Box Search Job'
+                on: [self filterList].
+
+    enterField immediateAccept: true.
+    enterField model: ValueHolder new.
+    enterField model onChangeSend: #restart to: searchJob.
+
+    "Created: / 03-08-2011 / 12:27:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 initialize
     |space2 halfSpace v vbw|
 
@@ -356,6 +379,23 @@
     "Modified: 12.5.1996 / 21:51:10 / cg"
 ! !
 
+!ListSelectionBox methodsFor:'private'!
+
+filterList
+
+    | pattern filteredList |
+
+    pattern := enterField model value.
+    pattern isEmptyOrNil ifTrue:[
+        filteredList := list.        
+    ] ifFalse:[
+        filteredList := list select:[:each|each asString startsWith: pattern].
+    ].
+    self sensor pushUserEvent: #list: for: selectionList withArgument: filteredList
+
+    "Created: / 03-08-2011 / 12:27:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !ListSelectionBox methodsFor:'queries'!
 
 preferredExtent
@@ -440,9 +480,9 @@
 !ListSelectionBox class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/ListSelectionBox.st,v 1.60 2010-08-25 20:02:37 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/ListSelectionBox.st,v 1.61 2011-08-03 11:50:06 vrany Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libwidg/ListSelectionBox.st,v 1.60 2010-08-25 20:02:37 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/ListSelectionBox.st,v 1.61 2011-08-03 11:50:06 vrany Exp $'
 ! !