PopUpList.st
changeset 2262 2d42623317f0
parent 2174 1245fc1a0654
child 2265 2c20c26e1fab
--- a/PopUpList.st	Thu Sep 07 19:39:31 2000 +0200
+++ b/PopUpList.st	Tue Sep 12 15:02:51 2000 +0200
@@ -401,6 +401,60 @@
      selectionHolder inspect
                                                                         [exEnd]
 
+    provide your own menu (spec could come from a specMethod):
+                                                                        [exBegin]
+     |p myMenu selectionHolder|
+
+     selectionHolder := nil asValue.
+     myMenu :=
+       #(#Menu
+           #(
+            #(#MenuItem
+                #label: 'Oranges'
+                #translateLabel: true
+                #value: #oranges
+            )
+            #(#MenuItem
+                #label: 'Lemons'
+                #translateLabel: true
+                #value: #lemons
+            )
+            #(#MenuItem
+                #label: 'grape'
+                #translateLabel: true
+                #value: #grape
+            )
+            #(#MenuItem
+                #label: '-'
+            )
+            #(#MenuItem
+               #label: 'other'
+               #translateLabel: true
+               #value: #other
+               #submenu: 
+                  #(#Menu
+                     #(
+                      #(#MenuItem
+                         #label: 'margarita'
+                         #translateLabel: true
+                         #value: #margarita
+                       )
+                      #(#MenuItem
+                         #label: 'vine'
+                         #translateLabel: true
+                         #value: #vine
+                       )
+                      )
+                   )
+            )
+          )
+       ) decodeAsLiteralArray.
+     p := PopUpList label:'healthy fruit'.
+     p menu:myMenu.
+     p model:selectionHolder; aspect:#value; change:#value:.
+     selectionHolder inspect.
+     p open.
+                                                                        [exEnd]
 
 "
 ! !
@@ -422,10 +476,14 @@
 !PopUpList methodsFor:'accessing'!
 
 contents
+    "return the current contents"
+
     ^ self label
 !
 
 contents:con
+    "change the contents"
+
     ^ self selection:con
 
     "Modified: 25.5.1996 / 14:20:57 / cg"
@@ -563,7 +621,19 @@
     menuAction := aOneArgBlock
 !
 
+menu:aMenu
+    "explicit change of the menu; 
+     allows for non-list-based, or MenuBuilder-constructed menus to be used.
+     Attention: this bypasses the list/listHolder"
+
+    menu := aMenu.
+!
+
 menu:aMenu default:label
+    "explicit change of the menu and default value; 
+     allows for non-list-based, or MenuBuilder-constructed menus to be used.
+     Attention: this bypasses the list/listHolder"
+
     menu := aMenu.
     defaultLabel := label
 !
@@ -676,6 +746,8 @@
 !
 
 model:aModel
+    "set the model which provides the selection and/or the list"
+
     super model:aModel.
     self getListFromModel.
     self getSelectionFromModel.
@@ -750,8 +822,7 @@
 !PopUpList methodsFor:'event handling'!
 
 keyPress:key x:x y:y
-    (key == Character space
-    or:[key == #Return])ifTrue:[
+    (key == Character space or:[key == #Return])ifTrue:[
         self popMenu.
         ^ self
     ].
@@ -1051,5 +1122,5 @@
 !PopUpList class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/PopUpList.st,v 1.65 2000-04-01 14:30:31 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/PopUpList.st,v 1.66 2000-09-12 13:02:51 cg Exp $'
 ! !