diff -r f65545e96d72 -r fb625951b7fc PopUpMenu.st --- a/PopUpMenu.st Sun Jan 14 13:02:38 1996 +0100 +++ b/PopUpMenu.st Sun Jan 14 15:21:47 1996 +0100 @@ -60,41 +60,42 @@ examples " + Examples: - |p| - p := PopUpMenu - labels:#('foo' - 'bar' - 'baz') - selectors:#( - #foo - #bar - #baz) - receiver:nil. - p showAtPointer + |p| + p := PopUpMenu + labels:#('foo' + 'bar' + 'baz') + selectors:#( + #foo + #bar + #baz) + receiver:nil. + p showAtPointer sometimes, you want to specify both selectors and some arguments to be sent; this is done by: - |p| - p := PopUpMenu - labels:#('foo' 'bar' 'baz') - selectors:#(#foo: #bar: #foo:) - args:#(1 2 3) - receiver:nil. - p showAtPointer + |p| + p := PopUpMenu + labels:#('foo' 'bar' 'baz') + selectors:#(#foo: #bar: #foo:) + args:#(1 2 3) + receiver:nil. + p showAtPointer or, the same selector but different arguments: - |p| - p := PopUpMenu - labels:#('foo' 'bar' 'baz') - selectors:#foo: - args:#(1 2 3) - receiver:nil. - p showAtPointer + |p| + p := PopUpMenu + labels:#('foo' 'bar' 'baz') + selectors:#foo: + args:#(1 2 3) + receiver:nil. + p showAtPointer Normally, you do not show the menu explicitely, but install it as a either as middleButtonMenu of some view or return it from @@ -103,34 +104,34 @@ button is pressed ...) Static menu: - |v m| + |v m| - v := View new. - m := PopUpMenu - labels:#('lower' - 'raise' - '-' - 'destroy') - selectors:#(#lower #raise nil #destroy) - receiver:v. - v middleButtonMenu:m. - v open + v := View new. + m := PopUpMenu + labels:#('lower' + 'raise' + '-' + 'destroy') + selectors:#(#lower #raise nil #destroy) + receiver:v. + 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| + |v model| - model := Plug new. - model respondTo:#getMenu with:[PopUpMenu labels:#('foo' 'bar') - selectors:#(foo bar)]. - model respondTo:#foo with:[Transcript showCr:'models foo called']. - model respondTo:#bar with:[Transcript showCr:'models bar called']. + model := Plug new. + model respondTo:#getMenu with:[PopUpMenu labels:#('foo' 'bar') + 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 + 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 @@ -141,16 +142,16 @@ starting with the special sequence '\c' (for check-mark). The value passed will be the truth-state of the check-mark. - |m v| + |m v| - v := View new. - m := PopUpMenu - labels:#('\c foo' - '\c bar') - selectors:#(#value: #value:) - receiver:[:v | Transcript show:'arg: '; showCr:v]. - v middleButtonMenu:m. - v open + v := View new. + m := PopUpMenu + labels:#('\c foo' + '\c bar') + selectors:#(#value: #value:) + receiver:[:v | Transcript show:'arg: '; showCr:v]. + v middleButtonMenu:m. + v open Finally, you can wrap other views into a popup menu (for example, to implement menus with icons or other components). @@ -159,32 +160,32 @@ Currently there is only one class in the system, which can be used this way (PatternMenu in the DrawTool demo): - |v p| + |v p| - v := View new. - p := PatternMenu new. - p patterns:(Array with:Color red - with:Color green - with:Color blue). - v middleButtonMenu:(PopUpMenu forMenu:p). - v open + v := View new. + p := PatternMenu new. + p patterns:(Array with:Color red + with:Color green + with:Color blue). + v middleButtonMenu:(PopUpMenu forMenu:p). + v open or try: - |v p| + |v p| - v := View new. - p := PatternMenu new. - p patterns:(Array with:Color red - with:Color green - with:Color blue). - p selectors:#value:. - p receiver:[:val | v viewBackground:val. v clear]. - p args:(Array with:Color red - with:Color green - with:Color blue). - v middleButtonMenu:(PopUpMenu forMenu:p). - v open + v := View new. + p := PatternMenu new. + p patterns:(Array with:Color red + with:Color green + with:Color blue). + p selectors:#value:. + p receiver:[:val | v viewBackground:val. v clear]. + p args:(Array with:Color red + with:Color green + with:Color blue). + v middleButtonMenu:(PopUpMenu forMenu:p). + v open ST-80 style: @@ -193,47 +194,47 @@ also possible, to use Smalltalk-80 style menus (which return some value from their startup method): - |m selection| + |m selection| - m := PopUpMenu - labels:#('one' 'two' 'three'). - selection := m startUp. - Transcript show:'the selection was: '; showCr:selection + m := PopUpMenu + labels:#('one' 'two' 'three'). + selection := m startUp. + Transcript show:'the selection was: '; showCr:selection startUp will return the entries index, or 0 if there was no selection. You can also specify an array of values to be returned instead of the index: - |m selection| + |m selection| - m := PopUpMenu - labels:#('one' 'two' 'three') - values:#(10 20 30). - selection := m startUp. - Transcript show:'the value was: '; showCr:selection + m := PopUpMenu + labels:#('one' 'two' 'three') + values:#(10 20 30). + selection := m startUp. + Transcript show:'the value was: '; showCr:selection In ST/X style menus, separating lines between entries are created by a '-'-string as its label text (and corresponding nil-entries in the selectors- and args-arrays). In ST-80, you have to pass the indices of the lines in an extra array: - |m selection| + |m selection| - m := PopUpMenu - labels:#('one' 'two' 'three' 'four' 'five') - lines:#(2 4). - selection := m startUp. - Transcript show:'the value was: '; showCr:selection + m := PopUpMenu + labels:#('one' 'two' 'three' 'four' 'five') + lines:#(2 4). + selection := m startUp. + Transcript show:'the value was: '; showCr:selection or: - |m selection| + |m selection| - m := PopUpMenu - labels:#('one' 'two' 'three') - lines:#(2) - values:#(10 20 30). - selection := m startUp. - Transcript show:'the value was: '; showCr:selection + m := PopUpMenu + labels:#('one' 'two' 'three') + lines:#(2) + values:#(10 20 30). + selection := m startUp. + Transcript show:'the value was: '; showCr:selection Use whichever interface you prefer. " @@ -949,5 +950,5 @@ !PopUpMenu class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.30 1996-01-10 19:17:31 cg Exp $' + ^ '$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.31 1996-01-14 14:21:47 cg Exp $' ! !