#FEATURE by exept draft
authorClaus Gittinger <cg@exept.de>
Sun, 20 Oct 2019 08:13:53 +0200
changeset 3793 4759769ba7a3
parent 3792 7682b28c1e92
child 3794 49da17b54a22
#FEATURE by exept class: ShowMeHowItWorks changed: #findComponent:in:
ShowMeHowItWorks.st
--- a/ShowMeHowItWorks.st	Fri Oct 18 23:29:24 2019 +0200
+++ b/ShowMeHowItWorks.st	Sun Oct 20 08:13:53 2019 +0200
@@ -1014,7 +1014,8 @@
      Uses the NameKey of the spec, and optionally the label or modelKey.
      Can return either a view or a menu item"
 
-    |idx app window component componentNameSymbol foundByName foundByTitle foundByLabel item
+    |idx app window component componentNameSymbol 
+     foundByName foundByHelpKey foundByTitle foundByLabel item
      checkIfAllMenuItemsDoTheSame|
 
     (componentNameOrPath includes:$/) ifTrue:[
@@ -1052,6 +1053,7 @@
     "/ or it has changed its name.
     "/ look for: widget's name, widget's title, widget's label
     foundByName := OrderedCollection new. 
+    foundByHelpKey := OrderedCollection new. 
     foundByTitle := OrderedCollection new. 
     foundByLabel := OrderedCollection new.
 
@@ -1060,35 +1062,36 @@
         
         foundIt := false.
         each shown ifTrue:[
-            [
-                each name = componentNameSymbol ifTrue:[ foundByName add:each. foundIt := true ].
-            ] on:MessageNotUnderstood do:[:ex | ].
-            foundIt ifFalse:[
-                [
-                    each title = componentNameSymbol ifTrue:[ foundByTitle add:each. foundIt := true ].
-                ] on:MessageNotUnderstood do:[:ex | ].
+            {
+                #name . foundByName .
+                #helpKey . foundByHelpKey .
+                #title . foundByTitle .
+                #label . foundByLabel .
+            } pairWiseDo:[:attr :coll |
                 foundIt ifFalse:[
                     [
-                        each label = componentNameSymbol ifTrue:[ foundByLabel add:each. foundIt := true ].
+                        (each perform:attr) = componentNameSymbol ifTrue:[ 
+                            coll add:each. foundIt := true
+                        ]
                     ] on:MessageNotUnderstood do:[:ex | ].
+                ]
+            ].
+            foundIt ifFalse:[
+                each isMenu ifTrue:[
+                    (item := each detectItemForNameKey:componentNameSymbol) notNil ifTrue:[
+                        foundByName add:item. foundIt := true
+                    ].
                     foundIt ifFalse:[
-                        each isMenu ifTrue:[
-                            (item := each detectItemForNameKey:componentNameSymbol) notNil ifTrue:[
-                                foundByName add:item. foundIt := true
-                            ].
-                            foundIt ifFalse:[
-                                (item := each detectItemForKey:componentNameSymbol) notNil ifTrue:[
-                                    foundByName add:item. foundIt := true 
-                                ].    
-                                foundIt ifFalse:[
-                                    (item := each detectItemForLabel:componentNameSymbol) notNil ifTrue:[
-                                        foundByLabel add:item. foundIt := true 
-                                    ].    
-                                ].
-                            ].
+                        (item := each detectItemForKey:componentNameSymbol) notNil ifTrue:[
+                            foundByName add:item. foundIt := true 
                         ].    
+                        foundIt ifFalse:[
+                            (item := each detectItemForLabel:componentNameSymbol) notNil ifTrue:[
+                                foundByLabel add:item. foundIt := true 
+                            ].    
+                        ].
                     ].
-                ]    
+                ].    
             ].
         ].
     ].
@@ -1115,6 +1118,11 @@
         self assert:(foundByName size == 1) message:'multiple components found by name'.
         ^ foundByName first.
     ].
+    foundByHelpKey notEmpty ifTrue:[
+        checkIfAllMenuItemsDoTheSame value:foundByHelpKey.
+        self assert:(foundByHelpKey size == 1) message:'multiple components found by helpKey'.
+        ^ foundByHelpKey first.
+    ].
     foundByTitle notEmpty ifTrue:[
         checkIfAllMenuItemsDoTheSame value:foundByTitle.
         self assert:(foundByTitle size == 1) message:'multiple components found by title'.