47 |
47 |
48 ! |
48 ! |
49 |
49 |
50 documentation |
50 documentation |
51 " |
51 " |
52 not yet finished Menu class - this will eventually replace |
52 Menu (aka MenuSpec, that's what it is!!). |
53 most of the MenuView and PopUpMenu stuff. |
53 |
54 (and hopefully be ST-80 compatible ...) |
54 similar to UISpecifications, this describes the look, feel and behavior of |
55 |
55 popUpMenus, toolbarMenus and window menus. |
56 For now, only a subset of the full protocol is implemented. |
56 |
57 |
57 Instances of me are usually created from menuSpec methods, which return a literal |
|
58 array description of me. |
|
59 Instances of me are processed by MenuBuilders, which create a real MenuView/MenuPanel |
|
60 from that into a window. |
|
61 |
|
62 Should be relatively VisualWorks compatible (clean room development, by emulating the |
|
63 protocol needed by some public domain VW applications) |
|
64 |
58 [author:] |
65 [author:] |
59 Claus Gittinger |
66 Claus Gittinger |
60 |
67 |
61 [see also:] |
68 [see also:] |
62 MenuItem |
69 MenuItem |
63 PopUpMenu |
70 PopUpMenu |
64 " |
71 " |
65 ! ! |
72 ! ! |
66 |
73 |
67 !Menu class methodsFor:'instance creation'! |
74 !Menu class methodsFor:'instance creation'! |
68 |
75 |
284 items:aCollectionOfMenuItems |
292 items:aCollectionOfMenuItems |
285 items := aCollectionOfMenuItems |
293 items := aCollectionOfMenuItems |
286 ! |
294 ! |
287 |
295 |
288 labelAt:anIndex |
296 labelAt:anIndex |
289 "gets the label of the menu item at the given index or nil |
297 "gets the label of the menu item at the given index or nil" |
290 " |
298 |
291 |item| |
299 |item| |
292 |
300 |
293 (item := self menuItemAt:anIndex) notNil ifTrue:[ |
301 (item := self menuItemAt:anIndex) notNil ifTrue:[ |
294 ^ item label |
302 ^ item label |
295 ]. |
303 ]. |
296 ^ nil |
304 ^ nil |
297 |
305 |
298 "Modified: / 2.2.1998 / 13:28:32 / cg" |
306 "Modified: / 02-02-1998 / 13:28:32 / cg" |
|
307 "Modified (comment): / 24-05-2018 / 16:11:26 / Claus Gittinger" |
299 ! |
308 ! |
300 |
309 |
301 labelAtValue:aValue |
310 labelAtValue:aValue |
302 "gets the label of the menu item assigned to value |
311 "gets the label of the menu item assigned to value" |
303 " |
312 |
304 |item| |
313 |item| |
305 |
314 |
306 item := self menuAndSubmenusDetectItem:[:anItem | anItem value == aValue ]. |
315 item := self menuAndSubmenusDetectItem:[:anItem | anItem value == aValue ]. |
307 |
316 |
308 item notNil ifTrue:[ |
317 item notNil ifTrue:[ |
309 ^ item label |
318 ^ item label |
310 ]. |
319 ]. |
311 ^ nil |
320 ^ nil |
312 |
321 |
313 "Modified: / 2.2.1998 / 13:28:28 / cg" |
322 "Modified: / 02-02-1998 / 13:28:28 / cg" |
|
323 "Modified (comment): / 24-05-2018 / 16:11:30 / Claus Gittinger" |
314 ! |
324 ! |
315 |
325 |
316 labels |
326 labels |
317 "return a collection of labels from my items" |
327 "return a collection of labels from my items" |
318 |
328 |
861 |enabledInItem enabled| |
872 |enabledInItem enabled| |
862 |
873 |
863 enabledInItem := each enabled. |
874 enabledInItem := each enabled. |
864 enabledInItem notNil ifTrue:[ |
875 enabledInItem notNil ifTrue:[ |
865 enabledInItem isSymbol ifTrue:[ |
876 enabledInItem isSymbol ifTrue:[ |
|
877 anApplicationOrNil isNil ifTrue:[ |
|
878 Smalltalk isSmalltalkDevelopmentSystem ifTrue:[ |
|
879 self halt:('no application to ask %1 (enabled)' bindWith:enabledInItem) |
|
880 ]. |
|
881 ]. |
866 enabled := anApplicationOrNil isNil or:[ (anApplicationOrNil perform:enabledInItem) ]. |
882 enabled := anApplicationOrNil isNil or:[ (anApplicationOrNil perform:enabledInItem) ]. |
867 ] ifFalse:[ |
883 ] ifFalse:[ |
868 enabled := enabledInItem |
884 enabled := enabledInItem |
869 ]. |
885 ]. |
870 enabled value ifFalse:[ |
886 enabled value ifFalse:[ |
1053 subItem := sub allItemsDetect:aOneArgBlock ifNone:nil. |
1070 subItem := sub allItemsDetect:aOneArgBlock ifNone:nil. |
1054 subItem notNil ifTrue:[^ subItem]. |
1071 subItem notNil ifTrue:[^ subItem]. |
1055 ] |
1072 ] |
1056 ]. |
1073 ]. |
1057 ^ exceptionalValue value |
1074 ^ exceptionalValue value |
|
1075 |
|
1076 "Modified (comment): / 24-05-2018 / 16:10:36 / Claus Gittinger" |
1058 ! |
1077 ! |
1059 |
1078 |
1060 allItemsDo:aOneArgBlock |
1079 allItemsDo:aOneArgBlock |
1061 "evaluate block on each item and submenu items |
1080 "recursively evaluate block on each item and submenu items" |
1062 " |
1081 |
1063 self itemsDo:[:anItem| |
1082 self itemsDo:[:anItem| |
1064 |sub| |
1083 |sub| |
1065 |
1084 |
1066 aOneArgBlock value:anItem. |
1085 aOneArgBlock value:anItem. |
1067 (sub := anItem submenu) notNil ifTrue:[ |
1086 (sub := anItem submenu) notNil ifTrue:[ |
1068 sub allItemsDo:aOneArgBlock |
1087 sub allItemsDo:aOneArgBlock |
1069 ] |
1088 ] |
1070 ] |
1089 ] |
1071 |
1090 |
1072 "Modified: / 19.6.1998 / 00:34:53 / cg" |
1091 "Modified: / 19-06-1998 / 00:34:53 / cg" |
|
1092 "Modified (comment): / 24-05-2018 / 16:10:41 / Claus Gittinger" |
1073 ! |
1093 ! |
1074 |
1094 |
1075 detectItem:aBlock |
1095 detectItem:aBlock |
1076 "evaluate the argument, aBlock for each item in the menu until the |
1096 "evaluate the argument, aBlock for each item in the menu until the |
1077 block returns true; in this case return the item which caused the |
1097 block returns true; in this case return the item which caused the |
1078 true evaluation. |
1098 true evaluation. |
1079 If none of the evaluations returns true, return the result of the |
1099 If none of the evaluations returns true, return the result of the |
1080 evaluation of the exceptionBlock |
1100 evaluation of the exceptionBlock" |
1081 " |
1101 |
1082 ^ self detectItem:aBlock ifNone:[self errorNotFound] |
1102 ^ self detectItem:aBlock ifNone:[self errorNotFound] |
1083 |
1103 |
|
1104 "Modified (comment): / 24-05-2018 / 16:10:46 / Claus Gittinger" |
1084 ! |
1105 ! |
1085 |
1106 |
1086 detectItem:aBlock ifNone:exceptionValue |
1107 detectItem:aBlock ifNone:exceptionValue |
1087 "evaluate the argument, aBlock for each item in the menu until the |
1108 "evaluate the argument, aBlock for each item in the menu until the |
1088 block returns true; in this case return the item which caused the |
1109 block returns true; in this case return the item which caused the |
1089 true evaluation. |
1110 true evaluation. |
1090 If none of the evaluations returns true, return the value from exceptionValue |
1111 If none of the evaluations returns true, return the value from exceptionValue" |
1091 " |
1112 |
1092 items notNil ifTrue:[ |
1113 items notNil ifTrue:[ |
1093 ^ items detect:aBlock ifNone:exceptionValue |
1114 ^ items detect:aBlock ifNone:exceptionValue |
1094 ]. |
1115 ]. |
1095 ^ exceptionValue value |
1116 ^ exceptionValue value |
1096 |
1117 |
1097 "Modified (comment): / 14-03-2017 / 16:09:51 / cg" |
1118 "Modified (comment): / 14-03-2017 / 16:09:51 / cg" |
|
1119 "Modified (comment): / 24-05-2018 / 16:10:51 / Claus Gittinger" |
|
1120 ! |
|
1121 |
|
1122 do:aOneArgBlock |
|
1123 "recursively evaluate block on each item and submenu items" |
|
1124 |
|
1125 self allItemsDo:aOneArgBlock |
|
1126 |
|
1127 "Created: / 24-05-2018 / 16:10:25 / Claus Gittinger" |
1098 ! |
1128 ! |
1099 |
1129 |
1100 itemsDo:aOneArgBlock |
1130 itemsDo:aOneArgBlock |
1101 "evaluate the block for each item in the current menu |
1131 "evaluate the block for each item in the current menu" |
1102 " |
1132 |
1103 items notNil ifTrue:[items do:aOneArgBlock] |
1133 items notNil ifTrue:[items do:aOneArgBlock] |
|
1134 |
|
1135 "Modified (comment): / 24-05-2018 / 16:10:55 / Claus Gittinger" |
1104 ! |
1136 ! |
1105 |
1137 |
1106 menuAndSubmenusDetectItem:aOneArgBlock |
1138 menuAndSubmenusDetectItem:aOneArgBlock |
1107 "evaluate the block for each item in the current menu and all |
1139 "evaluate the block for each item in the current menu and all |
1108 submenus. In case that the block returns a non nil argument, |
1140 submenus. In case that the block returns a non nil argument, |
1109 the item will be returned |
1141 the item will be returned" |
1110 " |
1142 |
1111 |item| |
1143 |item| |
1112 |
1144 |
1113 items notNil ifTrue:[ |
1145 items notNil ifTrue:[ |
1114 items do:[:anItem| |
1146 items do:[:anItem| |
1115 |sub| |
1147 |sub| |