1154 findComponent:componentNameOrPath in:anApplicationOrViewOrMenuItem |
1154 findComponent:componentNameOrPath in:anApplicationOrViewOrMenuItem |
1155 "find a component by name inside an app or inside a view. |
1155 "find a component by name inside an app or inside a view. |
1156 Uses the NameKey of the spec, and optionally the label or modelKey. |
1156 Uses the NameKey of the spec, and optionally the label or modelKey. |
1157 Can return either a view or a menu item" |
1157 Can return either a view or a menu item" |
1158 |
1158 |
1159 |idx app window component componentNameSymbol |
1159 |idxString idx app window component componentNameSymbol |
1160 foundByName foundByHelpKey foundByTitle foundByLabel item |
1160 foundByName foundByHelpKey foundByTitle foundByLabel item |
1161 checkIfAllMenuItemsDoTheSame| |
1161 checkIfAllMenuItemsDoTheSame| |
1162 |
1162 |
1163 (componentNameOrPath includes:$/) ifTrue:[ |
1163 (componentNameOrPath includes:$/) ifTrue:[ |
1164 (idx := componentNameOrPath indexOf:$/) ~~ 0 ifTrue:[ |
1164 (idx := componentNameOrPath indexOf:$/) ~~ 0 ifTrue:[ |
1169 container := self findComponent:containerName in:anApplicationOrViewOrMenuItem. |
1169 container := self findComponent:containerName in:anApplicationOrViewOrMenuItem. |
1170 container isNil ifTrue:[ ^ nil ]. |
1170 container isNil ifTrue:[ ^ nil ]. |
1171 ^ self findComponent:restPath in:container |
1171 ^ self findComponent:restPath in:container |
1172 ] |
1172 ] |
1173 ]. |
1173 ]. |
1174 (componentNameOrPath matchesRegex:'item\[[0-9]+\]') ifTrue:[ |
1174 (componentNameOrPath startsWith:'item[') ifTrue:[ |
1175 anApplicationOrViewOrMenuItem isMenu ifFalse:[ |
1175 anApplicationOrViewOrMenuItem isMenu ifFalse:[ |
1176 self assert:false message:'container is not a menu'. |
1176 self assert:false message:'container is not a menu'. |
1177 ]. |
1177 ]. |
1178 idx := Integer readFrom:(componentNameOrPath withoutPrefix:'item[') readStream. |
1178 idxString := (componentNameOrPath withoutPrefix:'item[') withoutSuffix:']'. |
1179 item := anApplicationOrViewOrMenuItem itemAt:idx. |
1179 (idxString conform:#isDigit) ifTrue:[ |
|
1180 idx := Integer readFrom:idxString. |
|
1181 item := anApplicationOrViewOrMenuItem itemAtIndex:idx. |
|
1182 ] ifFalse:[ |
|
1183 item := anApplicationOrViewOrMenuItem itemAt:idxString. |
|
1184 ]. |
|
1185 self assert:item notNil. |
1180 ^ ItemInView new view:anApplicationOrViewOrMenuItem item:item boundsInView:(item layout) |
1186 ^ ItemInView new view:anApplicationOrViewOrMenuItem item:item boundsInView:(item layout) |
1181 ]. |
1187 ]. |
1182 (componentNameOrPath matchesRegex:'tab\[[0-9]+\]') ifTrue:[ |
1188 (componentNameOrPath startsWith:'tab[') ifTrue:[ |
1183 (anApplicationOrViewOrMenuItem isKindOf:NoteBookView) ifFalse:[ |
1189 (anApplicationOrViewOrMenuItem isKindOf:NoteBookView) ifFalse:[ |
1184 self assert:false message:'container is not a notebook'. |
1190 self assert:false message:'container is not a notebook'. |
1185 ]. |
1191 ]. |
1186 idx := Integer readFrom:(componentNameOrPath withoutPrefix:'tab[') readStream. |
1192 idxString := (componentNameOrPath withoutPrefix:'tab[') withoutSuffix:']'. |
1187 item := anApplicationOrViewOrMenuItem tabAtIndex:idx. |
1193 (idxString conform:#isDigit) ifTrue:[ |
|
1194 idx := Integer readFrom:idxString. |
|
1195 item := anApplicationOrViewOrMenuItem tabAtIndex:idx. |
|
1196 ] ifFalse:[ |
|
1197 item := anApplicationOrViewOrMenuItem tabForWhich:[:tab | tab tabItem rawLabel = idxString]. |
|
1198 item isNil ifTrue:[ |
|
1199 item := anApplicationOrViewOrMenuItem tabForWhich:[:tab | tab printableLabel = idxString]. |
|
1200 item isNil ifTrue:[ |
|
1201 item := anApplicationOrViewOrMenuItem tabForWhich:[:tab | tab activeHelpKey = idxString]. |
|
1202 ]. |
|
1203 ]. |
|
1204 ]. |
|
1205 self assert:item notNil. |
1188 ^ ItemInView new view:anApplicationOrViewOrMenuItem item:item boundsInView:(item layout) |
1206 ^ ItemInView new view:anApplicationOrViewOrMenuItem item:item boundsInView:(item layout) |
1189 ]. |
1207 ]. |
1190 |
1208 |
1191 componentNameSymbol := componentNameOrPath asSymbolIfInterned ? componentNameOrPath. |
1209 componentNameSymbol := componentNameOrPath asSymbolIfInterned ? componentNameOrPath. |
1192 |
1210 |
1454 |viewToClick clickPos| |
1472 |viewToClick clickPos| |
1455 |
1473 |
1456 self assert:viewOrMenuItem notNil. |
1474 self assert:viewOrMenuItem notNil. |
1457 verifying ifTrue:[^ self]. |
1475 verifying ifTrue:[^ self]. |
1458 |
1476 |
1459 (viewOrMenuItem askFor:#isMenuItem) ifTrue:[ |
1477 ((viewOrMenuItem askFor:#isMenuItem) |
1460 viewToClick := viewOrMenuItem menuPanel. |
1478 or:[ (viewOrMenuItem askFor:#isNoteBookTab) ]) ifTrue:[ |
|
1479 viewToClick := viewOrMenuItem view. |
1461 clickPos := viewOrMenuItem layout center. |
1480 clickPos := viewOrMenuItem layout center. |
1462 self assert:(clickPos notNil). |
1481 self assert:(clickPos notNil). |
1463 ] ifFalse:[ |
1482 ] ifFalse:[ |
1464 viewToClick := viewOrMenuItem. |
1483 viewToClick := viewOrMenuItem. |
1465 clickPos := viewToClick extent // 2. |
1484 clickPos := viewToClick extent // 2. |