PullDownMenu.st
changeset 593 86dd024ed773
parent 586 032b3245e53a
child 605 11b03282d684
--- a/PullDownMenu.st	Sat Apr 27 20:13:37 1996 +0200
+++ b/PullDownMenu.st	Sat Apr 27 20:21:37 1996 +0200
@@ -139,91 +139,92 @@
 
 examples 
 "
-	|top menu|
+                                                                        [exBegin]
+        |top menu|
 
-	top := StandardSystemView new.
-	top extent:300@300.
+        top := StandardSystemView new.
+        top extent:300@300.
 
-	menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top.
-	menu labels:#('foo' 'bar').
-	menu selectors:#(foo bar).
-	menu at:#foo
-	     putLabels:#('foo1' 'foo2' 'foo3')
-	     selectors:#(foo1 foo2 foo3)
-	     receiver:nil.
-	menu at:#bar 
-	     putLabels:#('bar1' 'bar2' 'bar3')
-	     selectors:#(bar1 bar2 bar3)
-	     receiver:nil.
-	top open
+        menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top.
+        menu labels:#('foo' 'bar').
+        menu selectors:#(foo bar).
+        menu at:#foo
+             putLabels:#('foo1' 'foo2' 'foo3')
+             selectors:#(foo1 foo2 foo3)
+             receiver:nil.
+        menu at:#bar 
+             putLabels:#('bar1' 'bar2' 'bar3')
+             selectors:#(bar1 bar2 bar3)
+             receiver:nil.
+        top open
 
 
 
     empty entries are possible as selectable items (with non-nil seletor) ...
-
-	|top menu|
+                                                                        [exEnd]
+        |top menu|
 
-	top := StandardSystemView new.
-	top extent:300@300.
+        top := StandardSystemView new.
+        top extent:300@300.
 
-	menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top.
-	menu labels:#('foo' 'bar' 'baz').
-	menu selectors:#(foo bar baz).
-	menu at:#foo
-	     putLabels:#('foo1' 'foo2' 'foo3')
-	     selectors:#(foo1 foo2 foo3)
-	     receiver:nil.
-	menu at:#baz 
-	     putLabels:#('baz1' 'baz2' 'baz3')
-	     selectors:#(baz1 baz2 baz3)
-	     receiver:nil.
-	top open
+        menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top.
+        menu labels:#('foo' 'bar' 'baz').
+        menu selectors:#(foo bar baz).
+        menu at:#foo
+             putLabels:#('foo1' 'foo2' 'foo3')
+             selectors:#(foo1 foo2 foo3)
+             receiver:nil.
+        menu at:#baz 
+             putLabels:#('baz1' 'baz2' 'baz3')
+             selectors:#(baz1 baz2 baz3)
+             receiver:nil.
+        top open
 
 
 
     ... or as separators (with nil selector)
-
-	|top menu|
+                                                                        [exBegin]
+        |top menu|
 
-	top := StandardSystemView new.
-	top extent:500@200.
+        top := StandardSystemView new.
+        top extent:500@200.
 
-	menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top.
-	menu labels:#('foo' '    ' 'bar' ' baz' '    ' 'moreFoo' 'moreBar' 'moreBaz').
-	menu selectors:#(foo nil bar baz nil moreFoo moreBar moreBaz).
-	menu at:#foo
-	     putLabels:#('foo1' 'foo2' 'foo3')
-	     selectors:#(foo1 foo2 foo3)
-	     receiver:nil.
-	menu at:#bar 
-	     putLabels:#('bar1' 'bar2' 'bar3')
-	     selectors:#(bar1 bar2 bar3)
-	     receiver:nil.
-	menu at:#baz 
-	     putLabels:#('baz1' 'baz2' 'baz3')
-	     selectors:#(baz1 baz2 baz3)
-	     receiver:nil.
-	top open
+        menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top.
+        menu labels:#('foo' '    ' 'bar' ' baz' '    ' 'moreFoo' 'moreBar' 'moreBaz').
+        menu selectors:#(foo nil bar baz nil moreFoo moreBar moreBaz).
+        menu at:#foo
+             putLabels:#('foo1' 'foo2' 'foo3')
+             selectors:#(foo1 foo2 foo3)
+             receiver:nil.
+        menu at:#bar 
+             putLabels:#('bar1' 'bar2' 'bar3')
+             selectors:#(bar1 bar2 bar3)
+             receiver:nil.
+        menu at:#baz 
+             putLabels:#('baz1' 'baz2' 'baz3')
+             selectors:#(baz1 baz2 baz3)
+             receiver:nil.
+        top open
 
 
 
 
     use the menus default height
-
-	|top menu|
+                                                                        [exEnd]
+        |top menu|
 
-	top := StandardSystemView new.
-	top extent:300@300.
+        top := StandardSystemView new.
+        top extent:300@300.
 
-	menu := PullDownMenu in:top.
-	menu origin:0.0@0.0 corner:1.0@(menu height).
-	menu labels:#('foo' 'bar').
-	menu selectors:#(foo bar).
-	menu at:#foo
-	     putLabels:#('foo1' 'foo2' 'foo3')
-	     selectors:#(foo1 foo2 foo3)
-	     receiver:nil.
-	top open
+        menu := PullDownMenu in:top.
+        menu origin:0.0@0.0 corner:1.0@(menu height).
+        menu labels:#('foo' 'bar').
+        menu selectors:#(foo bar).
+        menu at:#foo
+             putLabels:#('foo1' 'foo2' 'foo3')
+             selectors:#(foo1 foo2 foo3)
+             receiver:nil.
+        top open
 
 
 
@@ -232,96 +233,97 @@
     you should NOT do it - since if you do so, the styleSheet settings
     are ineffective (which users wont like probably)
     BTW: The styleSheet entries for below are pullDownMenuForegroundColor,
-	 pullDownMenuBackgroundColor and pullDownMenuFont
-
-	|top menu|
+         pullDownMenuBackgroundColor and pullDownMenuFont
+                                                                        [exBegin]
+        |top menu|
 
-	top := StandardSystemView new.
-	menu := PullDownMenu in:top.
-	menu font:(Font family:'courier' size:20).
-	menu foregroundColor:Color red.
-	menu backgroundColor:Color yellow.
-	menu viewBackground:Color yellow.
-	menu showSeparatingLines:true.
+        top := StandardSystemView new.
+        menu := PullDownMenu in:top.
+        menu font:(Font family:'courier' size:20).
+        menu foregroundColor:Color red.
+        menu backgroundColor:Color yellow.
+        menu viewBackground:Color yellow.
+        menu showSeparatingLines:true.
 
-	menu origin:0.0@0.0 corner:1.0@(menu height).
-	menu labels:#('foo' 'bar').
-	menu selectors:#(foo bar).
-	menu at:#foo
-	     putLabels:#('foo1' 'foo2' 'foo3')
-	     selectors:#(foo1 foo2 foo3)
-	     receiver:nil.
-	(menu menuAt:#foo) font:(Font family:'courier' size:36).
-	top open
+        menu origin:0.0@0.0 corner:1.0@(menu height).
+        menu labels:#('foo' 'bar').
+        menu selectors:#(foo bar).
+        menu at:#foo
+             putLabels:#('foo1' 'foo2' 'foo3')
+             selectors:#(foo1 foo2 foo3)
+             receiver:nil.
+        (menu menuAt:#foo) font:(Font family:'courier' size:36).
+        top open
 
 
 
     you can use icons, too ...
-
-	|labels top menu|
+                                                                        [exEnd]
+        |labels top menu|
 
-	top := StandardSystemView new.
-	top extent:300@300.
+        top := StandardSystemView new.
+        top extent:300@300.
 
-	menu := PullDownMenu in:top.
-	menu origin:0.0@0.0 corner:1.0@(menu height).
-	labels := Array with:((Image fromFile:'SmalltalkX.xbm') magnifiedTo:16@16)
-			with:'foo'
-			with:'bar'.
-	menu labels:labels.
-	menu selectors:#(about foo bar).
-	menu at:#about 
-	     putLabels:#('about PullDownMenus')
-	     selectors:#(aboutMenus)
-	     receiver:nil.
-	menu at:#foo
-	     putLabels:#('foo1' 'foo2' 'foo3')
-	     selectors:#(foo1 foo2 foo3)
-	     receiver:nil.
-	top open
+        menu := PullDownMenu in:top.
+        menu origin:0.0@0.0 corner:1.0@(menu height).
+        labels := Array with:((Image fromFile:'SmalltalkX.xbm') magnifiedTo:16@16)
+                        with:'foo'
+                        with:'bar'.
+        menu labels:labels.
+        menu selectors:#(about foo bar).
+        menu at:#about 
+             putLabels:#('about PullDownMenus')
+             selectors:#(aboutMenus)
+             receiver:nil.
+        menu at:#foo
+             putLabels:#('foo1' 'foo2' 'foo3')
+             selectors:#(foo1 foo2 foo3)
+             receiver:nil.
+        top open
 
 
 
     a concrete example (combining things described above)
     (using a Plug, since we have no application class here):
-
-	|labels top menu textView appModel|
+                                                                        [exBegin]
+        |labels top menu textView appModel|
 
-	appModel := Plug new.
-	appModel respondTo:#quit with:[top destroy].
-	appModel respondTo:#showAbout with:[self information:'some info here ...'].
-	appModel respondTo:#help with:[self information:'some help here ...'].
+        appModel := Plug new.
+        appModel respondTo:#quit with:[top destroy].
+        appModel respondTo:#showAbout with:[self information:'some info here ...'].
+        appModel respondTo:#help with:[self information:'some help here ...'].
 
-	top := StandardSystemView new.
-	top extent:300@300.
+        top := StandardSystemView new.
+        top extent:300@300.
 
-	menu := PullDownMenu in:top.
-	menu receiver:appModel.
-	menu origin:0.0@0.0 corner:1.0@(menu height).
+        menu := PullDownMenu in:top.
+        menu receiver:appModel.
+        menu origin:0.0@0.0 corner:1.0@(menu height).
 
-	textView := ScrollableView forView:(EditTextView new).
-	textView origin:0.0@menu height corner:1.0@1.0.
-	top addSubView:textView.
+        textView := ScrollableView forView:(EditTextView new).
+        textView origin:0.0@menu height corner:1.0@1.0.
+        top addSubView:textView.
 
-	labels := Array with:((Image fromFile:'SmalltalkX.xbm') magnifiedTo:16@16)
-			with:'file'
-			with:'edit'
-			with:'help'.
-	menu labels:labels.
-	menu selectors:#(about file edit help).
-	menu at:#about 
-	     putLabels:#('about PullDownMenus')
-	     selectors:#(showAbout)
-	     receiver:appModel.
-	menu at:#file 
-	     putLabels:#('quit')
-	     selectors:#(quit)
-	     receiver:appModel.
-	menu at:#edit 
-	     putLabels:#('copy' 'cut' 'paste')
-	     selectors:#(copySelection cut paste)
-	     receiver:textView.
-	top open
+        labels := Array with:((Image fromFile:'SmalltalkX.xbm') magnifiedTo:16@16)
+                        with:'file'
+                        with:'edit'
+                        with:'help'.
+        menu labels:labels.
+        menu selectors:#(about file edit help).
+        menu at:#about 
+             putLabels:#('about PullDownMenus')
+             selectors:#(showAbout)
+             receiver:appModel.
+        menu at:#file 
+             putLabels:#('quit')
+             selectors:#(quit)
+             receiver:appModel.
+        menu at:#edit 
+             putLabels:#('copy' 'cut' 'paste')
+             selectors:#(copySelection cut paste)
+             receiver:textView.
+        top open
+                                                                        [exEnd]
 "
 ! !
 
@@ -1269,18 +1271,27 @@
 indexOf:stringOrNumber
     "return the index of the menu with title; return 0 if not found.
      stringOrNumber may be a number, a selector from the selectorArray
-     or a string from the title array."
+     or a string from the title array.
+     If stringOrNumber is not a valid item, return 0."
 
     |idx|
 
     stringOrNumber isNumber ifTrue:[
-	^ stringOrNumber
+        ^ stringOrNumber
     ].
     selectors notNil ifTrue:[
-	idx := selectors indexOf:stringOrNumber.
-	idx ~~ 0 ifTrue:[^ idx].
+        idx := selectors indexOf:stringOrNumber.
+        idx ~~ 0 ifTrue:[^ idx].
+    ].
+    stringOrNumber isString ifTrue:[
+        ^ titles indexOf:stringOrNumber
     ].
-    ^ titles indexOf:stringOrNumber
+    (stringOrNumber respondsTo:#string) ifTrue:[
+        ^ titles indexOf:stringOrNumber asString
+    ].
+    ^ 0
+
+    "Modified: 27.4.1996 / 15:25:28 / cg"
 !
 
 performEntry:itemIndex
@@ -1489,5 +1500,5 @@
 !PullDownMenu class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/PullDownMenu.st,v 1.48 1996-04-25 17:30:34 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/PullDownMenu.st,v 1.49 1996-04-27 18:21:17 cg Exp $'
 ! !