ST-80 compatible features addded
authorca
Tue, 27 May 1997 11:11:29 +0200
changeset 584 9a4c30f7586f
parent 583 f3b3936710c1
child 585 458fc4cd1437
ST-80 compatible features addded
Menu.st
MenuItem.st
--- a/Menu.st	Sun May 25 15:10:47 1997 +0200
+++ b/Menu.st	Tue May 27 11:11:29 1997 +0200
@@ -55,6 +55,32 @@
 
     groupSizes := something.!
 
+labelAt:anIndex
+    "gets the label of the menu item at the given index or nil
+    "
+    |item|
+
+    (item := self menuItemAt:anIndex) notNil ifTrue:[
+        ^ item label
+    ].
+  ^ nil
+
+!
+
+labelAtValue:aValue
+    "gets the label of the menu item assigned to value
+    "
+    |item|
+
+    item := self menuAndSubmenusDetectItem:[:anItem| anItem value == aValue ].
+
+    item notNil ifTrue:[
+        ^ item label
+    ].
+  ^ nil
+
+!
+
 labels
     "return a collection of labels from my items"
 
@@ -79,7 +105,13 @@
 !
 
 menuItemAt:index
-    ^ items at:index
+    "gets the menu item at the given index. When the index is out of bounds
+     nil is returned
+    "
+    (index > 0 and:[index <= items size]) ifTrue:[
+        ^ items at:index
+    ].
+  ^ nil
 !
 
 menuItems
@@ -139,12 +171,12 @@
 
 !Menu methodsFor:'accessing resource'!
 
-findGuiResourcesIn:aResourceContainer
+findGuiResourcesIn:aResourceContainerOrApplication
     "setup a resource owner
     "
-    aResourceContainer notNil ifTrue:[
+    aResourceContainerOrApplication notNil ifTrue:[
         items notNil ifTrue:[
-            items do:[:anItem| anItem findGuiResourcesIn:aResourceContainer ]
+            items do:[:anItem| anItem findGuiResourcesIn:aResourceContainerOrApplication ]
         ]
     ]
 
@@ -277,16 +309,73 @@
   ^ coll asArray
 ! !
 
+!Menu methodsFor:'enumerating'!
+
+menuAndSubmenusDetectItem:aOneArgBlock
+    "evaluate the block for each item in the current menu and all
+     submenus. In case that the block returns a non nil argument,
+     the item will be returned
+    "
+    |sm item|
+
+    items notNil ifTrue:[
+        items do:[:anItem|
+            (aOneArgBlock value:anItem) notNil ifTrue:[
+                ^ anItem
+            ].
+            (sm := anItem submenu) notNil ifTrue:[
+                item := anItem submenu menuAndSubmenusDetectItem:aOneArgBlock.
+                item notNil ifTrue:[
+                    ^ item
+                ]
+            ]
+        ]
+    ].
+  ^ nil
+! !
+
+!Menu methodsFor:'menu items'!
+
+someMenuItemWithValue:aValue
+    "get the menu item assigned with the value; in case that the value
+     is not found nil is returned
+    "
+    ^ self someMenuItemWithValue:aValue ifNone:nil
+!
+
+someMenuItemWithValue:aValue ifNone:exceptionBlock
+    "get the menu item assigned with the value; in case that the value
+     is not found, the given exceptionBlock is executed and returned
+    "
+    |item|
+
+    item := self menuAndSubmenusDetectItem:[:anItem| anItem value == aValue].
+
+    item notNil ifTrue:[
+        ^ item
+    ].
+  ^ exceptionBlock value
+! !
+
+!Menu methodsFor:'queries'!
+
+hasSubMenuAt:anIndex
+    "test whether the menu item at the given index has a submenu
+    "
+    ^ (self menuItemAt:anIndex) hasSubmenu
+! !
+
 !Menu methodsFor:'startup'!
 
 startUp
     "display the menu as a popUp; return the value associated with the
      selected item, 0 if none was selected"
 
-    |menu|
+    |menu result|
 
     menu := MenuPanel menu:self.
-  ^ menu startUp
+    result := menu startUp.
+  ^ result ? 0
 
 "   
         |m|
@@ -312,5 +401,5 @@
 !Menu class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/Menu.st,v 1.10 1997-05-23 14:04:26 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/Menu.st,v 1.11 1997-05-27 09:10:34 ca Exp $'
 ! !
--- a/MenuItem.st	Sun May 25 15:10:47 1997 +0200
+++ b/MenuItem.st	Tue May 27 11:11:29 1997 +0200
@@ -85,7 +85,7 @@
     "gets the labelImage
     "
     adornment notNil ifTrue:[
-        ^ adornment labelImage
+        ^ adornment labelImage value
     ].
   ^ nil
 !
@@ -194,13 +194,15 @@
 
 !MenuItem methodsFor:'accessing resource'!
 
-findGuiResourcesIn:aResourceContainer
+findGuiResourcesIn:aResourceContainerOrApplication
     "setup a resource container
     "
-    |lblAndIcon|
+    |lblImg|
 
-    (lblAndIcon := self labelAndIcon) notNil ifTrue:[
-        lblAndIcon findGuiResourcesIn:aResourceContainer
+    adornment notNil ifTrue:[
+        (lblImg := adornment labelImage) notNil ifTrue:[
+           lblImg findGuiResourcesIn:aResourceContainerOrApplication
+        ]
     ]
 ! !
 
@@ -277,7 +279,7 @@
 !MenuItem methodsFor:'queries'!
 
 hasSubmenu
-    ^ self subMenu notNil
+    ^ self submenu notNil
 
     "Created: 25.2.1997 / 20:56:20 / cg"
 !
@@ -385,5 +387,5 @@
 !MenuItem class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/MenuItem.st,v 1.9 1997-05-23 14:04:09 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/MenuItem.st,v 1.10 1997-05-27 09:11:29 ca Exp $'
 ! !