1012 findComponent:componentNameOrPath in:anApplicationOrViewOrMenuItem |
1012 findComponent:componentNameOrPath in:anApplicationOrViewOrMenuItem |
1013 "find a component by name inside an app or inside a view. |
1013 "find a component by name inside an app or inside a view. |
1014 Uses the NameKey of the spec, and optionally the label or modelKey. |
1014 Uses the NameKey of the spec, and optionally the label or modelKey. |
1015 Can return either a view or a menu item" |
1015 Can return either a view or a menu item" |
1016 |
1016 |
1017 |idx app window component componentNameSymbol foundByName foundByTitle foundByLabel item |
1017 |idx app window component componentNameSymbol |
|
1018 foundByName foundByHelpKey foundByTitle foundByLabel item |
1018 checkIfAllMenuItemsDoTheSame| |
1019 checkIfAllMenuItemsDoTheSame| |
1019 |
1020 |
1020 (componentNameOrPath includes:$/) ifTrue:[ |
1021 (componentNameOrPath includes:$/) ifTrue:[ |
1021 (idx := componentNameOrPath indexOf:$/) ~~ 0 ifTrue:[ |
1022 (idx := componentNameOrPath indexOf:$/) ~~ 0 ifTrue:[ |
1022 |containerName restPath container| |
1023 |containerName restPath container| |
1050 "/ mhmh - search through all widgets of anApplication; |
1051 "/ mhmh - search through all widgets of anApplication; |
1051 "/ maybe it was not created via the builder/spec, |
1052 "/ maybe it was not created via the builder/spec, |
1052 "/ or it has changed its name. |
1053 "/ or it has changed its name. |
1053 "/ look for: widget's name, widget's title, widget's label |
1054 "/ look for: widget's name, widget's title, widget's label |
1054 foundByName := OrderedCollection new. |
1055 foundByName := OrderedCollection new. |
|
1056 foundByHelpKey := OrderedCollection new. |
1055 foundByTitle := OrderedCollection new. |
1057 foundByTitle := OrderedCollection new. |
1056 foundByLabel := OrderedCollection new. |
1058 foundByLabel := OrderedCollection new. |
1057 |
1059 |
1058 window withAllSubViewsDo:[:each | |
1060 window withAllSubViewsDo:[:each | |
1059 |foundIt| |
1061 |foundIt| |
1060 |
1062 |
1061 foundIt := false. |
1063 foundIt := false. |
1062 each shown ifTrue:[ |
1064 each shown ifTrue:[ |
1063 [ |
1065 { |
1064 each name = componentNameSymbol ifTrue:[ foundByName add:each. foundIt := true ]. |
1066 #name . foundByName . |
1065 ] on:MessageNotUnderstood do:[:ex | ]. |
1067 #helpKey . foundByHelpKey . |
1066 foundIt ifFalse:[ |
1068 #title . foundByTitle . |
1067 [ |
1069 #label . foundByLabel . |
1068 each title = componentNameSymbol ifTrue:[ foundByTitle add:each. foundIt := true ]. |
1070 } pairWiseDo:[:attr :coll | |
1069 ] on:MessageNotUnderstood do:[:ex | ]. |
|
1070 foundIt ifFalse:[ |
1071 foundIt ifFalse:[ |
1071 [ |
1072 [ |
1072 each label = componentNameSymbol ifTrue:[ foundByLabel add:each. foundIt := true ]. |
1073 (each perform:attr) = componentNameSymbol ifTrue:[ |
|
1074 coll add:each. foundIt := true |
|
1075 ] |
1073 ] on:MessageNotUnderstood do:[:ex | ]. |
1076 ] on:MessageNotUnderstood do:[:ex | ]. |
|
1077 ] |
|
1078 ]. |
|
1079 foundIt ifFalse:[ |
|
1080 each isMenu ifTrue:[ |
|
1081 (item := each detectItemForNameKey:componentNameSymbol) notNil ifTrue:[ |
|
1082 foundByName add:item. foundIt := true |
|
1083 ]. |
1074 foundIt ifFalse:[ |
1084 foundIt ifFalse:[ |
1075 each isMenu ifTrue:[ |
1085 (item := each detectItemForKey:componentNameSymbol) notNil ifTrue:[ |
1076 (item := each detectItemForNameKey:componentNameSymbol) notNil ifTrue:[ |
1086 foundByName add:item. foundIt := true |
1077 foundByName add:item. foundIt := true |
|
1078 ]. |
|
1079 foundIt ifFalse:[ |
|
1080 (item := each detectItemForKey:componentNameSymbol) notNil ifTrue:[ |
|
1081 foundByName add:item. foundIt := true |
|
1082 ]. |
|
1083 foundIt ifFalse:[ |
|
1084 (item := each detectItemForLabel:componentNameSymbol) notNil ifTrue:[ |
|
1085 foundByLabel add:item. foundIt := true |
|
1086 ]. |
|
1087 ]. |
|
1088 ]. |
|
1089 ]. |
1087 ]. |
|
1088 foundIt ifFalse:[ |
|
1089 (item := each detectItemForLabel:componentNameSymbol) notNil ifTrue:[ |
|
1090 foundByLabel add:item. foundIt := true |
|
1091 ]. |
|
1092 ]. |
1090 ]. |
1093 ]. |
1091 ] |
1094 ]. |
1092 ]. |
1095 ]. |
1093 ]. |
1096 ]. |
1094 ]. |
1097 ]. |
1095 |
1098 |
1096 "/ a check, if multiple menu items have the same action, then choose the first found |
1099 "/ a check, if multiple menu items have the same action, then choose the first found |
1112 |
1115 |
1113 foundByName notEmpty ifTrue:[ |
1116 foundByName notEmpty ifTrue:[ |
1114 checkIfAllMenuItemsDoTheSame value:foundByName. |
1117 checkIfAllMenuItemsDoTheSame value:foundByName. |
1115 self assert:(foundByName size == 1) message:'multiple components found by name'. |
1118 self assert:(foundByName size == 1) message:'multiple components found by name'. |
1116 ^ foundByName first. |
1119 ^ foundByName first. |
|
1120 ]. |
|
1121 foundByHelpKey notEmpty ifTrue:[ |
|
1122 checkIfAllMenuItemsDoTheSame value:foundByHelpKey. |
|
1123 self assert:(foundByHelpKey size == 1) message:'multiple components found by helpKey'. |
|
1124 ^ foundByHelpKey first. |
1117 ]. |
1125 ]. |
1118 foundByTitle notEmpty ifTrue:[ |
1126 foundByTitle notEmpty ifTrue:[ |
1119 checkIfAllMenuItemsDoTheSame value:foundByTitle. |
1127 checkIfAllMenuItemsDoTheSame value:foundByTitle. |
1120 self assert:(foundByTitle size == 1) message:'multiple components found by title'. |
1128 self assert:(foundByTitle size == 1) message:'multiple components found by title'. |
1121 ^ foundByTitle first. |
1129 ^ foundByTitle first. |