author | Claus Gittinger <cg@exept.de> |
Thu, 21 Feb 2019 17:56:00 +0100 | |
changeset 4230 | 240c17007808 |
parent 4228 | 699d09d62316 |
child 4231 | 5542e515b2d9 |
permissions | -rw-r--r-- |
4230 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1802 | 3 |
" |
4 |
COPYRIGHT (c) 2001 by eXept Software AG |
|
5 |
All Rights Reserved |
|
6 |
||
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
1536 | 14 |
"{ Package: 'stx:libview2' }" |
15 |
||
3656 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
1536 | 18 |
ActiveHelp subclass:#FlyByHelp |
4119 | 19 |
instanceVariableNames:'currentFrame currentView currentHelpView showProcess closeProcess' |
20 |
classVariableNames:'MaxNumberOfLines MaxNumberOfColumns' |
|
21 |
poolDictionaries:'' |
|
22 |
category:'Interface-Help' |
|
1536 | 23 |
! |
24 |
||
1802 | 25 |
!FlyByHelp class methodsFor:'documentation'! |
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 2001 by eXept Software AG |
|
30 |
All Rights Reserved |
|
31 |
||
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
1893 | 39 |
! |
40 |
||
4055 | 41 |
documentation |
42 |
" |
|
43 |
an instance of me is used to provide tooltips |
|
44 |
(sigh: smalltalk was ahead of its time in the early 90's: |
|
45 |
initially called 'activeHelp', then renamed to 'flyByHelp' |
|
46 |
and now commonly known as tooltip). |
|
47 |
||
48 |
I will watch the mouse movements via an event hook, and determine |
|
49 |
where the mouse pointer is. Then ask the underlying view about its |
|
50 |
helpText and display it in a little floating popup view. |
|
51 |
||
52 |
The hool is installed via: |
|
53 |
FlyByHelp start |
|
54 |
and possibly deactivated/uninstalled via: |
|
55 |
FlyByHelp stop |
|
56 |
||
57 |
There can be only one FlyByHelp at any time - the start/stop methods |
|
58 |
assure that. |
|
59 |
" |
|
60 |
! |
|
61 |
||
1893 | 62 |
examples |
63 |
" |
|
3220 | 64 |
UserPreferences current toolTipShapeStyle:nil |
65 |
UserPreferences current toolTipShapeStyle:#cartoon |
|
66 |
||
1893 | 67 |
FlyByHelp isActive |
68 |
||
69 |
FlyByHelp stop |
|
70 |
FlyByHelp start |
|
71 |
" |
|
1802 | 72 |
! ! |
1536 | 73 |
|
2692 | 74 |
!FlyByHelp class methodsFor:'accessing'! |
75 |
||
76 |
currentlyShownView |
|
2846
e90ba00f9df1
changed: #currentlyShownView
Claus Gittinger <cg@exept.de>
parents:
2826
diff
changeset
|
77 |
TheOneAndOnlyHelpListener isNil ifTrue:[^ nil]. |
2692 | 78 |
^ TheOneAndOnlyHelpListener currentlyShownView |
2846
e90ba00f9df1
changed: #currentlyShownView
Claus Gittinger <cg@exept.de>
parents:
2826
diff
changeset
|
79 |
|
e90ba00f9df1
changed: #currentlyShownView
Claus Gittinger <cg@exept.de>
parents:
2826
diff
changeset
|
80 |
"Modified: / 09-06-2010 / 16:35:48 / cg" |
3255 | 81 |
! |
82 |
||
83 |
maxNumberOfColumns |
|
84 |
^ MaxNumberOfColumns ? 200 |
|
85 |
! |
|
86 |
||
87 |
maxNumberOfLines |
|
88 |
^ MaxNumberOfLines ? 40 |
|
2692 | 89 |
! ! |
90 |
||
2684 | 91 |
!FlyByHelp methodsFor:'defaults'! |
92 |
||
93 |
flyByHelpTimeoutMillis |
|
94 |
"abort flyby help text generation, if no text can be generated within that |
|
95 |
time delta. This is used to abort long-lasting parsing/scanning/analysis in |
|
96 |
large methods when the mouse is moved over some syntactic constructs, and |
|
97 |
it takes too long to parse... |
|
98 |
The returned time is given in ms" |
|
99 |
||
100 |
^ 300 |
|
101 |
! ! |
|
102 |
||
2392 | 103 |
!FlyByHelp methodsFor:'event handling'! |
1540 | 104 |
|
2474 | 105 |
buttonMotion:buttonAndModifierState x:x y:y view:aView |
2519 | 106 |
aView == currentHelpView ifTrue:[ |
107 |
"/ the help-bubble itself |
|
108 |
^ false |
|
109 |
]. |
|
110 |
||
4055 | 111 |
"/ don't start tooltip, if this view is not active. |
112 |
"/ The following line does not work, because motion events are reported for the current focus-view, |
|
3321 | 113 |
"/ which is always active. Must check after we have determined the view under the pointer |
3675 | 114 |
"/ aView topView isActive ifFalse:[^ false]. |
2477
b009e0b51999
suppress tooltip for inactive (lower) windows
Claus Gittinger <cg@exept.de>
parents:
2474
diff
changeset
|
115 |
|
2474 | 116 |
^ super buttonMotion:buttonAndModifierState x:x y:y view:aView |
1540 | 117 |
! |
118 |
||
2611
f578b9c43a6f
handle escape key to close flyByHelp
Claus Gittinger <cg@exept.de>
parents:
2521
diff
changeset
|
119 |
buttonPress:button x:x y:y view:aView |
3198 | 120 |
|prevView| |
121 |
||
122 |
"/ hideHelp nils the currentView |
|
123 |
"/ we restore it, so the tooltip is not shown again for this view |
|
124 |
"/ until the mouse really leaves the view |
|
125 |
"/ let's call this the "do-not-show-in-this-view mode" |
|
126 |
prevView := currentView. |
|
2978
4358a9302b95
changed: #buttonPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents:
2925
diff
changeset
|
127 |
self hideHelp. |
3198 | 128 |
currentView := prevView. |
129 |
||
130 |
^ false |
|
2978
4358a9302b95
changed: #buttonPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents:
2925
diff
changeset
|
131 |
|
4358a9302b95
changed: #buttonPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents:
2925
diff
changeset
|
132 |
"Modified: / 23-12-2011 / 20:37:28 / cg" |
2611
f578b9c43a6f
handle escape key to close flyByHelp
Claus Gittinger <cg@exept.de>
parents:
2521
diff
changeset
|
133 |
! |
f578b9c43a6f
handle escape key to close flyByHelp
Claus Gittinger <cg@exept.de>
parents:
2521
diff
changeset
|
134 |
|
f578b9c43a6f
handle escape key to close flyByHelp
Claus Gittinger <cg@exept.de>
parents:
2521
diff
changeset
|
135 |
keyPress:key x:x y:y view:aView |
4226 | 136 |
<resource: #keyboard (#Escape #Control #Shift)> |
3216 | 137 |
|
4228 | 138 |
|prevView text| |
3198 | 139 |
|
2885
a70144d85a81
changed: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents:
2884
diff
changeset
|
140 |
currentHelpView notNil ifTrue:[ |
4230 | 141 |
key == $§ ifTrue:[ |
2979
306456bdfb61
comment in: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents:
2978
diff
changeset
|
142 |
"/ generate a line suitable for the resources file (a null translation) |
3216 | 143 |
"/ into the clipboard; makes it easy to add missing translations to a .rs file, |
4082 | 144 |
"/ by pressing paragraph whenever you see an untranslated helptext |
4228 | 145 |
text := (lastHelpText storeString withoutCRs, ' ' , lastHelpText storeString withoutCRs). |
146 |
aView setClipboardText:text. |
|
2612 | 147 |
self hideHelp. |
4230 | 148 |
^ false |
2612 | 149 |
]. |
2979
306456bdfb61
comment in: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents:
2978
diff
changeset
|
150 |
key == #Escape ifTrue:[ |
3198 | 151 |
prevView := currentView. |
2979
306456bdfb61
comment in: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents:
2978
diff
changeset
|
152 |
self hideHelp. |
3198 | 153 |
currentView := prevView. |
4230 | 154 |
^ false |
2885
a70144d85a81
changed: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents:
2884
diff
changeset
|
155 |
]. |
4228 | 156 |
(#(#'Shift' #'Shift_L' #'Shift_R') includes:key) ifTrue:[ |
157 |
aView device ctrlDown ifTrue:[ |
|
4230 | 158 |
self hideHelp. |
159 |
self openDeveloperMenuFor:aView |
|
160 |
]. |
|
161 |
^ false |
|
4228 | 162 |
]. |
163 |
||
164 |
(#(#'Control' #'Control_L' #'Control_R') includes:key) ifTrue:[ |
|
4226 | 165 |
"/ reopen showing the key |
166 |
self initiateHelpFor:aView at:(x@y) now:true. |
|
4230 | 167 |
^ false |
4226 | 168 |
]. |
169 |
||
170 |
(#('Shift' #'Shift_L' #'Shift_R' #'Control' #'Control_L' #'Control_R') includes:key) ifTrue:[ |
|
3216 | 171 |
"/ do not close on those... |
172 |
^ false |
|
173 |
]. |
|
4226 | 174 |
]. |
3198 | 175 |
|
176 |
"/ hideHelp nils the currentView |
|
177 |
"/ we restore it, so the tooltip is not shown again for this view |
|
178 |
"/ until the mouse really leaves the view |
|
179 |
"/ let's call this the "do-not-show-in-this-view mode" |
|
180 |
prevView := currentView. |
|
181 |
self hideHelpIgnoringErrors. |
|
182 |
currentView := prevView. |
|
183 |
||
184 |
^ false |
|
185 |
"/ ^ super keyPress:key x:x y:y view:aView |
|
2884
7d37f5a0719e
changed: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents:
2878
diff
changeset
|
186 |
|
2979
306456bdfb61
comment in: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents:
2978
diff
changeset
|
187 |
"Modified (format): / 25-12-2011 / 10:25:23 / cg" |
4082 | 188 |
"Modified (format): / 16-04-2018 / 16:53:15 / stefan" |
4230 | 189 |
"Modified: / 21-02-2019 / 17:22:48 / Claus Gittinger" |
4226 | 190 |
! |
191 |
||
192 |
keyRelease:key x:x y:y view:aView |
|
193 |
<resource: #keyboard (#Control)> |
|
194 |
||
195 |
currentHelpView notNil ifTrue:[ |
|
196 |
(#(#'Control' #'Control_L' #'Control_R') includes:key) ifTrue:[ |
|
197 |
"/ reopen showing the text |
|
198 |
self initiateHelpFor:aView at:(x@y) now:true. |
|
199 |
^ true |
|
200 |
]. |
|
201 |
(#('Shift' #'Shift_L' #'Shift_R' #'Control' #'Control_L' #'Control_R') includes:key) ifTrue:[ |
|
202 |
"/ do not close on those... |
|
203 |
^ false |
|
204 |
]. |
|
205 |
]. |
|
206 |
^ super keyRelease:key x:x y:y view:aView |
|
207 |
||
208 |
"Created: / 20-02-2019 / 11:26:19 / Claus Gittinger" |
|
2611
f578b9c43a6f
handle escape key to close flyByHelp
Claus Gittinger <cg@exept.de>
parents:
2521
diff
changeset
|
209 |
! |
f578b9c43a6f
handle escape key to close flyByHelp
Claus Gittinger <cg@exept.de>
parents:
2521
diff
changeset
|
210 |
|
2521
7e51aa294156
care for mousewheel while showing help
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
211 |
mouseWheelMotion:state x:x y:y amount:amount deltaTime:dTime view:aView |
7e51aa294156
care for mousewheel while showing help
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
212 |
currentHelpView notNil ifTrue:[ |
7e51aa294156
care for mousewheel while showing help
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
213 |
self handleMouseIn:aView x:x y:y. |
7e51aa294156
care for mousewheel while showing help
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
214 |
]. |
7e51aa294156
care for mousewheel while showing help
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
215 |
^ false |
7e51aa294156
care for mousewheel while showing help
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
216 |
! |
7e51aa294156
care for mousewheel while showing help
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
217 |
|
4230 | 218 |
openDeveloperMenuFor:aView |
219 |
|app helpText helpKey| |
|
220 |
||
221 |
app := aView topView application. |
|
222 |
app enqueueDelayedAction:[ |
|
223 |
|editor m canDefineTranslationForLabel canDefineTranslationForHelpText| |
|
224 |
||
225 |
m := Menu new. |
|
226 |
m addItem:(MenuItem |
|
227 |
label: 'Edit Resources' |
|
228 |
itemValue:[ |
|
229 |
app enqueueDelayedAction:[ |
|
230 |
app withWaitCursorDo:[ |
|
231 |
editor := Tools::InternationalLanguageTranslationEditor |
|
232 |
openOnPackage:((aView topView application ? aView) class package). |
|
233 |
editor selectOrAddKey:(lastHelpText storeString withoutCRs). |
|
234 |
Transcript showCR:'help text is: %1' with:lastHelpText storeString withoutCRs. |
|
235 |
||
236 |
]. |
|
237 |
]. |
|
238 |
]). |
|
239 |
m addItem:(MenuItem |
|
240 |
label: 'Browse Resources' |
|
241 |
itemValue:[ |
|
242 |
app enqueueDelayedAction:[ |
|
243 |
app withWaitCursorDo:[ |
|
244 |
FileBrowser default |
|
245 |
openOn:(app class projectDefinitionClass |
|
246 |
packageDirectory / 'resources'). |
|
247 |
]. |
|
248 |
]. |
|
249 |
]). |
|
250 |
||
251 |
canDefineTranslationForLabel := |
|
252 |
[ |
|
253 |
aView isTextLabel |
|
254 |
or:[ aView isButton ] |
|
255 |
]. |
|
256 |
||
257 |
canDefineTranslationForHelpText := |
|
258 |
[ |
|
259 |
|ok| |
|
260 |
||
261 |
ok := lastHelpText notEmptyOrNil. |
|
262 |
ok := ok or:[ (helpText := aView helpText) notEmptyOrNil]. |
|
263 |
ok := ok or:[ (helpKey := aView helpKey) notNil]. |
|
264 |
ok := ok or:[ (helpText := app helpTextFor:aView) notEmptyOrNil ]. |
|
265 |
ok |
|
266 |
]. |
|
267 |
||
268 |
m addItem:(MenuItem |
|
269 |
label: 'Define Translation for Label...' |
|
270 |
itemValue:[ |
|
271 |
|package key | |
|
272 |
||
273 |
key := aView label asString string. |
|
274 |
package := app class package. |
|
275 |
ResourcePack defineResourceFor:key package:package. |
|
276 |
] |
|
277 |
enabled:canDefineTranslationForLabel). |
|
278 |
m addItem:(MenuItem |
|
279 |
label: 'Define Translation for Helptext...' |
|
280 |
itemValue:[ |
|
281 |
|package key | |
|
282 |
||
283 |
key := (lastHelpText ? helpText ? helpKey) asString string. |
|
284 |
package := app class package. |
|
285 |
ResourcePack defineResourceFor:key package:package. |
|
286 |
] |
|
287 |
enabled:canDefineTranslationForHelpText). |
|
288 |
||
289 |
m showAtPointer. |
|
290 |
]. |
|
291 |
||
292 |
"Created: / 21-02-2019 / 17:20:20 / Claus Gittinger" |
|
293 |
! |
|
294 |
||
1540 | 295 |
pointerLeave:state view:aView |
2611
f578b9c43a6f
handle escape key to close flyByHelp
Claus Gittinger <cg@exept.de>
parents:
2521
diff
changeset
|
296 |
aView == currentHelpView ifTrue:[^ true]. |
3198 | 297 |
|
298 |
"/ clear the do-not-show-in-this-view mode (see keyPress) |
|
299 |
"/ (currentHelpView isNil and:[currentView notNil]) ifTrue:[currentView := nil]. |
|
300 |
||
2611
f578b9c43a6f
handle escape key to close flyByHelp
Claus Gittinger <cg@exept.de>
parents:
2521
diff
changeset
|
301 |
^ super pointerLeave:state view:aView |
1540 | 302 |
! ! |
303 |
||
2392 | 304 |
!FlyByHelp methodsFor:'help texts'! |
1536 | 305 |
|
306 |
helpTextFromModel:aModel view:aView at:aPointOrNil |
|
307 |
"helper: ask aModel for its helpText." |
|
308 |
||
309 |
|text| |
|
310 |
||
4048 | 311 |
(aPointOrNil notNil and:[aModel respondsTo:#helpTextFor:at:]) ifTrue:[ |
312 |
text := aModel helpTextFor:aView at:aPointOrNil. |
|
4121 | 313 |
text notNil ifTrue:[ |
314 |
"/ Transcript showCR:aModel. |
|
315 |
"/ Transcript showCR:'via model-text'; showCR:text. |
|
316 |
^ text |
|
317 |
]. |
|
1536 | 318 |
]. |
4048 | 319 |
(aModel respondsTo:#helpTextFor:) ifTrue:[ |
320 |
text := aModel helpTextFor:aView. |
|
4121 | 321 |
text notNil ifTrue:[ |
322 |
"/ Transcript showCR:aModel. |
|
323 |
"/ Transcript showCR:'via model-text'; showCR:text. |
|
324 |
^ text |
|
325 |
]. |
|
1536 | 326 |
]. |
2754 | 327 |
^ nil |
4040 | 328 |
|
329 |
"Modified: / 09-01-2018 / 17:35:26 / stefan" |
|
4121 | 330 |
"Modified: / 11-06-2018 / 09:53:40 / Claus Gittinger" |
1536 | 331 |
! |
332 |
||
333 |
helpTextFromView:aView at:aPointOrNil |
|
334 |
"helper: ask aView for its helpText." |
|
335 |
||
2754 | 336 |
|text key app| |
1536 | 337 |
|
4121 | 338 |
"/ is there any view which does not understand helpTextAt: ??? |
4048 | 339 |
(aPointOrNil notNil and:[aView respondsTo:#helpTextAt:]) ifTrue:[ |
340 |
text := aView helpTextAt:aPointOrNil. |
|
4121 | 341 |
text notNil ifTrue:[ |
342 |
"/ Transcript showCR:'via helpTextAt:'; showCR:text. |
|
343 |
^ text |
|
344 |
]. |
|
1536 | 345 |
]. |
4121 | 346 |
"/ is there any view which does not understand helpText ??? |
4048 | 347 |
(aView respondsTo:#helpText) ifTrue:[ |
348 |
text := aView helpText. |
|
4121 | 349 |
text notNil ifTrue:[ |
350 |
"/ Transcript showCR:'via helpText'; showCR:text. |
|
4220 | 351 |
^ text value |
4121 | 352 |
]. |
2754 | 353 |
]. |
3804 | 354 |
"/ to be enabled in next release... |
355 |
"/ (aView superView notNil |
|
4048 | 356 |
"/ and:[aView superView respondsTo:#helpTextFor:]) ifTrue:[ |
357 |
"/ text := aView superView helpTextFor:aView. |
|
3804 | 358 |
"/ text notNil ifTrue:[^ text]. |
359 |
"/ ]. |
|
4121 | 360 |
|
361 |
"/ is there any view which does not understand helpKey ??? |
|
2754 | 362 |
(aView respondsTo:#helpKey) ifTrue:[ |
363 |
key := aView helpKey. |
|
364 |
key notNil ifTrue:[ |
|
365 |
app := aView application. |
|
366 |
app isNil ifTrue:[ |
|
4175 | 367 |
|topView topViewsHelpSpec| |
368 |
||
3763 | 369 |
"/ special case for oldStyle Dialog subclasses. |
4175 | 370 |
topView := aView topView. |
371 |
(topViewsHelpSpec := topView helpSpec) notNil ifTrue:[ |
|
372 |
text := topViewsHelpSpec at:key ifAbsent:nil. |
|
3763 | 373 |
text notNil ifTrue:[ |
4121 | 374 |
"/ Transcript showCR:'via topViewspec+helpKey'; showCR:text. |
4175 | 375 |
^ topView resources stringWithCRs:text. |
3763 | 376 |
]. |
377 |
]. |
|
2754 | 378 |
app := Error handle:[:ex | nil] do:[ aView windowGroup mainGroup application ]. |
379 |
]. |
|
380 |
app notNil ifTrue:[ |
|
4121 | 381 |
text := app helpTextForKey:key. |
382 |
true "text notNil" ifTrue:[ |
|
383 |
"/ Transcript showCR:'via helpKey+helpTextForKey:'; showCR:text. |
|
384 |
^ text |
|
385 |
]. |
|
2754 | 386 |
]. |
4121 | 387 |
text := aView resources string:key. |
388 |
true "(text notNil and:[text ~= key])" ifTrue:[ |
|
389 |
"/ Transcript showCR:'via helpKey'; showCR:text. |
|
4110 | 390 |
^ text |
391 |
] |
|
1536 | 392 |
]. |
393 |
]. |
|
2754 | 394 |
^ nil. |
4040 | 395 |
|
396 |
"Modified: / 09-01-2018 / 17:38:42 / stefan" |
|
4111 | 397 |
"Modified (format): / 07-06-2018 / 09:51:41 / sr" |
4220 | 398 |
"Modified: / 07-02-2019 / 19:18:39 / Claus Gittinger" |
2392 | 399 |
! ! |
400 |
||
4119 | 401 |
!FlyByHelp methodsFor:'queries'! |
402 |
||
403 |
currentlyShownView |
|
404 |
^ currentHelpView |
|
405 |
! |
|
406 |
||
407 |
toolTipFollowsMouse |
|
408 |
"if true, the tooltip-window moves with the pointer |
|
409 |
so that it stays away from (does not cover) the mouse pointer" |
|
410 |
||
411 |
^ false |
|
412 |
||
413 |
"Modified: / 06-06-2018 / 17:37:19 / Claus Gittinger" |
|
414 |
! ! |
|
415 |
||
416 |
!FlyByHelp methodsFor:'show & hide help'! |
|
417 |
||
418 |
activeHelpViewForApplication:applicationOrNil text:helpText onDevice:aDevice |
|
419 |
applicationOrNil notNil ifTrue:[ |
|
420 |
^ applicationOrNil activeHelpViewFor:helpText onDevice:aDevice |
|
421 |
]. |
|
422 |
^ ActiveHelpView for:helpText onDevice:aDevice. |
|
423 |
||
424 |
" |
|
425 |
(ActiveHelpView for:'Hello' onDevice:Display) open |
|
426 |
" |
|
427 |
! |
|
428 |
||
429 |
hideHelp |
|
430 |
"hide the help text" |
|
431 |
||
432 |
|p| |
|
433 |
||
434 |
"/ lastHelpText := nil. |
|
435 |
self stopHelpDisplayProcess. |
|
436 |
lastHelpText := nil. |
|
437 |
||
438 |
currentHelpView notNil ifTrue:[ |
|
439 |
[ |
|
440 |
currentHelpView notNil ifTrue:[ |
|
441 |
currentHelpView destroy. |
|
442 |
currentHelpView := nil. |
|
443 |
currentView := nil. |
|
444 |
] |
|
445 |
] valueUninterruptably |
|
446 |
]. |
|
447 |
currentFrame := nil. |
|
448 |
(p := closeProcess) notNil ifTrue:[ |
|
449 |
closeProcess := nil. |
|
450 |
p terminate. |
|
451 |
] |
|
452 |
||
453 |
"Modified: / 28-06-1997 / 14:03:50 / cg" |
|
454 |
"Modified: / 16-04-2018 / 16:51:01 / stefan" |
|
455 |
! |
|
1536 | 456 |
|
457 |
hideIfPointerLeft:aView |
|
458 |
"hide help, if the pointer is not in aView" |
|
459 |
||
4119 | 460 |
|helpFrame whereOnScreen| |
1536 | 461 |
|
4119 | 462 |
(helpFrame := currentFrame) notNil ifTrue:[ |
1536 | 463 |
whereOnScreen := aView graphicsDevice pointerPosition. |
464 |
||
4119 | 465 |
((helpFrame insetBy:1@1) containsPoint:whereOnScreen) ifFalse:[ |
1536 | 466 |
self hideHelp. |
4119 | 467 |
] ifTrue:[ |
468 |
pointerPositionAtShowTime notNil ifTrue:[ |
|
469 |
(whereOnScreen dist:pointerPositionAtShowTime) > 10 ifTrue:[ |
|
470 |
self hideHelp. |
|
471 |
]. |
|
472 |
]. |
|
473 |
]. |
|
1536 | 474 |
]. |
475 |
||
4082 | 476 |
"Modified: / 28-05-1996 / 20:18:28 / cg" |
477 |
"Modified: / 16-04-2018 / 16:59:48 / stefan" |
|
4119 | 478 |
"Modified: / 08-06-2018 / 10:30:04 / Claus Gittinger" |
1536 | 479 |
! |
480 |
||
481 |
initiateHelpFor:aView at:aPointOrNil now:showItNow |
|
482 |
"ask aView for helpText, passing x/y coordinates; |
|
483 |
start a timeout process to display this helpText after some delay; |
|
484 |
Normally used internally, but can also be used by widgets to force |
|
485 |
re-negotiation of the displayed helpText |
|
486 |
(for example in a menu, when the selection changes)" |
|
487 |
||
4110 | 488 |
|text delayTime| |
1536 | 489 |
|
490 |
(self interestedIn:aView) ifFalse:[ |
|
491 |
^ self |
|
492 |
]. |
|
493 |
||
2680 | 494 |
"/ do not allow for more than 200 ms to be spent in the |
2679
552847065fb3
car not to hog the cpu by flyByHelp processing
Claus Gittinger <cg@exept.de>
parents:
2651
diff
changeset
|
495 |
"/ helpText gatherer (the codeView parses the code for the variable under the cursor) |
552847065fb3
car not to hog the cpu by flyByHelp processing
Claus Gittinger <cg@exept.de>
parents:
2651
diff
changeset
|
496 |
[ |
2826
74bd82edee5a
changed: #initiateHelpFor:at:now:
Claus Gittinger <cg@exept.de>
parents:
2799
diff
changeset
|
497 |
Error handle:[:ex | |
3394 | 498 |
('FlyByhelp [warning]: error while asking for helpText: ',ex description) errorPrintCR. |
3675 | 499 |
Transcript showCR:'-------------------------'. |
3394 | 500 |
ex suspendedContext fullPrintAllOn:Transcript. |
2872
ea7e6fe01727
comment/format in: #initiateHelpFor:at:now:
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
501 |
"/ self halt. |
2826
74bd82edee5a
changed: #initiateHelpFor:at:now:
Claus Gittinger <cg@exept.de>
parents:
2799
diff
changeset
|
502 |
] do:[ |
74bd82edee5a
changed: #initiateHelpFor:at:now:
Claus Gittinger <cg@exept.de>
parents:
2799
diff
changeset
|
503 |
text := self helpTextFor:aView at:aPointOrNil. |
74bd82edee5a
changed: #initiateHelpFor:at:now:
Claus Gittinger <cg@exept.de>
parents:
2799
diff
changeset
|
504 |
]. |
3656 | 505 |
] valueWithWatchDog:[ |
506 |
'FlyByhelp [info]: flyBy text generation took too long' infoPrintCR. |
|
507 |
^ self |
|
508 |
] afterMilliseconds:(self flyByHelpTimeoutMillis). |
|
2679
552847065fb3
car not to hog the cpu by flyByHelp processing
Claus Gittinger <cg@exept.de>
parents:
2651
diff
changeset
|
509 |
|
4110 | 510 |
false ifTrue:[ |
511 |
(text notNil and:[text isEmpty]) ifTrue:[ |
|
512 |
Logger warning:('empty help from: ',aView class printString) |
|
513 |
] ifFalse:[ |
|
514 |
text isEmptyOrNil ifTrue:[ |
|
515 |
Logger warning:('no help from: ',aView class printString) |
|
516 |
]. |
|
517 |
]. |
|
518 |
]. |
|
519 |
||
4082 | 520 |
(lastHelpText = text and:[lastHelpWidget == aView]) ifTrue:[ |
521 |
self toolTipFollowsMouse ifFalse:[ |
|
522 |
^ self |
|
2392 | 523 |
] |
1536 | 524 |
]. |
525 |
||
4110 | 526 |
((text size > 0) or:[text notNil and:[text isString not]]) ifTrue:[ |
2778 | 527 |
(showItNow not and:[(delayTime := self delayTime) > 0]) ifTrue:[ |
1536 | 528 |
self stopHelpDisplayProcess. |
2392 | 529 |
showProcess := |
530 |
[ |
|
2680 | 531 |
Delay waitForSeconds:delayTime. |
2774
7894ba397774
changed: #initiateHelpFor:at:now:
Claus Gittinger <cg@exept.de>
parents:
2754
diff
changeset
|
532 |
[ |
3766 | 533 |
aView device notNil ifTrue:[ |
534 |
aView device anyButtonPressed ifFalse:[ |
|
535 |
showProcess := nil. |
|
536 |
self showHelp:text for:aView |
|
537 |
] |
|
538 |
]. |
|
2774
7894ba397774
changed: #initiateHelpFor:at:now:
Claus Gittinger <cg@exept.de>
parents:
2754
diff
changeset
|
539 |
] ensure:[ |
7894ba397774
changed: #initiateHelpFor:at:now:
Claus Gittinger <cg@exept.de>
parents:
2754
diff
changeset
|
540 |
showProcess := nil. |
2680 | 541 |
] |
2392 | 542 |
] forkAt:(Processor userSchedulingPriority + 1). |
1536 | 543 |
] ifFalse:[ |
544 |
self showHelp:text for:aView |
|
545 |
] |
|
1542 | 546 |
] ifFalse:[ |
547 |
self hideHelp |
|
1536 | 548 |
]. |
2872
ea7e6fe01727
comment/format in: #initiateHelpFor:at:now:
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
549 |
|
2901
fed697afcef8
changed: #initiateHelpFor:at:now:
Claus Gittinger <cg@exept.de>
parents:
2900
diff
changeset
|
550 |
"Modified: / 22-03-2011 / 19:10:28 / cg" |
4082 | 551 |
"Modified: / 16-04-2018 / 12:20:33 / stefan" |
4110 | 552 |
"Modified: / 06-06-2018 / 17:19:26 / Claus Gittinger" |
1536 | 553 |
! |
554 |
||
555 |
showHelp:aHelpText for:view |
|
556 |
"show the help text for aView" |
|
557 |
||
3786 | 558 |
|wg applicationOrNil org p v device helpTextShown textLines |
3334 | 559 |
helpViewWidth helpViewHeight usableWidth monitorBounds usableHeight |
4119 | 560 |
showTime cursorView pos pointerPosition| |
1536 | 561 |
|
2781 | 562 |
"/ thisContext fullPrintAllOn:Transcript. |
2651 | 563 |
(wg := view windowGroup) notNil ifTrue:[ |
564 |
wg isInModalLoop ifTrue:[ |
|
565 |
wg isModal ifFalse:[ |
|
566 |
^ self |
|
567 |
]. |
|
2628
03a41945fb37
do not show flyBy help for a view,
Claus Gittinger <cg@exept.de>
parents:
2612
diff
changeset
|
568 |
]. |
03a41945fb37
do not show flyBy help for a view,
Claus Gittinger <cg@exept.de>
parents:
2612
diff
changeset
|
569 |
]. |
03a41945fb37
do not show flyBy help for a view,
Claus Gittinger <cg@exept.de>
parents:
2612
diff
changeset
|
570 |
|
3786 | 571 |
device := view graphicsDevice. |
4119 | 572 |
pointerPosition := device pointerPosition. |
573 |
||
3418 | 574 |
"/ mouse still over that view? |
4119 | 575 |
cursorView := device viewFromPoint:pointerPosition. |
3418 | 576 |
cursorView ~~ view ifTrue:[ |
577 |
Debugging ifTrue:[ 'mouse no longer in view' infoPrintCR ]. |
|
578 |
^ self |
|
579 |
]. |
|
580 |
||
4082 | 581 |
(view == currentView and:[lastHelpText = aHelpText]) ifTrue:[ |
582 |
^ self |
|
1536 | 583 |
]. |
4119 | 584 |
|
585 |
pointerPositionAtShowTime := pointerPosition. |
|
3228 | 586 |
lastHelpWidget := view. |
1536 | 587 |
lastHelpText := aHelpText. |
3251
afc7d588b25b
handle key press and close help.
Claus Gittinger <cg@exept.de>
parents:
3248
diff
changeset
|
588 |
helpTextShown := aHelpText. |
4129 | 589 |
|
3257 | 590 |
"/ the text originator must already have generated CRs; |
4114 | 591 |
"/ no longer done here (otherwise, we could not generate tooltips with Windows filenames in it) |
3681 | 592 |
textLines := helpTextShown isStringCollection |
593 |
ifTrue:[helpTextShown] |
|
3767 | 594 |
ifFalse:[ |
595 |
helpTextShown isString |
|
4129 | 596 |
ifTrue:[helpTextShown asCollectionOfLines asStringCollection] |
3767 | 597 |
ifFalse:[nil]]. |
598 |
textLines notNil ifTrue:[ |
|
599 |
textLines size > (self class maxNumberOfLines) ifTrue:[ |
|
600 |
textLines := (textLines copyTo:(self class maxNumberOfLines)) copyWith:'...' |
|
601 |
]. |
|
602 |
textLines := textLines collect:[:l | l contractAtEndTo:(self class maxNumberOfColumns)]. |
|
603 |
helpTextShown := textLines asString. |
|
3251
afc7d588b25b
handle key press and close help.
Claus Gittinger <cg@exept.de>
parents:
3248
diff
changeset
|
604 |
]. |
3767 | 605 |
|
2780 | 606 |
(p := closeProcess) notNil ifTrue:[ |
607 |
closeProcess := nil. |
|
1536 | 608 |
p terminate. |
609 |
]. |
|
610 |
currentHelpView notNil ifTrue:[ |
|
611 |
self hideHelp |
|
612 |
]. |
|
613 |
||
3770 | 614 |
"/ Transcript showCR:helpTextShown storeString. |
3769 | 615 |
helpTextShown isEmptyOrNil ifTrue:[^ self]. |
616 |
||
1536 | 617 |
org := view originRelativeTo:nil. |
618 |
currentFrame := org extent:view extent. |
|
2848 | 619 |
org := org + (view extent // 2). |
1536 | 620 |
|
3248
d72c8e4f7684
more control over the shape style
Claus Gittinger <cg@exept.de>
parents:
3247
diff
changeset
|
621 |
wg notNil ifTrue:[ applicationOrNil := wg application ]. |
3786 | 622 |
v := self activeHelpViewForApplication:applicationOrNil text:helpTextShown onDevice:device. |
3251
afc7d588b25b
handle key press and close help.
Claus Gittinger <cg@exept.de>
parents:
3248
diff
changeset
|
623 |
v perform:#controllingHelpListener: with:self ifNotUnderstood:[]. |
1536 | 624 |
|
2848 | 625 |
helpViewWidth := v width. |
626 |
helpViewHeight := v height. |
|
1677
dc49ab70b762
open helpView on the correcdt device
Claus Gittinger <cg@exept.de>
parents:
1657
diff
changeset
|
627 |
|
4082 | 628 |
"https://expeccoalm.exept.de/D226383: keep the help window away from the pointer under any circumstances |
629 |
(especially when the window touches the bottom or the right edge of the screen). |
|
630 |
When the pointer is no longer in the current window, the help window is closed!!" |
|
631 |
pos := device pointerPosition. |
|
632 |
org := pos + (10@18). |
|
3786 | 633 |
monitorBounds := device monitorBoundsAt:org. |
3114 | 634 |
usableWidth := monitorBounds width - 2. |
3786 | 635 |
usableHeight := device usableHeightAt:org. |
3114 | 636 |
|
637 |
helpViewWidth > usableWidth ifTrue:[v width:(helpViewWidth := usableWidth)]. |
|
3247 | 638 |
helpViewHeight > usableHeight ifTrue:[v height:(helpViewHeight := usableHeight)]. |
3114 | 639 |
|
640 |
(org x + helpViewWidth) > (monitorBounds left + usableWidth) ifTrue:[ |
|
4082 | 641 |
org x:(monitorBounds left + usableWidth - helpViewWidth). |
1536 | 642 |
]. |
3114 | 643 |
(org y + helpViewHeight) > (monitorBounds top + usableHeight) ifTrue:[ |
4082 | 644 |
org y:(monitorBounds top + usableHeight - helpViewHeight). |
1536 | 645 |
]. |
4082 | 646 |
((org extent:v extent) containsPoint:pos) ifTrue:[ |
647 |
"pointer would be in the help window (see comment above). |
|
648 |
Help window is at the lower right edge. Move it to the left of the pointer" |
|
649 |
org x:(pos x - helpViewWidth - 20). |
|
650 |
]. |
|
1536 | 651 |
v origin:org. |
652 |
v realize. |
|
653 |
currentHelpView := v. |
|
2392 | 654 |
currentView := view. |
1536 | 655 |
|
3334 | 656 |
showTime := self showTime. |
4082 | 657 |
(showTime > 0) ifTrue:[ |
3959 | 658 |
p := |
659 |
[ |
|
1546 | 660 |
[ |
4082 | 661 |
Delay waitForSeconds:showTime. |
2392 | 662 |
[ |
2780 | 663 |
|v| |
664 |
(v := currentHelpView) notNil ifTrue:[ |
|
2392 | 665 |
currentHelpView := nil. |
2780 | 666 |
v destroy. |
2392 | 667 |
] |
668 |
] valueUninterruptably |
|
669 |
] ifCurtailed:[ |
|
3959 | 670 |
(p == closeProcess) ifTrue:[ closeProcess := nil ]. |
2392 | 671 |
]. |
672 |
] newProcess. |
|
3959 | 673 |
p priority:(Processor userSchedulingPriority + 1). |
674 |
closeProcess := p. |
|
675 |
p resume. |
|
2392 | 676 |
]. |
1536 | 677 |
|
1963
fb6663696d20
removed withCRs in showHelp:
Claus Gittinger <cg@exept.de>
parents:
1893
diff
changeset
|
678 |
"Modified: / 31-08-1995 / 19:20:45 / claus" |
3959 | 679 |
"Modified: / 06-06-2017 / 15:06:41 / cg" |
4082 | 680 |
"Modified (format): / 16-04-2018 / 17:29:10 / stefan" |
4119 | 681 |
"Modified: / 08-06-2018 / 10:28:32 / Claus Gittinger" |
4129 | 682 |
"Modified (format): / 14-06-2018 / 08:29:43 / Claus Gittinger" |
1536 | 683 |
! |
684 |
||
685 |
stopHelpDisplayProcess |
|
686 |
|p| |
|
687 |
||
2680 | 688 |
(p := showProcess) notNil ifTrue:[ |
689 |
showProcess := nil. |
|
1536 | 690 |
p terminate. |
691 |
]. |
|
692 |
||
693 |
"Created: 28.6.1997 / 14:03:17 / cg" |
|
694 |
! ! |
|
695 |
||
696 |
!FlyByHelp class methodsFor:'documentation'! |
|
697 |
||
2979
306456bdfb61
comment in: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents:
2978
diff
changeset
|
698 |
version |
3656 | 699 |
^ '$Header$' |
2979
306456bdfb61
comment in: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents:
2978
diff
changeset
|
700 |
! |
306456bdfb61
comment in: #keyPress:x:y:view:
Claus Gittinger <cg@exept.de>
parents:
2978
diff
changeset
|
701 |
|
2754 | 702 |
version_CVS |
3656 | 703 |
^ '$Header$' |
1536 | 704 |
! ! |
3114 | 705 |