--- a/PopUpMenu.st Sat Mar 25 23:22:05 1995 +0100
+++ b/PopUpMenu.st Sun Mar 26 22:16:09 1995 +0200
@@ -23,7 +23,7 @@
COPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.16 1995-03-25 22:20:58 claus Exp $
+$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.17 1995-03-26 20:15:57 claus Exp $
'!
!PopUpMenu class methodsFor:'documentation'!
@@ -44,7 +44,7 @@
version
"
-$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.16 1995-03-25 22:20:58 claus Exp $
+$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.17 1995-03-26 20:15:57 claus Exp $
"
!
@@ -57,6 +57,18 @@
PopUpMenus are usually created with a list of labels, selectors and a
receivier. Once activated, the specified receiver will be sent a
'selector'-message.
+
+ PopupMenus may be either assigned statically to a view (via the #middleButtonMenu:
+ message) or created dynamically as required.
+ Static definition makes sense, if the menu stays constant and you want to
+ assign it once for the lifetime of the view.
+
+ Dynamic menus are easier to use, if the number of or look of the entries has to
+ change according the internal state of some model. Also, this is the ST-80 way
+ of using popupMenus. For dynamic popups, the views model is asked for a menu
+ via the #menuSelector each time a button press occurs.
+
+ See examples section for more.
"
!
@@ -99,8 +111,11 @@
p showAtPointer
Normally, you do not show the menu explicitely, but install
- it as a middleButtonMenu of some view. (Views button-event handler
- will show it when the button is pressed ...)
+ it as a either as middleButtonMenu of some view or return it from
+ a model.
+ (Views/Controllers button-event handler will show it when the middle
+ button is pressed ...)
+ Static menu:
|v m|
@@ -115,6 +130,27 @@
v middleButtonMenu:m.
v open
+ Dynamic menu:
+ (since we need some model which responds to a menu-message,
+ we use a plug in the example below; normally, this would be your model)
+
+ |v model|
+
+ model := Plug new.
+ model respondTo:#getMenu with:[PopUpMenu labels:#('foo' 'par')
+ selectors:#(foo bar)].
+ model respondTo:#foo with:[Transcript showCr:'models foo called'].
+ model respondTo:#bar with:[Transcript showCr:'models bar called'].
+
+ v := View new.
+ v model:model; menu:#getMenu.
+ v open
+
+ Dynamic menus are the MVC-way (i.e. ST-80) way of doing things.
+ They are usually easier to use, if the menu changes depending on the models
+ state. (for example, see the systemBrowsers menus being different when
+ things are selected ...)
+
It is also possible, to add check-mark entries, with an entry string
starting with the special sequence '\c' (for check-mark). The value
passed will be the truth-state of the check-mark.
@@ -510,19 +546,22 @@
"tell the submenu to notify me when action is performed"
aMenu superMenu:self.
- "|v m|
+ "
+ |v m someObject|
+
v := View new.
m := PopUpMenu labels:#('1' '2' '3')
selectors:#(one two nil)
- receiver:v
+ receiver:someObject
for:nil.
m subMenuAt:3 put:(PopUpMenu
labels:#('a' 'b' 'c')
selectors:#(a b c)
- receiver:v
+ receiver:someObject
for:nil).
v middleButtonMenu:m.
- v realize"
+ v realize
+ "
!
numberOfItems
@@ -741,7 +780,9 @@
pointerEnter:state x:x y:y
"catch quick release of button"
- state == 0 ifTrue:[^ self hide].
+ hideOnLeave ifTrue:[
+ state == 0 ifTrue:[^ self hide].
+ ]
!
pointerLeave:state
@@ -788,4 +829,9 @@
menuView superMenu submenuTriggered
].
menuView buttonRelease:button x:x y:y.
+!
+
+keyPress:key x:x y:y
+"/ hideOnRelease := true.
+ menuView keyPress:key x:x y:y.
! !