#REFACTORING by cg
authorClaus Gittinger <cg@exept.de>
Tue, 23 Jul 2019 10:14:34 +0200
changeset 3727 6faffd2a64a3
parent 3726 036d0b8499cb
child 3728 e7faeed17679
#REFACTORING by cg class: ShowMeHowItWorks added: #circlePointerAroundScreenPosition: #fastMovePointerToScreenPosition: #movePointerToScreenPosition: #movePointerToScreenPosition:speed: removed: #circlePointerAroundPosition: #movePointerToPosition: #movePointerToPosition:speed: comment/format in: #componentNamed: #doCommand: #fastMoveTo: #findComponent: #movePointerToComponent:speed: #talking changed: #circlePointerAroundComponent: #findComponent:in: #movePointerToComponent: (send #movePointerToScreenPosition: instead of #movePointerToPosition:) #movePointerToComponent:offset: (send #movePointerToScreenPosition: instead of #movePointerToPosition:) #press: (send #movePointerToScreenPosition: instead of #movePointerToPosition:) #release: (send #movePointerToScreenPosition: instead of #movePointerToPosition:) category of: #componentNamed: #findComponent: #findComponent:in: class: ShowMeHowItWorks class removed: #doStream: comment/format in: #do:
ShowMeHowItWorks.st
--- a/ShowMeHowItWorks.st	Mon Jul 22 17:37:58 2019 +0200
+++ b/ShowMeHowItWorks.st	Tue Jul 23 10:14:34 2019 +0200
@@ -54,29 +54,34 @@
 !ShowMeHowItWorks class methodsFor:'running'!
 
 do:specArray
-    self doStream:specArray readStream
-
-    "Created: / 19-07-2019 / 10:52:59 / Claus Gittinger"
-    "Modified: / 19-07-2019 / 14:30:43 / Claus Gittinger"
-!
-
-doStream:specStream
     "must run as a separate process;
      otherwise - if started by the app itself -
      no events will be processed while running"
 
     |appWhichStartedMe|
-    
+
     appWhichStartedMe := WindowGroup activeMainApplication.
-    
+
     [
-        self new 
-            application:appWhichStartedMe;
-            doStream:specStream
+        Error handle:[:ex |
+            Dialog warn:(self classResources stringWithCRs:'An error was encountered in the show:\\%1' with:ex description)
+        ] do:[
+            self new 
+                application:appWhichStartedMe;
+                doStream:(specArray readStream)
+        ].
     ] fork.
 
-    "Created: / 19-07-2019 / 10:53:07 / Claus Gittinger"
-    "Modified: / 19-07-2019 / 16:44:02 / Claus Gittinger"
+    "
+     ShowMeHowItWorks do:
+        #(
+            (show: 'bla bla')
+            (moveTo: NameOfComponent)
+        )    
+    "
+
+    "Created: / 19-07-2019 / 10:52:59 / Claus Gittinger"
+    "Modified: / 23-07-2019 / 09:19:40 / Claus Gittinger"
 ! !
 
 !ShowMeHowItWorks methodsFor:'accessing'!
@@ -257,8 +262,14 @@
     component := self componentNamed:componentName.
     self movePointerToComponent:component speed:(self pointerMoveSpeedFast).
 
+    "
+     ShowMeHowItWorks basicNew fastMoveTo:'Classes'
+     ShowMeHowItWorks basicNew fastMoveTo:'Klassen'
+    "
+
     "Created: / 19-07-2019 / 15:39:23 / Claus Gittinger"
     "Modified: / 20-07-2019 / 08:14:16 / Claus Gittinger"
+    "Modified (comment): / 23-07-2019 / 09:33:31 / Claus Gittinger"
 !
 
 moveTo:componentName
@@ -478,111 +489,15 @@
 !
 
 talking
+    "/ ^ Expecco::ExpeccoPreferences current speechEffectsEnabled
     ^ true
 
     "Created: / 19-07-2019 / 14:31:14 / Claus Gittinger"
+    "Modified (comment): / 23-07-2019 / 09:45:35 / Claus Gittinger"
 ! !
 
 !ShowMeHowItWorks methodsFor:'helper'!
 
-componentNamed:componentName
-    "retrieve a component by name or report an error if not found"
-
-    |component|
-
-    lastComponentName := componentName.
-
-    component := self findComponent:componentName.
-    component isNil ifTrue:[
-        self error:'no component found for: ',componentName.
-    ].
-    lastComponent := component.
-    ^ component
-
-    "Created: / 19-07-2019 / 15:37:35 / Claus Gittinger"
-!
-
-findComponent:componentName
-    "find a component by name - in the active and possibly in any app"
-    
-    |component candidates|
-
-    application notNil ifTrue:[ 
-        component := self findComponent:componentName in:application.
-    ].
-    
-    component isNil ifTrue:[
-        "/ search through all current applications
-        candidates := OrderedCollection new.
-        WindowGroup scheduledWindowGroups do:[:eachWG |
-            |eachApp|
-
-            (eachApp := eachWG application) notNil ifTrue:[
-                component := self findComponent:componentName in:eachApp.
-                component notNil ifTrue:[ 
-                    candidates add:component
-                ].
-            ].
-        ].
-        
-        candidates size == 1 ifTrue:[
-            component := candidates first
-        ] ifFalse:[    
-            candidates notEmpty ifTrue:[
-                self error:'multiple components found by name: ',componentName.
-            ]    
-        ].    
-    ].    
-    ^ component
-
-    "Created: / 19-07-2019 / 12:02:30 / Claus Gittinger"
-    "Modified: / 19-07-2019 / 16:44:30 / Claus Gittinger"
-!
-
-findComponent:componentName in:anApplication
-    |component componentNameSymbol foundByName foundByTitle foundByLabel|
-
-    (component := anApplication componentAt:componentName) notNil ifTrue:[^ component].
-    (componentNameSymbol := componentName asSymbolIfInterned) notNil ifTrue:[
-        (component := anApplication componentAt:componentNameSymbol) notNil ifTrue:[^ component].
-    ].
-    
-    "/ mhmh - search through all widgets of anApplication; 
-    "/ maybe it was not created via the builder/spec,
-    "/ or it has changed its name.
-    "/ look for: widget's name, widget's title, widget's label
-    foundByName := OrderedCollection new. 
-    foundByTitle := OrderedCollection new. 
-    foundByLabel := OrderedCollection new.
-    
-    anApplication window allSubViewsDo:[:each |
-        [
-            each name = componentName ifTrue:[ foundByName add:each ].
-        ] on:MessageNotUnderstood do:[:ex | ].
-        [
-            each title = componentName ifTrue:[ foundByTitle add:each ].
-        ] on:MessageNotUnderstood do:[:ex | ].
-        [
-            each label = componentName ifTrue:[ foundByLabel add:each ].
-        ] on:MessageNotUnderstood do:[:ex | ].
-    ].
-    foundByName notEmpty ifTrue:[
-        self assert:(foundByName size == 1) message:'multiple components found by name'.
-        ^ foundByName first.
-    ].
-    foundByTitle notEmpty ifTrue:[
-        self assert:(foundByTitle size == 1) message:'multiple components found by title'.
-        ^ foundByTitle first.
-    ].
-    foundByLabel notEmpty ifTrue:[
-        self assert:(foundByLabel size == 1) message:'multiple components found by label'.
-        ^ foundByLabel first.
-    ].
-    ^ component
-
-    "Created: / 19-07-2019 / 11:36:21 / Claus Gittinger"
-!
-
 randomThankYou
     ^ #(
         'thank you, for watching'
@@ -637,17 +552,175 @@
     "Created: / 19-07-2019 / 13:14:51 / Claus Gittinger"
 ! !
 
+!ShowMeHowItWorks methodsFor:'helpers - component search'!
+
+componentNamed:componentName
+    "retrieve a component by name or report an error if not found.
+     Can return either a view or a menu item"
+
+    |component|
+
+    lastComponentName := componentName.
+
+    component := self findComponent:componentName.
+    component isNil ifTrue:[
+        self error:'no component found for: ',componentName.
+    ].
+    lastComponent := component.
+    ^ component
+
+    "Created: / 19-07-2019 / 15:37:35 / Claus Gittinger"
+    "Modified (comment): / 23-07-2019 / 09:31:53 / Claus Gittinger"
+!
+
+findComponent:componentName
+    "find a component by name - in the active and possibly in any app.
+     Can return either a view or a menu item"
+    
+    |component candidates|
+
+    application notNil ifTrue:[ 
+        component := self findComponent:componentName in:application.
+    ].
+    
+    component isNil ifTrue:[
+        "/ search through all current applications
+        candidates := OrderedCollection new.
+        WindowGroup scheduledWindowGroups do:[:eachWG |
+            |eachApp|
+
+            (eachApp := eachWG application) notNil ifTrue:[
+                component := self findComponent:componentName in:eachApp.
+                component notNil ifTrue:[ 
+                    candidates add:component
+                ].
+            ].
+        ].
+        
+        candidates size == 1 ifTrue:[
+            component := candidates first
+        ] ifFalse:[    
+            candidates notEmpty ifTrue:[
+                self error:'multiple components found by name: ',componentName.
+            ]    
+        ].    
+    ].    
+    ^ component
+
+    "
+     ShowMeHowItWorks basicNew findComponent:'Classes'
+     ShowMeHowItWorks basicNew findComponent:'Klassen'
+    "
+
+    "Created: / 19-07-2019 / 12:02:30 / Claus Gittinger"
+    "Modified: / 19-07-2019 / 16:44:30 / Claus Gittinger"
+    "Modified (comment): / 23-07-2019 / 09:32:44 / Claus Gittinger"
+!
+
+findComponent:componentName in:anApplicationOrView
+    "find a component by name inside an app.
+     Uses the NameKey of the spec, and optionally the label or modelKey.
+     Can return either a view or a menu item"
+
+    |app window component componentNameSymbol foundByName foundByTitle foundByLabel item|
+
+    (app := anApplicationOrView) isView ifTrue:[
+        window := anApplicationOrView.
+        app := anApplicationOrView application
+    ].
+    app notNil ifTrue:[
+        (component := app componentAt:componentName) notNil ifTrue:[^ component].
+        (componentNameSymbol := componentName asSymbolIfInterned) notNil ifTrue:[
+            (component := app componentAt:componentNameSymbol) notNil ifTrue:[^ component].
+        ].
+        window := app window.
+    ].    
+    
+    "/ mhmh - search through all widgets of anApplication; 
+    "/ maybe it was not created via the builder/spec,
+    "/ or it has changed its name.
+    "/ look for: widget's name, widget's title, widget's label
+    foundByName := OrderedCollection new. 
+    foundByTitle := OrderedCollection new. 
+    foundByLabel := OrderedCollection new.
+    
+    window allSubViewsDo:[:each |
+        |foundIt|
+        
+        foundIt := false.
+        [
+            each name = componentName ifTrue:[ foundByName add:each. foundIt := true ].
+        ] on:MessageNotUnderstood do:[:ex | ].
+        foundIt ifFalse:[
+            [
+                each title = componentName ifTrue:[ foundByTitle add:each. foundIt := true ].
+            ] on:MessageNotUnderstood do:[:ex | ].
+            foundIt ifFalse:[
+                [
+                    each label = componentName ifTrue:[ foundByLabel add:each. foundIt := true ].
+                ] on:MessageNotUnderstood do:[:ex | ].
+                foundIt ifFalse:[
+                    each isMenu ifTrue:[
+                        (item := each detectItemForNameKey:componentName) notNil ifTrue:[
+                            foundByName add:item. foundIt := true
+                        ].
+                        foundIt ifFalse:[
+                            (item := each detectItemForKey:componentName) notNil ifTrue:[
+                                foundByName add:item. foundIt := true 
+                            ].    
+                            foundIt ifFalse:[
+                                (item := each detectItemForLabel:componentName) notNil ifTrue:[
+                                    foundByLabel add:item. foundIt := true 
+                                ].    
+                            ].
+                        ].
+                    ].    
+                ].
+            ]    
+        ].
+    ].
+    
+    foundByName notEmpty ifTrue:[
+        self assert:(foundByName size == 1) message:'multiple components found by name'.
+        ^ foundByName first.
+    ].
+    foundByTitle notEmpty ifTrue:[
+        self assert:(foundByTitle size == 1) message:'multiple components found by title'.
+        ^ foundByTitle first.
+    ].
+    foundByLabel notEmpty ifTrue:[
+        self assert:(foundByLabel size == 1) message:'multiple components found by label'.
+        ^ foundByLabel first.
+    ].
+    ^ component
+
+    "
+     self basicNew findComponent:'Klassen' in:(Transcript topView)
+    "
+
+    "Created: / 19-07-2019 / 11:36:21 / Claus Gittinger"
+    "Modified (comment): / 23-07-2019 / 09:31:34 / Claus Gittinger"
+! !
+
 !ShowMeHowItWorks methodsFor:'helpers - mouse movement'!
 
-circlePointerAroundComponent:component
+circlePointerAroundComponent:aWidgetOrMenuItem
     "circle around it a few times"
+
+    |position|
     
-    self circlePointerAroundPosition:(component screenBounds center rounded)
+    aWidgetOrMenuItem isView ifTrue:[
+        position := aWidgetOrMenuItem screenBounds center rounded
+    ] ifFalse:[
+        self halt.
+    ].    
+    self circlePointerAroundScreenPosition:position
 
     "Created: / 19-07-2019 / 13:12:35 / Claus Gittinger"
+    "Modified: / 23-07-2019 / 09:38:12 / Claus Gittinger"
 !
 
-circlePointerAroundPosition:position
+circlePointerAroundScreenPosition:position
     "circle around it a few times"
     
     |screen stepDelayTime numCircles circlingSpeed radius|
@@ -684,44 +757,59 @@
         Delay waitFor:stepDelayTime.
     ].
 
-    "Created: / 19-07-2019 / 13:12:40 / Claus Gittinger"
+    "Created: / 23-07-2019 / 09:37:46 / Claus Gittinger"
+!
+
+fastMovePointerToScreenPosition:position
+    self movePointerToScreenPosition:position speed:(self pointerMoveSpeedFast).
+
+    "Created: / 23-07-2019 / 09:36:20 / Claus Gittinger"
 !
 
 movePointerToComponent:aWidget
     "move the mouse to aWidget's center"
     
-    self movePointerToPosition:(aWidget screenBounds center rounded).
+    self movePointerToScreenPosition:(aWidget screenBounds center rounded).
 
     "Created: / 19-07-2019 / 13:11:33 / Claus Gittinger"
+    "Modified: / 23-07-2019 / 09:37:01 / Claus Gittinger"
 !
 
 movePointerToComponent:aWidget offset:offset
     "move the mouse to position inside aWidget's"
     
-    self movePointerToPosition:(aWidget screenBounds origin + offset) rounded.
+    self movePointerToScreenPosition:(aWidget screenBounds origin + offset) rounded.
 
     "Created: / 19-07-2019 / 16:18:58 / Claus Gittinger"
+    "Modified: / 23-07-2019 / 09:36:57 / Claus Gittinger"
 !
 
-movePointerToComponent:aWidget speed:pixelsPerSecond
+movePointerToComponent:aWidgetOrMenuItem speed:pixelsPerSecond
     "move the mouse to aWidget's center"
+
+    |position|
     
-    self movePointerToPosition:(aWidget screenBounds center rounded) speed:pixelsPerSecond.
+    aWidgetOrMenuItem isView ifTrue:[
+        position := aWidgetOrMenuItem screenBounds center rounded
+    ] ifFalse:[
+        self halt.
+    ].    
+    self movePointerToScreenPosition:position speed:pixelsPerSecond.
 
     "Created: / 20-07-2019 / 08:12:49 / Claus Gittinger"
+    "Modified: / 23-07-2019 / 09:37:27 / Claus Gittinger"
 !
 
-movePointerToPosition:newPosition
+movePointerToScreenPosition:newPosition
     "move the mouse to newPosition"
 
-    self movePointerToPosition:newPosition speed:self pointerMoveSpeed
+    self movePointerToScreenPosition:newPosition speed:(self pointerMoveSpeed)
 
-    "Created: / 19-07-2019 / 12:57:30 / Claus Gittinger"
-    "Modified: / 20-07-2019 / 08:12:34 / Claus Gittinger"
+    "Created: / 23-07-2019 / 09:36:39 / Claus Gittinger"
 !
 
-movePointerToPosition:newPosition speed:pixelsPerSecond
-    "move the mouse to newPosition"
+movePointerToScreenPosition:newPosition speed:pixelsPerSecond
+    "move the mouse to newPosition, which is a screen position"
     
     |screen distance start numSteps moveTime stepDelayTime delta|
 
@@ -749,7 +837,7 @@
         Delay waitFor:stepDelayTime.
     ].
 
-    "Created: / 20-07-2019 / 08:12:07 / Claus Gittinger"
+    "Created: / 23-07-2019 / 09:36:45 / Claus Gittinger"
 ! !
 
 !ShowMeHowItWorks methodsFor:'menu actions - mouse buttons'!
@@ -791,7 +879,7 @@
     x := position x.
     y := position y.
     
-    self movePointerToPosition:position.
+    self movePointerToScreenPosition:position.
 
     false "OperatingSystem isOSXlike" ifTrue:[
         |osxPos|
@@ -807,6 +895,7 @@
     screen flush.
 
     "Created: / 19-07-2019 / 13:52:38 / Claus Gittinger"
+    "Modified: / 23-07-2019 / 09:38:31 / Claus Gittinger"
 !
 
 release:buttonNr
@@ -819,7 +908,7 @@
     x := position x.
     y := position y.
     
-    self movePointerToPosition:position.
+    self movePointerToScreenPosition:position.
 
     false "OperatingSystem isOSXlike" ifTrue:[
         |osxPos|
@@ -835,11 +924,14 @@
     screen flush.
 
     "Created: / 19-07-2019 / 13:53:05 / Claus Gittinger"
+    "Modified: / 23-07-2019 / 09:38:38 / Claus Gittinger"
 ! !
 
 !ShowMeHowItWorks methodsFor:'running'!
 
 doCommand:op
+    "execute a single command"
+    
     |numArgs sel args method|
 
     op isArray ifTrue:[
@@ -896,6 +988,7 @@
 END"
 
     "Created: / 19-07-2019 / 15:34:55 / Claus Gittinger"
+    "Modified: / 23-07-2019 / 09:14:26 / Claus Gittinger"
 !
 
 doStream:specStream