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