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