#FEATURE by exept
authorClaus Gittinger <cg@exept.de>
Thu, 31 Oct 2019 13:40:45 +0100
changeset 3803 34ea88ec4dc4
parent 3802 908abf2676e7
child 3804 2355596aec0a
#FEATURE by exept class: ShowMeHowItWorks class definition added: #findApplication:ifMultiple: #popApplication #pushApplication: #selectComponent: comment/format in: #application: changed: #select: #showing:saying:do:
ShowMeHowItWorks.st
--- a/ShowMeHowItWorks.st	Thu Oct 31 10:25:01 2019 +0100
+++ b/ShowMeHowItWorks.st	Thu Oct 31 13:40:45 2019 +0100
@@ -8,7 +8,7 @@
 	instanceVariableNames:'application opStream streamStack lastComponentName lastComponent
 		lastResult voice translate language verifying
 		closeApplicationWhenFinished defaultComponentWaitTime ui
-		theShowFile defaultElementTimeout'
+		theShowFile defaultElementTimeout applicationStack'
 	classVariableNames:'IntroShownCount DebugMode StartLabel'
 	poolDictionaries:''
 	category:'Interface-Help'
@@ -220,7 +220,7 @@
 !ShowMeHowItWorks methodsFor:'accessing'!
 
 application:anApplication
-    "if set, only that application is presented (widget search is limtied to that one)"
+    "if set, only that application is presented (widget search is limited to that one)"
 
     application := anApplication.
 !
@@ -315,6 +315,32 @@
     "Modified: / 19-07-2019 / 16:13:33 / Claus Gittinger"
 !
 
+popApplication
+    <action>
+
+    "go back to the previous app"
+
+    application := applicationStack removeLast.
+!
+
+pushApplication:newApplicationOrName
+    <action>
+
+    "goto another app, remembering where we were before"
+
+    |newApplication|
+
+    (newApplication := newApplicationOrName) isString ifTrue:[
+        newApplication := self findApplication:newApplicationOrName ifMultiple:nil.
+        self assert: newApplication notNil.
+    ].
+
+    applicationStack isNil ifTrue:[applicationStack := OrderedCollection new].
+
+    applicationStack add:application.
+    self application:newApplication.
+!
+
 raise:what
     <action>
 
@@ -417,8 +443,8 @@
     |xLatedMessage messageView talkDone|
 
     xLatedMessage := (translate and:[application notNil]) 
-                            ifTrue:[application resources string:message]
-                            ifFalse:[message].
+                            ifTrue:[application resources stringWithCRs:message]
+                            ifFalse:[message withCRs].
     
     self assert:(operationsOrNothing isNil or:[operationsOrNothing isSequenceable]).
 
@@ -872,13 +898,15 @@
 select:itemsIndexOrLabelOrPattern
     "select an item by label,
      allowed after moving to:
-        aComboBox
-        aSelectionInListView
+        a ComboBox
+        a SelectionInListView
+        a NoteBook
+        a DSVColumnView
     "    
 
     <action>
 
-    |idx component|
+    |idx component yPos tab|
 
     verifying ifTrue:[^ self].
 
@@ -911,8 +939,6 @@
         ^ self
     ].    
     (component isKindOf:HierarchicalListView) ifTrue:[
-        |idx yPos|
-
         itemsIndexOrLabelOrPattern isInteger ifTrue:[
             idx := itemsIndexOrLabelOrPattern
         ] ifFalse:[
@@ -934,8 +960,6 @@
         ^ self
     ].
     (component isKindOf:SelectionInListModelView) ifTrue:[
-        |idx yPos|
-
         itemsIndexOrLabelOrPattern isInteger ifTrue:[
             idx := itemsIndexOrLabelOrPattern
         ] ifFalse:[
@@ -960,16 +984,46 @@
     (component isKindOf:ItemInView) ifTrue:[
         component isMenuItem ifTrue:[
             self movePointerToComponent:component.
-            self halt.
+            self click.
+            ^ self
         ].
     ].
 
-    self error:('cannot select this component: %1' bindWith:component className)
+    (component isKindOf:NoteBookView) ifTrue:[
+        (idx := itemsIndexOrLabelOrPattern) isInteger ifFalse:[
+            idx := component indexOfTabNamed:itemsIndexOrLabelOrPattern
+        ].
+        tab := component tabAtIndex:idx.
+        self movePointerToComponent:component offset:(tab layout center).
+        component selection:idx.
+        ^ self
+    ].
+    (component isKindOf:DSVColumnView) ifTrue:[
+        (idx := itemsIndexOrLabelOrPattern) isInteger ifFalse:[
+            self halt.
+        ].
+        yPos := ((component yVisibleOfRowNr:idx) + (component yVisibleOfRowNr:idx+1)) // 2.
+        self movePointerToComponent:component offset:(1 @ yPos).
+        component selectRow:idx.
+        ^ self
+    ].
+
+    self error:('cannot select "%1" this component: %2' bindWith:itemsIndexOrLabelOrPattern with:component className)
 
     "Created: / 19-07-2019 / 12:34:25 / Claus Gittinger"
     "Modified (format): / 19-07-2019 / 14:55:34 / Claus Gittinger"
 !
 
+selectComponent:componentName
+    "Leaves component in lastComponent without moving"
+
+    <action>
+
+    |component|
+
+    component := self componentNamed:componentName.
+!
+
 selectIndex:itemsIndex
     "select an item by index,
      allowed after moving to:
@@ -1271,6 +1325,44 @@
     "Modified (comment): / 23-07-2019 / 09:31:53 / Claus Gittinger"
 !
 
+findApplication:classNameOrWindowTitle ifMultiple:exceptionalValue
+    "find an application by name"
+    
+    |candidates|
+
+    candidates := IdentitySet new.
+
+    "/ search through all current applications
+    WindowGroup scheduledWindowGroups do:[:eachWG |
+        |eachApp|
+
+        (eachApp := eachWG application) notNil ifTrue:[
+            ((classNameOrWindowTitle match:eachApp className) 
+            or:[(classNameOrWindowTitle match:eachApp class nameWithoutPrefix)
+            or:[(classNameOrWindowTitle match:eachApp mainWindow label)]]) ifTrue:[
+                candidates add:eachApp
+            ].
+        ].
+    ].
+    candidates size == 1 ifTrue:[
+        ^ candidates first
+    ].
+    candidates notEmpty ifTrue:[
+        "/ multiple elements (probably there are multiple topviews open...
+        "/ check the current windowGroup
+        ^ exceptionalValue value
+    ].
+    ^ nil
+
+    "
+     ShowMeHowItWorks basicNew findApplication:'Inspector*' ifMultiple:nil.
+    "
+
+    "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
     "find a component by name - in the active and possibly in any app.
      Can return either a view or a menu item"