ShowMeHowItWorks.st
changeset 3781 0040ac44a2f3
parent 3780 604d8ffc8903
child 3783 e935b92253c9
equal deleted inserted replaced
3780:604d8ffc8903 3781:0040ac44a2f3
   305 waitFor:componentName timeout:seconds
   305 waitFor:componentName timeout:seconds
   306     <action>
   306     <action>
   307 
   307 
   308     |endTime|
   308     |endTime|
   309 
   309 
   310     DebugMode == true ifTrue:[^ self].
   310     verifying ifTrue:[^ self].
       
   311 
   311     endTime := Timestamp now + seconds.
   312     endTime := Timestamp now + seconds.
   312     [
   313     [
   313         (self findComponent:componentName) notNil ifTrue:[
   314         (self findComponent:componentName) notNil ifTrue:[
   314             self halt.
       
   315             ^ self
   315             ^ self
   316         ].
   316         ].
   317         Delay waitForSeconds:0.05.
   317         Delay waitForSeconds:0.05.
   318         Timestamp now > endTime ifTrue:[
   318         Timestamp now > endTime ifTrue:[
   319             self error:('component %1 not present after %2' bindWith:componentName with:seconds)
   319             self error:('component %1 not present after %2' bindWith:componentName with:seconds)
   792     "Created: / 19-07-2019 / 12:02:30 / Claus Gittinger"
   792     "Created: / 19-07-2019 / 12:02:30 / Claus Gittinger"
   793     "Modified: / 19-07-2019 / 16:44:30 / Claus Gittinger"
   793     "Modified: / 19-07-2019 / 16:44:30 / Claus Gittinger"
   794     "Modified (comment): / 23-07-2019 / 09:32:44 / Claus Gittinger"
   794     "Modified (comment): / 23-07-2019 / 09:32:44 / Claus Gittinger"
   795 !
   795 !
   796 
   796 
   797 findComponent:componentNameOrPath in:anApplicationOrView
   797 findComponent:componentNameOrPath in:anApplicationOrViewOrMenuItem
   798     "find a component by name inside an app or inside a view.
   798     "find a component by name inside an app or inside a view.
   799      Uses the NameKey of the spec, and optionally the label or modelKey.
   799      Uses the NameKey of the spec, and optionally the label or modelKey.
   800      Can return either a view or a menu item"
   800      Can return either a view or a menu item"
   801 
   801 
   802     |idx app window component componentNameSymbol foundByName foundByTitle foundByLabel item
   802     |idx app window component componentNameSymbol foundByName foundByTitle foundByLabel item
   806         (idx := componentNameOrPath indexOf:$/) ~~ 0 ifTrue:[
   806         (idx := componentNameOrPath indexOf:$/) ~~ 0 ifTrue:[
   807             |containerName restPath container|
   807             |containerName restPath container|
   808 
   808 
   809             containerName := componentNameOrPath copyTo:idx-1.
   809             containerName := componentNameOrPath copyTo:idx-1.
   810             restPath := componentNameOrPath copyFrom:idx+1.
   810             restPath := componentNameOrPath copyFrom:idx+1.
   811             container := self findComponent:containerName in:anApplicationOrView.
   811             container := self findComponent:containerName in:anApplicationOrViewOrMenuItem.
   812             container isNil ifTrue:[ ^ nil ].
   812             container isNil ifTrue:[ ^ nil ].
   813             ^ self findComponent:restPath in:container
   813             ^ self findComponent:restPath in:container
   814         ]
   814         ]
   815     ].
   815     ].
   816 
   816 
   817     componentNameSymbol := componentNameOrPath asSymbolIfInterned ? componentNameOrPath.
   817     componentNameSymbol := componentNameOrPath asSymbolIfInterned ? componentNameOrPath.
   818 
   818 
   819     (app := anApplicationOrView) isView ifTrue:[
   819     (app := anApplicationOrViewOrMenuItem) isView ifTrue:[
   820         window := anApplicationOrView.
   820         window := anApplicationOrViewOrMenuItem.
   821         app := anApplicationOrView application
   821         app := anApplicationOrViewOrMenuItem application
   822     ].
   822     ].
   823     app notNil ifTrue:[
   823     app isApplicationModel ifTrue:[
   824         (component := app componentAt:componentNameSymbol) notNil ifTrue:[^ component].
   824         (component := app componentAt:componentNameSymbol) notNil ifTrue:[^ component].
   825         window := window ? app window.
   825         window := window ? app window.
   826     ].    
   826     ] ifFalse:[
       
   827         app isMenuItem ifTrue:[
       
   828             window := app submenu.
       
   829         ]
       
   830     ].
   827     
   831     
   828     "/ mhmh - search through all widgets of anApplication; 
   832     "/ mhmh - search through all widgets of anApplication; 
   829     "/ maybe it was not created via the builder/spec,
   833     "/ maybe it was not created via the builder/spec,
   830     "/ or it has changed its name.
   834     "/ or it has changed its name.
   831     "/ look for: widget's name, widget's title, widget's label
   835     "/ look for: widget's name, widget's title, widget's label
   849                     [
   853                     [
   850                         each label = componentNameSymbol ifTrue:[ foundByLabel add:each. foundIt := true ].
   854                         each label = componentNameSymbol ifTrue:[ foundByLabel add:each. foundIt := true ].
   851                     ] on:MessageNotUnderstood do:[:ex | ].
   855                     ] on:MessageNotUnderstood do:[:ex | ].
   852                     foundIt ifFalse:[
   856                     foundIt ifFalse:[
   853                         each isMenu ifTrue:[
   857                         each isMenu ifTrue:[
   854                             verifying ifFalse:[
       
   855                                 componentNameSymbol = 'NewTestSuite' ifTrue:[self halt].
       
   856                             ].
       
   857                             (item := each detectItemForNameKey:componentNameSymbol) notNil ifTrue:[
   858                             (item := each detectItemForNameKey:componentNameSymbol) notNil ifTrue:[
   858                                 foundByName add:item. foundIt := true
   859                                 foundByName add:item. foundIt := true
   859                             ].
   860                             ].
   860                             foundIt ifFalse:[
   861                             foundIt ifFalse:[
   861                                 (item := each detectItemForKey:componentNameSymbol) notNil ifTrue:[
   862                                 (item := each detectItemForKey:componentNameSymbol) notNil ifTrue:[