--- a/Menu.st Thu May 24 14:51:36 2018 +0200
+++ b/Menu.st Thu May 24 16:12:03 2018 +0200
@@ -49,18 +49,25 @@
documentation
"
- not yet finished Menu class - this will eventually replace
- most of the MenuView and PopUpMenu stuff.
- (and hopefully be ST-80 compatible ...)
+ Menu (aka MenuSpec, that's what it is!!).
+
+ similar to UISpecifications, this describes the look, feel and behavior of
+ popUpMenus, toolbarMenus and window menus.
- For now, only a subset of the full protocol is implemented.
+ Instances of me are usually created from menuSpec methods, which return a literal
+ array description of me.
+ Instances of me are processed by MenuBuilders, which create a real MenuView/MenuPanel
+ from that into a window.
+ Should be relatively VisualWorks compatible (clean room development, by emulating the
+ protocol needed by some public domain VW applications)
+
[author:]
- Claus Gittinger
+ Claus Gittinger
[see also:]
- MenuItem
- PopUpMenu
+ MenuItem
+ PopUpMenu
"
! !
@@ -270,11 +277,12 @@
!
itemAtValue:aValue
- "gets the item which has aValue assigned as value
- "
+ "gets the item which has aValue assigned as value"
+
^ self menuAndSubmenusDetectItem:[:anItem | anItem value == aValue ].
"Created: / 14-03-2017 / 16:12:37 / cg"
+ "Modified (comment): / 24-05-2018 / 16:11:15 / Claus Gittinger"
!
items
@@ -286,8 +294,8 @@
!
labelAt:anIndex
- "gets the label of the menu item at the given index or nil
- "
+ "gets the label of the menu item at the given index or nil"
+
|item|
(item := self menuItemAt:anIndex) notNil ifTrue:[
@@ -295,12 +303,13 @@
].
^ nil
- "Modified: / 2.2.1998 / 13:28:32 / cg"
+ "Modified: / 02-02-1998 / 13:28:32 / cg"
+ "Modified (comment): / 24-05-2018 / 16:11:26 / Claus Gittinger"
!
labelAtValue:aValue
- "gets the label of the menu item assigned to value
- "
+ "gets the label of the menu item assigned to value"
+
|item|
item := self menuAndSubmenusDetectItem:[:anItem | anItem value == aValue ].
@@ -310,7 +319,8 @@
].
^ nil
- "Modified: / 2.2.1998 / 13:28:28 / cg"
+ "Modified: / 02-02-1998 / 13:28:28 / cg"
+ "Modified (comment): / 24-05-2018 / 16:11:30 / Claus Gittinger"
!
labels
@@ -461,10 +471,11 @@
].
values notNil ifTrue:[
- items with:values do:[:anItem :aValue |anItem value:aValue]
+ items with:values do:[:anItem :eachValue |anItem value:eachValue]
].
- "Modified: / 19.4.1998 / 11:47:34 / cg"
+ "Modified: / 19-04-1998 / 11:47:34 / cg"
+ "Modified (format): / 24-05-2018 / 15:18:25 / Claus Gittinger"
!
menuPerformer:something
@@ -863,6 +874,11 @@
enabledInItem := each enabled.
enabledInItem notNil ifTrue:[
enabledInItem isSymbol ifTrue:[
+ anApplicationOrNil isNil ifTrue:[
+ Smalltalk isSmalltalkDevelopmentSystem ifTrue:[
+ self halt:('no application to ask %1 (enabled)' bindWith:enabledInItem)
+ ].
+ ].
enabled := anApplicationOrNil isNil or:[ (anApplicationOrNil perform:enabledInItem) ].
] ifFalse:[
enabled := enabledInItem
@@ -891,6 +907,7 @@
^ PopUpMenu forMenu:menuView
"Modified: / 30-06-2011 / 10:35:57 / cg"
+ "Modified: / 24-05-2018 / 15:26:17 / Claus Gittinger"
!
fromLiteralArrayEncoding:aLiteralEncodedArray
@@ -1043,7 +1060,7 @@
!Menu methodsFor:'enumerating'!
allItemsDetect:aOneArgBlock ifNone:exceptionalValue
- "find an element amongst each item and submenu items"
+ "recursively find an element amongst each item and submenu items"
self itemsDo:[:anItem|
|sub subItem|
@@ -1055,11 +1072,13 @@
]
].
^ exceptionalValue value
+
+ "Modified (comment): / 24-05-2018 / 16:10:36 / Claus Gittinger"
!
allItemsDo:aOneArgBlock
- "evaluate block on each item and submenu items
- "
+ "recursively evaluate block on each item and submenu items"
+
self itemsDo:[:anItem|
|sub|
@@ -1069,7 +1088,8 @@
]
]
- "Modified: / 19.6.1998 / 00:34:53 / cg"
+ "Modified: / 19-06-1998 / 00:34:53 / cg"
+ "Modified (comment): / 24-05-2018 / 16:10:41 / Claus Gittinger"
!
detectItem:aBlock
@@ -1077,37 +1097,49 @@
block returns true; in this case return the item which caused the
true evaluation.
If none of the evaluations returns true, return the result of the
- evaluation of the exceptionBlock
- "
+ evaluation of the exceptionBlock"
+
^ self detectItem:aBlock ifNone:[self errorNotFound]
+ "Modified (comment): / 24-05-2018 / 16:10:46 / Claus Gittinger"
!
detectItem:aBlock ifNone:exceptionValue
"evaluate the argument, aBlock for each item in the menu until the
block returns true; in this case return the item which caused the
true evaluation.
- If none of the evaluations returns true, return the value from exceptionValue
- "
+ If none of the evaluations returns true, return the value from exceptionValue"
+
items notNil ifTrue:[
^ items detect:aBlock ifNone:exceptionValue
].
^ exceptionValue value
"Modified (comment): / 14-03-2017 / 16:09:51 / cg"
+ "Modified (comment): / 24-05-2018 / 16:10:51 / Claus Gittinger"
+!
+
+do:aOneArgBlock
+ "recursively evaluate block on each item and submenu items"
+
+ self allItemsDo:aOneArgBlock
+
+ "Created: / 24-05-2018 / 16:10:25 / Claus Gittinger"
!
itemsDo:aOneArgBlock
- "evaluate the block for each item in the current menu
- "
+ "evaluate the block for each item in the current menu"
+
items notNil ifTrue:[items do:aOneArgBlock]
+
+ "Modified (comment): / 24-05-2018 / 16:10:55 / Claus Gittinger"
!
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
- "
+ the item will be returned"
+
|item|
items notNil ifTrue:[
@@ -1127,7 +1159,8 @@
].
^ nil
- "Modified: / 19.6.1998 / 00:35:00 / cg"
+ "Modified: / 19-06-1998 / 00:35:00 / cg"
+ "Modified (comment): / 24-05-2018 / 16:10:59 / Claus Gittinger"
! !
!Menu methodsFor:'kludged fixes'!