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