author | ca |
Wed, 15 Oct 1997 18:05:19 +0200 | |
changeset 340 | 1de048872d5e |
parent 339 | 121b64d9b39a |
child 354 | a6de8821d3bf |
permissions | -rw-r--r-- |
156 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
||
14 |
||
148 | 15 |
ApplicationModel subclass:#UIHelpTool |
286 | 16 |
instanceVariableNames:'specClass dictionary listSelection maxCharsPerLine modifiedHolder' |
148 | 17 |
classVariableNames:'' |
18 |
poolDictionaries:'' |
|
19 |
category:'Interface-UIPainter' |
|
20 |
! |
|
21 |
||
22 |
!UIHelpTool class methodsFor:'documentation'! |
|
23 |
||
156 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1995 by eXept Software AG |
|
27 |
All Rights Reserved |
|
28 |
||
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
||
37 |
||
38 |
! |
|
39 |
||
148 | 40 |
documentation |
41 |
" |
|
42 |
used by the UIPainter to add help text to any component which will be shown |
|
43 |
during runing an application with enabled activeHelp mode. |
|
156 | 44 |
|
45 |
[author:] |
|
46 |
Claus Atzkern |
|
148 | 47 |
" |
48 |
! ! |
|
49 |
||
286 | 50 |
!UIHelpTool class methodsFor:'instance creation'! |
51 |
||
52 |
openOnClass:aClass |
|
53 |
" |
|
54 |
UIHelpTool openOnClass:UIPainter |
|
55 |
" |
|
56 |
|helpTool| |
|
57 |
||
58 |
helpTool := UIHelpTool new. |
|
59 |
helpTool openInterface:#standAloneSpec. |
|
292 | 60 |
helpTool helpSpecFrom:aClass |
286 | 61 |
|
62 |
||
63 |
! ! |
|
64 |
||
65 |
!UIHelpTool class methodsFor:'constants'! |
|
66 |
||
67 |
label |
|
68 |
^ 'Help' |
|
69 |
! ! |
|
70 |
||
151 | 71 |
!UIHelpTool class methodsFor:'help specs'! |
72 |
||
73 |
helpSpec |
|
74 |
"return a dictionary filled with helpKey -> helptext associations. |
|
292 | 75 |
These are used by the activeHelp tool." |
76 |
||
172 | 77 |
" |
292 | 78 |
UIHelpTool openOnClass:UIHelpTool |
79 |
" |
|
80 |
||
172 | 81 |
^ super helpSpec addPairsFrom:#( |
151 | 82 |
|
172 | 83 |
#activeHelpAccessKey |
286 | 84 |
'This ID is used to access an active help text for the selected component' |
172 | 85 |
|
86 |
) |
|
151 | 87 |
! ! |
88 |
||
148 | 89 |
!UIHelpTool class methodsFor:'interface specs'! |
90 |
||
286 | 91 |
menuPanelStandAlone |
92 |
"this window spec was automatically generated by the ST/X MenuEditor" |
|
93 |
||
94 |
"do not manually edit this - the builder may not be able to |
|
95 |
handle the specification if its corrupted." |
|
96 |
||
97 |
" |
|
98 |
MenuEditor new openOnClass:UIHelpTool andSelector:#menuPanelStandAlone |
|
99 |
(Menu new fromLiteralArrayEncoding:(UIHelpTool menuPanelStandAlone)) startUp |
|
100 |
" |
|
101 |
||
102 |
<resource: #menu> |
|
103 |
||
104 |
^ |
|
105 |
||
106 |
#(#Menu |
|
107 |
||
108 |
#( |
|
109 |
#(#MenuItem |
|
110 |
#'label:' 'file' |
|
111 |
#'submenu:' |
|
112 |
#(#Menu |
|
113 |
||
114 |
#( |
|
115 |
#(#MenuItem |
|
116 |
#'label:' 'reload' |
|
117 |
#'value:' #doReload |
|
118 |
) |
|
119 |
#(#MenuItem |
|
120 |
#'label:' '-' |
|
121 |
) |
|
122 |
#(#MenuItem |
|
292 | 123 |
#'label:' 'quit' |
286 | 124 |
#'value:' #closeRequest |
125 |
) |
|
126 |
) nil |
|
127 |
nil |
|
128 |
) |
|
129 |
) |
|
130 |
#(#MenuItem |
|
131 |
#'label:' 'code' |
|
132 |
#'submenu:' |
|
133 |
#(#Menu |
|
134 |
||
135 |
#( |
|
136 |
#(#MenuItem |
|
137 |
#'label:' 'class' |
|
138 |
#'value:' #doFromClass |
|
139 |
) |
|
140 |
#(#MenuItem |
|
141 |
#'label:' '-' |
|
142 |
) |
|
143 |
#(#MenuItem |
|
144 |
#'label:' 'install help spec.' |
|
145 |
#'value:' #doInstallHelpSpec |
|
146 |
) |
|
147 |
) nil |
|
148 |
nil |
|
149 |
) |
|
150 |
) |
|
151 |
) nil |
|
152 |
nil |
|
153 |
) |
|
154 |
! |
|
155 |
||
156 |
standAloneSpec |
|
157 |
"this window spec was automatically generated by the ST/X UIPainter" |
|
158 |
||
159 |
"do not manually edit this - the painter/builder may not be able to |
|
160 |
handle the specification if its corrupted." |
|
161 |
||
162 |
" |
|
163 |
UIPainter new openOnClass:UIHelpTool andSelector:#standAloneSpec |
|
164 |
UIHelpTool new openInterface:#standAloneSpec |
|
165 |
" |
|
166 |
||
167 |
<resource: #canvas> |
|
168 |
||
169 |
^ |
|
170 |
||
171 |
#(#FullSpec |
|
172 |
#'window:' |
|
173 |
#(#WindowSpec |
|
174 |
#'name:' 'HelpTool' |
|
339 | 175 |
#'layout:' #(#LayoutFrame 136 0 718 0 731 0 1215 0) |
286 | 176 |
#'label:' 'HelpTool' |
177 |
#'min:' #(#Point 10 10) |
|
178 |
#'max:' #(#Point 1160 870) |
|
339 | 179 |
#'bounds:' #(#Rectangle 136 718 732 1216) |
286 | 180 |
) |
181 |
#'component:' |
|
182 |
#(#SpecCollection |
|
183 |
#'collection:' |
|
184 |
#( |
|
185 |
#(#MenuPanelSpec |
|
186 |
#'name:' 'menuPanelStandAlone' |
|
187 |
#'layout:' #(#LayoutFrame 0 0.0 0 0.0 0 1.0 25 0) |
|
188 |
#'menu:' #menuPanelStandAlone |
|
189 |
) |
|
190 |
#(#VariableHorizontalPanelSpec |
|
191 |
#'name:' 'variableHorizontalPanel1' |
|
192 |
#'layout:' #(#LayoutFrame 0 0.0 25 0.0 0 1.0 0 1.0) |
|
193 |
#'component:' |
|
194 |
#(#SpecCollection |
|
195 |
#'collection:' |
|
196 |
#( |
|
197 |
#(#TextEditorSpec |
|
198 |
#'name:' 'textView' |
|
199 |
#'hasHorizontalScrollBar:' true |
|
200 |
#'hasVerticalScrollBar:' true |
|
201 |
#'miniScrollerHorizontal:' true |
|
202 |
#'miniScrollerVertical:' true |
|
203 |
) |
|
204 |
#(#SequenceViewSpec |
|
205 |
#'name:' 'selectionList' |
|
339 | 206 |
#'model:' #listModel |
286 | 207 |
#'hasHorizontalScrollBar:' true |
208 |
#'hasVerticalScrollBar:' true |
|
209 |
#'miniScrollerHorizontal:' true |
|
210 |
#'miniScrollerVertical:' true |
|
339 | 211 |
#'useIndex:' false |
212 |
#'sequenceList:' #listChannel |
|
286 | 213 |
) |
214 |
) |
|
215 |
) |
|
339 | 216 |
#'handles:' #(#Any 0.5 1.0) |
286 | 217 |
) |
218 |
) |
|
219 |
) |
|
220 |
) |
|
221 |
! |
|
222 |
||
148 | 223 |
windowSpec |
224 |
"this window spec was automatically generated by the ST/X UIPainter" |
|
225 |
||
226 |
"do not manually edit this - the painter/builder may not be able to |
|
227 |
handle the specification if its corrupted." |
|
228 |
||
229 |
" |
|
151 | 230 |
UIPainter new openOnClass:UIHelpTool andSelector:#windowSpec |
231 |
UIHelpTool new openInterface:#windowSpec |
|
148 | 232 |
" |
151 | 233 |
"UIHelpTool open" |
148 | 234 |
|
235 |
<resource: #canvas> |
|
236 |
||
237 |
^ |
|
238 |
||
239 |
#(#FullSpec |
|
240 |
#'window:' |
|
241 |
#(#WindowSpec |
|
286 | 242 |
#'name:' 'HelpTool' |
243 |
#'layout:' #(#LayoutFrame 199 0 167 0 484 0 437 0) |
|
148 | 244 |
#'label:' 'unnamed canvas' |
286 | 245 |
#'min:' #(#Point 10 10) |
246 |
#'max:' #(#Point 1160 870) |
|
247 |
#'bounds:' #(#Rectangle 199 167 485 438) |
|
148 | 248 |
) |
249 |
#'component:' |
|
250 |
#(#SpecCollection |
|
251 |
#'collection:' |
|
252 |
#( |
|
286 | 253 |
#(#LabelSpec |
254 |
#'name:' 'keyLabel' |
|
255 |
#'layout:' #(#AlignmentOrigin 3 0.0 42 0.0 0 1) |
|
256 |
#'label:' 'Key:' |
|
257 |
#'adjust:' #left |
|
258 |
#'resizeForLabel:' true |
|
259 |
) |
|
260 |
#(#ComboBoxSpec |
|
261 |
#'name:' 'comboBox' |
|
262 |
#'layout:' #(#LayoutFrame 48 0 22 0 -3 1.0 44 0) |
|
263 |
#'activeHelpKey:' #activeHelpAccessKey |
|
264 |
#'tabable:' true |
|
265 |
#'model:' #listModel |
|
266 |
#'type:' #symbolOrNil |
|
267 |
#'comboList:' #listChannel |
|
268 |
) |
|
148 | 269 |
#(#TextEditorSpec |
270 |
#'name:' 'textView' |
|
286 | 271 |
#'layout:' #(#LayoutFrame 3 0.0 45 0.0 -3 1.0 -3 1.0) |
148 | 272 |
#'hasHorizontalScrollBar:' true |
273 |
#'hasVerticalScrollBar:' true |
|
274 |
#'miniScrollerHorizontal:' true |
|
275 |
#'miniScrollerVertical:' true |
|
276 |
) |
|
277 |
) |
|
278 |
) |
|
279 |
) |
|
280 |
! ! |
|
281 |
||
282 |
!UIHelpTool methodsFor:'accessing'! |
|
283 |
||
151 | 284 |
dictionary |
285 |
"return the value of the instance variable 'dictionary' (automatically generated)" |
|
286 |
||
287 |
^ dictionary! |
|
288 |
||
289 |
dictionary:aDictionary |
|
290 |
"set the value of the instance variable 'dictionary' (automatically generated)" |
|
291 |
||
286 | 292 |
(dictionary := aDictionary) isNil ifTrue:[ |
204 | 293 |
dictionary := IdentityDictionary new. |
286 | 294 |
]. |
295 |
self updateList |
|
296 |
! |
|
297 |
||
298 |
helpKey |
|
299 |
listSelection size ~~ 0 ifTrue:[ |
|
300 |
^ listSelection asSymbol |
|
151 | 301 |
]. |
286 | 302 |
^ nil |
303 |
! |
|
304 |
||
305 |
helpKey:aKey |
|
306 |
|key| |
|
307 |
||
308 |
aKey size ~~ 0 ifTrue:[ |
|
309 |
key := aKey asString |
|
310 |
]. |
|
311 |
self listModel value:key |
|
151 | 312 |
! |
313 |
||
196 | 314 |
helpSpecFrom:aClass |
315 |
"read help text from an application associated with the class |
|
316 |
" |
|
286 | 317 |
|help| |
318 |
||
335 | 319 |
specClass := self applicationClassAssociatedWith:aClass. |
196 | 320 |
|
286 | 321 |
(specClass respondsTo:#helpSpec) ifTrue:[ |
322 |
help := specClass helpSpec |
|
323 |
] ifFalse:[ |
|
324 |
specClass := nil |
|
196 | 325 |
]. |
326 |
self dictionary:help |
|
327 |
! |
|
328 |
||
286 | 329 |
modifiedHolder:aValueHolder |
330 |
"set the value holder set to true in case of modifying attributes |
|
148 | 331 |
" |
286 | 332 |
modifiedHolder notNil ifTrue:[ |
333 |
modifiedHolder removeDependent:self. |
|
334 |
]. |
|
148 | 335 |
|
286 | 336 |
(modifiedHolder := aValueHolder) notNil ifTrue:[ |
337 |
modifiedHolder addDependent:self. |
|
148 | 338 |
]. |
286 | 339 |
|
340 |
||
148 | 341 |
! |
342 |
||
286 | 343 |
updateList |
344 |
"update list from dictionary |
|
148 | 345 |
" |
286 | 346 |
self listChannel value:(dictionary keys asSortedCollection) |
148 | 347 |
! ! |
348 |
||
349 |
!UIHelpTool methodsFor:'actions'! |
|
350 |
||
351 |
accept |
|
352 |
"accept the text |
|
353 |
" |
|
286 | 354 |
|view key txt list| |
148 | 355 |
|
286 | 356 |
(listSelection size == 0 or:[(view := self editTextView) isNil]) ifFalse:[ |
357 |
txt := view contents asString. |
|
358 |
key := listSelection asSymbol. |
|
359 |
list := self listChannel value. |
|
148 | 360 |
|
361 |
(dictionary at:key ifAbsent:nil) isNil ifTrue:[ |
|
362 |
list add:key. |
|
363 |
]. |
|
286 | 364 |
dictionary at:key put:txt |
148 | 365 |
] |
196 | 366 |
! |
367 |
||
368 |
installHelpSpecInto:aClass |
|
369 |
"install help text |
|
370 |
" |
|
371 |
|cls src| |
|
372 |
||
335 | 373 |
cls := self applicationClassAssociatedWith:aClass. |
196 | 374 |
|
375 |
cls isNil ifTrue:[ |
|
376 |
^ self information:'no application class defined'. |
|
377 |
]. |
|
378 |
dictionary isEmpty ifTrue:[ |
|
379 |
^ self information:'no help text defined' |
|
380 |
]. |
|
381 |
src := '' writeStream. |
|
382 |
||
383 |
src nextPutAll: |
|
384 |
||
385 |
'helpSpec |
|
386 |
"return a dictionary filled with helpKey -> helptext associations. |
|
292 | 387 |
These are used by the activeHelp tool." |
388 |
||
196 | 389 |
" |
292 | 390 |
UIHelpTool openOnClass:', cls name asString ,' |
391 |
" |
|
392 |
||
196 | 393 |
^ super helpSpec addPairsFrom:#( |
394 |
||
395 |
'. |
|
396 |
||
397 |
dictionary keysAndValuesDo:[:key :txt| |
|
398 |
|t| |
|
399 |
src nextPutLine:key storeString. |
|
400 |
||
319
f16aa0e8541e
dont crash with nonexisting bitmaps
Claus Gittinger <cg@exept.de>
parents:
299
diff
changeset
|
401 |
t := txt asString replaceAll:(Character cr) with:(Character space). |
286 | 402 |
|
403 |
(t endsWith:Character space) ifTrue:[ |
|
196 | 404 |
t := t copyWithoutLast:1 |
405 |
]. |
|
406 |
src nextPutLine:t storeString; cr. |
|
407 |
]. |
|
408 |
src nextPutLine:')'. |
|
409 |
||
410 |
Compiler compile:(src contents) |
|
411 |
forClass:cls class |
|
412 |
inCategory:'help specs' |
|
413 |
||
148 | 414 |
! ! |
415 |
||
416 |
!UIHelpTool methodsFor:'aspects'! |
|
417 |
||
418 |
listChannel |
|
419 |
"automatically generated by UIPainter ..." |
|
420 |
||
421 |
|holder| |
|
422 |
||
423 |
(holder := builder bindingAt:#listChannel) isNil ifTrue:[ |
|
424 |
builder aspectAt:#listChannel put:(holder := ValueHolder new). |
|
286 | 425 |
holder value:(OrderedCollection new). |
148 | 426 |
]. |
427 |
^ holder |
|
428 |
! |
|
429 |
||
286 | 430 |
listModel |
148 | 431 |
"automatically generated by UIPainter ..." |
432 |
||
433 |
|holder| |
|
434 |
||
286 | 435 |
(holder := builder bindingAt:#listModel) isNil ifTrue:[ |
436 |
holder := AspectAdaptor new subject:self; forAspect:#listSelection. |
|
437 |
builder aspectAt:#listModel put:holder. |
|
148 | 438 |
]. |
439 |
^ holder |
|
440 |
! ! |
|
441 |
||
442 |
!UIHelpTool methodsFor:'initialization'! |
|
443 |
||
444 |
initialize |
|
445 |
"setup instance attributes |
|
446 |
" |
|
447 |
super initialize. |
|
286 | 448 |
dictionary := IdentityDictionary new. |
449 |
! ! |
|
450 |
||
451 |
!UIHelpTool methodsFor:'private'! |
|
452 |
||
453 |
editTextView |
|
454 |
"get the editTextView or nil. |
|
455 |
" |
|
456 |
|view| |
|
457 |
||
458 |
(view := builder componentAt:#textView) notNil ifTrue:[ |
|
459 |
view := view scrolledView. |
|
460 |
||
461 |
view acceptAction isNil ifTrue:[ |
|
462 |
view acceptAction:[:aList| self accept ]. |
|
463 |
]. |
|
464 |
||
465 |
view left ~~ 0 ifTrue:[ |
|
466 |
(maxCharsPerLine := view extent x // view font width) < 10 ifTrue:[ |
|
467 |
maxCharsPerLine := nil |
|
468 |
] |
|
469 |
]. |
|
470 |
]. |
|
471 |
^ view |
|
472 |
! ! |
|
473 |
||
335 | 474 |
!UIHelpTool methodsFor:'queries'! |
475 |
||
476 |
applicationClassAssociatedWith:aClass |
|
477 |
"get application class keeping the associated help text or nil |
|
478 |
" |
|
479 |
|cls| |
|
480 |
||
481 |
cls := self resolveName:aClass. |
|
482 |
||
483 |
(cls notNil and:[cls includesBehavior:UISpecification]) ifTrue:[ |
|
484 |
^ UISpecificationTool |
|
485 |
]. |
|
486 |
^ cls |
|
487 |
||
488 |
||
489 |
! ! |
|
490 |
||
286 | 491 |
!UIHelpTool methodsFor:'selection'! |
492 |
||
493 |
listSelection |
|
494 |
"returns current selection |
|
495 |
" |
|
496 |
^ listSelection |
|
497 |
! |
|
498 |
||
499 |
listSelection:aSelection |
|
500 |
"current selection changed |
|
501 |
" |
|
299 | 502 |
|txt view sel| |
286 | 503 |
|
504 |
aSelection isNumber ifTrue:[ |
|
505 |
aSelection ~~ 0 ifTrue:[ |
|
506 |
sel := self listChannel value at:aSelection |
|
507 |
] |
|
508 |
] ifFalse:[ |
|
509 |
aSelection size ~~ 0 ifTrue:[ |
|
510 |
sel := aSelection withoutSeparators. |
|
511 |
sel size == 0 ifTrue:[ |
|
512 |
sel := nil |
|
513 |
] |
|
514 |
] |
|
515 |
]. |
|
516 |
||
299 | 517 |
listSelection = sel ifFalse:[ |
518 |
listSelection := sel. |
|
286 | 519 |
|
299 | 520 |
modifiedHolder notNil ifTrue:[ |
521 |
modifiedHolder value:true. |
|
522 |
]. |
|
286 | 523 |
|
299 | 524 |
(view := self editTextView) notNil ifTrue:[ |
525 |
listSelection notNil ifTrue:[ |
|
526 |
txt := dictionary at:(listSelection asSymbol) ifAbsent:nil. |
|
286 | 527 |
|
299 | 528 |
(txt isNil or:[maxCharsPerLine isNil]) ifFalse:[ |
529 |
txt := UIPainter convertString:(txt asString) maxLineSize:maxCharsPerLine. |
|
286 | 530 |
] |
531 |
]. |
|
299 | 532 |
view contents:txt. |
533 |
] |
|
534 |
] |
|
286 | 535 |
|
536 |
! ! |
|
537 |
||
538 |
!UIHelpTool methodsFor:'user interactions'! |
|
539 |
||
540 |
doFromClass |
|
541 |
"setup new specification from a class accessed through to a dialog |
|
542 |
" |
|
543 |
|cls accepted| |
|
544 |
||
545 |
specClass notNil ifTrue:[cls := specClass name asValue] |
|
546 |
ifFalse:[cls := '' asValue]. |
|
547 |
||
548 |
[true] whileTrue:[ |
|
549 |
accepted := |
|
550 |
(DialogBox new |
|
551 |
addTextLabel:'Classes name:'; |
|
552 |
addInputFieldOn:cls; |
|
553 |
addAbortButton; |
|
554 |
addOkButton; |
|
555 |
open |
|
556 |
) accepted. |
|
557 |
||
558 |
accepted ifFalse:[^ self]. |
|
335 | 559 |
cls := self applicationClassAssociatedWith:cls value. |
286 | 560 |
|
561 |
cls notNil ifTrue:[ |
|
562 |
^ self helpSpecFrom:cls |
|
563 |
]. |
|
564 |
self warn:'no such class'. |
|
565 |
] |
|
566 |
! |
|
567 |
||
568 |
doInstallHelpSpec |
|
569 |
"install help spec |
|
570 |
" |
|
571 |
self installHelpSpecInto:specClass |
|
572 |
! |
|
573 |
||
574 |
doReload |
|
575 |
"reload specification |
|
576 |
" |
|
577 |
|oldSel model| |
|
578 |
||
579 |
model := self listModel. |
|
580 |
oldSel := model value. |
|
581 |
model value:nil. |
|
582 |
self helpSpecFrom:specClass. |
|
583 |
model value:oldSel. |
|
148 | 584 |
! ! |
585 |
||
586 |
!UIHelpTool class methodsFor:'documentation'! |
|
587 |
||
588 |
version |
|
589 |
^ '$Header$' |
|
590 |
! ! |