+hideOnKeyFilter
authorClaus Gittinger <cg@exept.de>
Fri, 25 Aug 2006 12:26:27 +0200
changeset 3365 efa2c707567a
parent 3364 d77d6254c38e
child 3366 0df1eb5da5aa
+hideOnKeyFilter
PopUpMenu.st
--- a/PopUpMenu.st	Thu Aug 24 23:20:35 2006 +0200
+++ b/PopUpMenu.st	Fri Aug 25 12:26:27 2006 +0200
@@ -14,7 +14,8 @@
 
 PopUpView subclass:#PopUpMenu
 	instanceVariableNames:'menuView lastSelection memorize hideOnLeave actionLabels
-		actionLines actionValues hideOnRelease defaultHideOnRelease'
+		actionLines actionValues hideOnRelease defaultHideOnRelease
+		hideOnAnyKey hideOnKeyFilter'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Views-Menus'
@@ -1016,6 +1017,12 @@
 
 !PopUpMenu methodsFor:'accessing-behavior'!
 
+hideOnKeyFilter:aBlock
+    "set a filter, which determines if a key should lead to closing the menu."
+
+    hideOnKeyFilter := aBlock
+!
+
 hideOnLeave:aBoolean
     "set/clear the hideOnLeave attribute, which controls
      if the menu should be hidden when the pointer leaves
@@ -1410,23 +1417,26 @@
 keyPress:key x:x y:y
     <resource: #keyboard (#Tab)>
 
-"/    (x isNil or:[x == 0]) ifTrue:[
-"/        "/ already redelegated
-"/        ^ self
-"/    ].
+    hideOnKeyFilter notNil ifTrue:[
+        (hideOnKeyFilter value:key) ifTrue:[
+            self hide.
+            ^ self.
+        ].
+    ].
 
     key == #Tab ifTrue:[
         self hide.
         super keyPress:key x:x y:y.
+        ^ self.
+    ].
+
+    x == 0 ifTrue:[
+        menuView keyPress:key x:nil y:nil.
     ] ifFalse:[
-        x == 0 ifTrue:[
-            menuView keyPress:key x:nil y:nil.
-        ] ifFalse:[
-            x notNil ifTrue:[
-                "/ already redelegated
-                menuView keyPress:key x:x y:y.
-            ].
-        ]
+        x notNil ifTrue:[
+            "/ already redelegated
+            menuView keyPress:key x:x y:y.
+        ].
     ].
 
     "Modified: / 6.12.1997 / 01:53:08 / cg"
@@ -1595,5 +1605,5 @@
 !PopUpMenu class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.97 2006-01-09 08:49:39 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.98 2006-08-25 10:26:27 cg Exp $'
 ! !