FlyByWindowInformation.st
author Claus Gittinger <cg@exept.de>
Sat, 21 Jul 2012 18:58:03 +0200
changeset 2898 c7f6c498df6a
parent 2847 65280fe44707
child 2939 5e2872ba0b95
permissions -rw-r--r--
category of:15 methods
     1 "
     2  COPYRIGHT (c) 2008 by eXept Software AG
     3               All Rights Reserved
     4 
     5  This software is furnished under a license and may be used
     6  only in accordance with the terms of that license and with the
     7  inclusion of the above copyright notice.   This software may not
     8  be provided or otherwise made available to, or used by, any
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    11 "
    12 "{ Package: 'stx:libtool2' }"
    13 
    14 FlyByHelp subclass:#FlyByWindowInformation
    15 	instanceVariableNames:'lastApplication lastView cleanupAction finishSemaphore finished'
    16 	classVariableNames:''
    17 	poolDictionaries:''
    18 	category:'Interface-Help'
    19 !
    20 
    21 !FlyByWindowInformation class methodsFor:'documentation'!
    22 
    23 copyright
    24 "
    25  COPYRIGHT (c) 2008 by eXept Software AG
    26               All Rights Reserved
    27 
    28  This software is furnished under a license and may be used
    29  only in accordance with the terms of that license and with the
    30  inclusion of the above copyright notice.   This software may not
    31  be provided or otherwise made available to, or used by, any
    32  other person.  No title to or ownership of the software is
    33  hereby transferred.
    34 "
    35 !
    36 
    37 examples
    38 "
    39     self shownInformationOfViewUnderMouseUntilButtonIsPressed
    40 "
    41 !
    42 
    43 shownInformationOfViewUnderMouseUntilButtonIsPressed
    44     self start waitUntilFinished
    45 
    46     "
    47      self shownInformationOfViewUnderMouseUntilButtonIsPressed
    48     "
    49 ! !
    50 
    51 !FlyByWindowInformation methodsFor:'accessing'!
    52 
    53 cleanupAction:something 
    54     cleanupAction := something.
    55 !
    56 
    57 lastApplication
    58     ^ lastApplication
    59 !
    60 
    61 lastView
    62     ^ lastView
    63 ! !
    64 
    65 !FlyByWindowInformation methodsFor:'defaults'!
    66 
    67 flyByHelpTimeoutMillis
    68     ^ 1000
    69 ! !
    70 
    71 !FlyByWindowInformation methodsFor:'event handling'!
    72 
    73 buttonMotion:buttonAndModifierState x:x y:y view:aView
    74     finished == true ifTrue:[^ self].
    75 
    76     super buttonMotion:buttonAndModifierState x:x y:y view:aView.
    77     ^ true
    78 !
    79 
    80 buttonPress:button x:x y:y view:aView
    81     self stop.
    82     ^ true
    83 !
    84 
    85 keyPress:key x:x y:y view:aView
    86     |obj objToInspect objToBrowse lcKey|
    87 
    88     key == #Escape ifTrue:[
    89         self stop.
    90         ^ true
    91     ].
    92 
    93     key == $? ifTrue:[
    94         [
    95             WindowTreeView notNil ifTrue:[
    96                 WindowTreeView openOn:(lastView topView) initialSelection:lastView.
    97             ] ifFalse:[
    98                 self warn:'WindowTreeView class is not present!!'.
    99             ].
   100         ] fork.
   101         self stop.
   102         ^ true.
   103     ].
   104 
   105     key == #Return ifTrue:[
   106         objToBrowse := lastApplication ? lastView
   107     ].
   108 
   109     key isCharacter ifTrue:[
   110         lcKey := key asLowercase.
   111 
   112         lcKey == $a ifTrue:[
   113             obj := lastApplication
   114         ].
   115         lcKey == $o ifTrue:[
   116             lastView notNil ifTrue:[
   117                 obj := lastView model
   118             ].
   119         ].
   120         lcKey == $m ifTrue:[
   121             lastApplication notNil ifTrue:[
   122                 obj := lastApplication masterApplication
   123             ]
   124         ].
   125         lcKey == $t ifTrue:[
   126             lastApplication notNil ifTrue:[
   127                 obj := lastApplication topApplication
   128             ].
   129         ].
   130         lcKey == $v ifTrue:[
   131             obj := lastView
   132         ].
   133         lcKey == $w ifTrue:[
   134             lastView notNil ifTrue:[
   135                 obj := lastView topView
   136             ]
   137         ].
   138         obj notNil ifTrue:[
   139             key isLowercase ifTrue:[
   140                 objToInspect := obj
   141             ] ifFalse:[
   142                 objToBrowse := obj
   143             ].
   144         ].
   145     ].
   146 
   147     objToInspect notNil ifTrue:[
   148         [ objToInspect inspect ] forkAt:(Processor userSchedulingPriority).
   149     ].
   150     objToBrowse notNil ifTrue:[
   151         [ objToBrowse browse ] forkAt:(Processor userSchedulingPriority).
   152     ].
   153 
   154     ^ true
   155 
   156     "Modified: / 12-11-2010 / 11:51:04 / cg"
   157 ! !
   158 
   159 !FlyByWindowInformation methodsFor:'help texts'!
   160 
   161 helpTextFor:aView at:aPointOrNil
   162     "generate the text to be shown as popup-flyby info"
   163 
   164     |resources|
   165 
   166     lastView := aView.
   167     lastApplication := aView application.
   168 
   169     resources := self class classResources.
   170 
   171     ^ Text streamContents:[:s |
   172         |topViewToInspect applicationToInspect 
   173          masterApplicationToInspect topApplicationToInspect modelToInspect
   174          genComponentNameForApplication|
   175 
   176         genComponentNameForApplication := 
   177             [:app :s |
   178                 (app notNil 
   179                 and:[ app builder notNil ]) ifTrue:[
   180                     |components v|
   181 
   182                     components := app builder namedComponents.
   183 
   184                     v := aView.
   185                     [   (components includes:v) not
   186                         and:[v container notNil]
   187                     ] whileTrue:[
   188                         v := v container.
   189                     ].
   190                     (components includes:v) ifTrue:[
   191                         |k|
   192 
   193                         k := components keyAtValue:v.
   194                         v == aView ifTrue:[
   195                             s nextPutLine:('       component: ' , k).
   196                         ] ifFalse:[
   197                             s nextPutLine:('       subview of component: ' , k).
   198                         ].
   199                     ].
   200                 ].
   201             ].
   202 
   203         aView topView ~~ aView ifTrue:[
   204             topViewToInspect := aView topView.
   205         ].
   206         lastApplication notNil ifTrue:[
   207             applicationToInspect := lastApplication.
   208             masterApplicationToInspect := lastApplication masterApplication.
   209             masterApplicationToInspect notNil ifTrue:[
   210                 masterApplicationToInspect == applicationToInspect ifTrue:[
   211                     masterApplicationToInspect := nil
   212                 ] ifFalse:[
   213                     topApplicationToInspect := masterApplicationToInspect topApplication.
   214                     topApplicationToInspect == masterApplicationToInspect ifTrue:[
   215                         topApplicationToInspect := nil
   216                     ]
   217                 ].
   218             ]
   219         ].
   220         aView model notNil ifTrue:[
   221             modelToInspect := aView model.
   222             ((modelToInspect == applicationToInspect)
   223             or:[ modelToInspect == masterApplicationToInspect ]) ifTrue:[
   224                 modelToInspect := nil.
   225             ].
   226         ].
   227 
   228         applicationToInspect notNil ifTrue:[
   229             s nextPutLine:(resources string:'Application: %1' with:applicationToInspect class name allBold).
   230             genComponentNameForApplication value:applicationToInspect value:s.
   231         ].
   232         masterApplicationToInspect notNil ifTrue:[
   233             s nextPutLine:(resources string:'Master-Application: %1' with:masterApplicationToInspect class name allBold).
   234             "/ genComponentNameForApplication value:masterApplicationToInspect value:s.
   235         ].
   236         topApplicationToInspect notNil ifTrue:[
   237             s nextPutLine:(resources string:'Top-Application: %1' with:topApplicationToInspect class name allBold).
   238             "/ genComponentNameForApplication value:topApplicationToInspect value:s.
   239         ].
   240         s nextPutLine:(resources string:'View: %1 "%2"' with:aView class name allBold with:aView name).
   241         topViewToInspect notNil ifTrue:[
   242             s nextPutLine:(resources string:'Topview: %1' with:topViewToInspect class name allBold).
   243         ].
   244         modelToInspect notNil ifTrue:[
   245             s nextPutLine:(resources string:'Model: %1' with:modelToInspect class name allBold).
   246         ].
   247 
   248         s cr.
   249         s nextPutLine:'Press:'.
   250         s nextPutLine:'    ? to show the viewtree'.
   251         applicationToInspect notNil ifTrue:[
   252             s nextPutLine:'    a to inspect application (A to browse)'.
   253             masterApplicationToInspect notNil ifTrue:[
   254                 s nextPutLine:'    m to inspect masterApplication (M to browse)'.
   255                 topApplicationToInspect notNil ifTrue:[
   256                     s nextPutLine:'    t to inspect masterApplication (T to browse)'.
   257                 ]
   258             ].
   259         ].
   260         s nextPutLine:'    v to inspect view (V to browse)'.
   261         topViewToInspect notNil ifTrue:[
   262             s nextPutLine:'    w to inspect topWindow (W to browse)'.
   263         ].
   264         modelToInspect notNil ifTrue:[
   265             s nextPutLine:'    o to inspect model (O to browse)'.
   266         ].
   267         s cr.
   268         s nextPutLine:'RETURN to browse application.'.
   269         s nextPutAll:'ESC or click to leave flyBy-info mode.'.
   270     ]
   271 
   272     "
   273      self shownInformationOfViewUnderMouseUntilButtonIsPressed
   274     "
   275 
   276     "Modified: / 12-11-2010 / 11:54:59 / cg"
   277 ! !
   278 
   279 !FlyByWindowInformation methodsFor:'private'!
   280 
   281 handleMouseIn:aView x:x y:y
   282     finished == true ifTrue:[^ self].
   283     super handleMouseIn:aView x:x y:y
   284 !
   285 
   286 targetViewInitiatesHelpViaSensor
   287     ^ false
   288 ! !
   289 
   290 !FlyByWindowInformation methodsFor:'queries'!
   291 
   292 toolTipFollowsMouse
   293     ^ true
   294 ! !
   295 
   296 !FlyByWindowInformation methodsFor:'start & stop'!
   297 
   298 initiateHelpFor:aView at:aPointOrNil
   299     self initiateHelpFor:aView at:aPointOrNil now:true
   300 !
   301 
   302 initiateHelpFor:aView at:aPointOrNil now:showItNow
   303     finished == true ifTrue:[^ self].
   304     super initiateHelpFor:aView at:aPointOrNil now:showItNow
   305 !
   306 
   307 start
   308     |l|
   309 
   310     finished == true ifTrue:[^ self].
   311 
   312     l := FlyByHelp currentHelpListener.
   313     l notNil ifTrue:[
   314         FlyByHelp stop.
   315         cleanupAction := [ FlyByHelp start ].
   316     ].
   317     finishSemaphore := Semaphore new.
   318     finished := false.
   319     super start.
   320 !
   321 
   322 stop
   323     finished := true.
   324     super stop.
   325     cleanupAction value.
   326     finishSemaphore notNil ifTrue:[
   327         finishSemaphore signalIf.
   328     ].
   329 !
   330 
   331 waitUntilFinished
   332     finishSemaphore wait.
   333 ! !
   334 
   335 !FlyByWindowInformation class methodsFor:'documentation'!
   336 
   337 version_CVS
   338     ^ '$Header$'
   339 ! !