class: PopUpMenu
authorClaus Gittinger <cg@exept.de>
Wed, 28 Aug 2013 16:50:58 +0200
changeset 4686 4af1a7c70580
parent 4685 717be378400e
child 4687 2ab92c301044
class: PopUpMenu added: #memorizeLastSelection: comment/format in: #startUpWithHeading: changed: #realize
PopUpMenu.st
--- a/PopUpMenu.st	Wed Aug 28 14:11:55 2013 +0200
+++ b/PopUpMenu.st	Wed Aug 28 16:50:58 2013 +0200
@@ -1009,8 +1009,7 @@
 
     defaultHideOnRelease := false.
     (vector := menuView labels) notNil ifTrue:[
-        menuView labels:(Array with:aString
-                               with:'=') , vector.
+        menuView labels:(Array with:aString with:'=') , vector.
     ].
     (vector := menuView selectors) notNil ifTrue:[
         menuView selectors:#(nil nil) , vector.
@@ -1070,6 +1069,14 @@
     "return true, if the item at anIndexOrName is enabled"
 
     ^ menuView isEnabled:indexOrName
+!
+
+memorizeLastSelection:index
+    "normally, a popup menu comes up unselected, even if reused.
+     This can be used to arrange for an initial selection to be shown"
+
+    lastSelection := index.
+    memorize := true.
 ! !
 
 !PopUpMenu methodsFor:'accessing-items'!
@@ -1667,7 +1674,11 @@
 !
 
 realize
-    menuView deselectWithoutRedraw.
+    (memorize == true and:[lastSelection notNil]) ifTrue:[
+        menuView setSelection:lastSelection.
+    ] ifFalse:[
+        menuView deselectWithoutRedraw.
+    ].
     super realize.
     hideOnRelease := defaultHideOnRelease.
 ! !
@@ -1675,10 +1686,10 @@
 !PopUpMenu class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.113 2013-08-28 12:11:55 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.114 2013-08-28 14:50:58 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.113 2013-08-28 12:11:55 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.114 2013-08-28 14:50:58 cg Exp $'
 ! !