author | ca |
Wed, 15 Oct 1997 12:41:27 +0200 | |
changeset 330 | 643ac5544426 |
parent 319 | f16aa0e8541e |
child 331 | aa1663b8c2ab |
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' |
|
175 |
#'layout:' #(#LayoutFrame 199 0 167 0 794 0 664 0) |
|
176 |
#'label:' 'HelpTool' |
|
177 |
#'min:' #(#Point 10 10) |
|
178 |
#'max:' #(#Point 1160 870) |
|
179 |
#'bounds:' #(#Rectangle 199 167 795 665) |
|
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' |
|
206 |
#'model:' #selectionListModel |
|
207 |
#'hasHorizontalScrollBar:' true |
|
208 |
#'hasVerticalScrollBar:' true |
|
209 |
#'miniScrollerHorizontal:' true |
|
210 |
#'miniScrollerVertical:' true |
|
211 |
) |
|
212 |
) |
|
213 |
) |
|
214 |
) |
|
215 |
) |
|
216 |
) |
|
217 |
) |
|
218 |
! |
|
219 |
||
148 | 220 |
windowSpec |
221 |
"this window spec was automatically generated by the ST/X UIPainter" |
|
222 |
||
223 |
"do not manually edit this - the painter/builder may not be able to |
|
224 |
handle the specification if its corrupted." |
|
225 |
||
226 |
" |
|
151 | 227 |
UIPainter new openOnClass:UIHelpTool andSelector:#windowSpec |
228 |
UIHelpTool new openInterface:#windowSpec |
|
148 | 229 |
" |
151 | 230 |
"UIHelpTool open" |
148 | 231 |
|
232 |
<resource: #canvas> |
|
233 |
||
234 |
^ |
|
235 |
||
236 |
#(#FullSpec |
|
237 |
#'window:' |
|
238 |
#(#WindowSpec |
|
286 | 239 |
#'name:' 'HelpTool' |
240 |
#'layout:' #(#LayoutFrame 199 0 167 0 484 0 437 0) |
|
148 | 241 |
#'label:' 'unnamed canvas' |
286 | 242 |
#'min:' #(#Point 10 10) |
243 |
#'max:' #(#Point 1160 870) |
|
244 |
#'bounds:' #(#Rectangle 199 167 485 438) |
|
148 | 245 |
) |
246 |
#'component:' |
|
247 |
#(#SpecCollection |
|
248 |
#'collection:' |
|
249 |
#( |
|
286 | 250 |
#(#LabelSpec |
251 |
#'name:' 'keyLabel' |
|
252 |
#'layout:' #(#AlignmentOrigin 3 0.0 42 0.0 0 1) |
|
253 |
#'label:' 'Key:' |
|
254 |
#'adjust:' #left |
|
255 |
#'resizeForLabel:' true |
|
256 |
) |
|
257 |
#(#ComboBoxSpec |
|
258 |
#'name:' 'comboBox' |
|
259 |
#'layout:' #(#LayoutFrame 48 0 22 0 -3 1.0 44 0) |
|
260 |
#'activeHelpKey:' #activeHelpAccessKey |
|
261 |
#'tabable:' true |
|
262 |
#'model:' #listModel |
|
263 |
#'type:' #symbolOrNil |
|
264 |
#'comboList:' #listChannel |
|
265 |
) |
|
148 | 266 |
#(#TextEditorSpec |
267 |
#'name:' 'textView' |
|
286 | 268 |
#'layout:' #(#LayoutFrame 3 0.0 45 0.0 -3 1.0 -3 1.0) |
148 | 269 |
#'hasHorizontalScrollBar:' true |
270 |
#'hasVerticalScrollBar:' true |
|
271 |
#'miniScrollerHorizontal:' true |
|
272 |
#'miniScrollerVertical:' true |
|
273 |
) |
|
274 |
) |
|
275 |
) |
|
276 |
) |
|
277 |
! ! |
|
278 |
||
196 | 279 |
!UIHelpTool class methodsFor:'misc'! |
280 |
||
281 |
applicationClassAssociatedWith:aClass |
|
282 |
"get application class keeping the associated help text or nil |
|
283 |
" |
|
284 |
|cls| |
|
285 |
||
286 |
aClass notNil ifTrue:[ |
|
287 |
aClass isBehavior ifFalse:[cls := Smalltalk at:aClass asSymbol] |
|
288 |
ifTrue:[cls := aClass]. |
|
289 |
||
290 |
(cls notNil and:[cls includesBehavior:UISpecification]) ifTrue:[ |
|
291 |
^ UISpecificationTool |
|
292 |
] |
|
293 |
]. |
|
294 |
^ cls |
|
295 |
||
296 |
! ! |
|
297 |
||
148 | 298 |
!UIHelpTool methodsFor:'accessing'! |
299 |
||
151 | 300 |
dictionary |
301 |
"return the value of the instance variable 'dictionary' (automatically generated)" |
|
302 |
||
303 |
^ dictionary! |
|
304 |
||
305 |
dictionary:aDictionary |
|
306 |
"set the value of the instance variable 'dictionary' (automatically generated)" |
|
307 |
||
286 | 308 |
(dictionary := aDictionary) isNil ifTrue:[ |
204 | 309 |
dictionary := IdentityDictionary new. |
286 | 310 |
]. |
311 |
self updateList |
|
312 |
! |
|
313 |
||
314 |
helpKey |
|
315 |
listSelection size ~~ 0 ifTrue:[ |
|
316 |
^ listSelection asSymbol |
|
151 | 317 |
]. |
286 | 318 |
^ nil |
319 |
! |
|
320 |
||
321 |
helpKey:aKey |
|
322 |
|key| |
|
323 |
||
324 |
aKey size ~~ 0 ifTrue:[ |
|
325 |
key := aKey asString |
|
326 |
]. |
|
327 |
self listModel value:key |
|
151 | 328 |
! |
329 |
||
196 | 330 |
helpSpecFrom:aClass |
331 |
"read help text from an application associated with the class |
|
332 |
" |
|
286 | 333 |
|help| |
334 |
||
335 |
specClass := self class applicationClassAssociatedWith:aClass. |
|
196 | 336 |
|
286 | 337 |
(specClass respondsTo:#helpSpec) ifTrue:[ |
338 |
help := specClass helpSpec |
|
339 |
] ifFalse:[ |
|
340 |
specClass := nil |
|
196 | 341 |
]. |
342 |
self dictionary:help |
|
343 |
! |
|
344 |
||
286 | 345 |
modifiedHolder:aValueHolder |
346 |
"set the value holder set to true in case of modifying attributes |
|
148 | 347 |
" |
286 | 348 |
modifiedHolder notNil ifTrue:[ |
349 |
modifiedHolder removeDependent:self. |
|
350 |
]. |
|
148 | 351 |
|
286 | 352 |
(modifiedHolder := aValueHolder) notNil ifTrue:[ |
353 |
modifiedHolder addDependent:self. |
|
148 | 354 |
]. |
286 | 355 |
|
356 |
||
148 | 357 |
! |
358 |
||
286 | 359 |
updateList |
360 |
"update list from dictionary |
|
148 | 361 |
" |
286 | 362 |
self listChannel value:(dictionary keys asSortedCollection) |
148 | 363 |
! ! |
364 |
||
365 |
!UIHelpTool methodsFor:'actions'! |
|
366 |
||
367 |
accept |
|
368 |
"accept the text |
|
369 |
" |
|
286 | 370 |
|view key txt list| |
148 | 371 |
|
286 | 372 |
(listSelection size == 0 or:[(view := self editTextView) isNil]) ifFalse:[ |
373 |
txt := view contents asString. |
|
374 |
key := listSelection asSymbol. |
|
375 |
list := self listChannel value. |
|
148 | 376 |
|
377 |
(dictionary at:key ifAbsent:nil) isNil ifTrue:[ |
|
378 |
list add:key. |
|
379 |
]. |
|
286 | 380 |
dictionary at:key put:txt |
148 | 381 |
] |
196 | 382 |
! |
383 |
||
384 |
installHelpSpecInto:aClass |
|
385 |
"install help text |
|
386 |
" |
|
387 |
|cls src| |
|
388 |
||
389 |
cls := self class applicationClassAssociatedWith:aClass. |
|
390 |
||
391 |
cls isNil ifTrue:[ |
|
392 |
^ self information:'no application class defined'. |
|
393 |
]. |
|
394 |
dictionary isEmpty ifTrue:[ |
|
395 |
^ self information:'no help text defined' |
|
396 |
]. |
|
397 |
src := '' writeStream. |
|
398 |
||
399 |
src nextPutAll: |
|
400 |
||
401 |
'helpSpec |
|
402 |
"return a dictionary filled with helpKey -> helptext associations. |
|
292 | 403 |
These are used by the activeHelp tool." |
404 |
||
196 | 405 |
" |
292 | 406 |
UIHelpTool openOnClass:', cls name asString ,' |
407 |
" |
|
408 |
||
196 | 409 |
^ super helpSpec addPairsFrom:#( |
410 |
||
411 |
'. |
|
412 |
||
413 |
dictionary keysAndValuesDo:[:key :txt| |
|
414 |
|t| |
|
415 |
src nextPutLine:key storeString. |
|
416 |
||
319
f16aa0e8541e
dont crash with nonexisting bitmaps
Claus Gittinger <cg@exept.de>
parents:
299
diff
changeset
|
417 |
t := txt asString replaceAll:(Character cr) with:(Character space). |
286 | 418 |
|
419 |
(t endsWith:Character space) ifTrue:[ |
|
196 | 420 |
t := t copyWithoutLast:1 |
421 |
]. |
|
422 |
src nextPutLine:t storeString; cr. |
|
423 |
]. |
|
424 |
src nextPutLine:')'. |
|
425 |
||
426 |
Compiler compile:(src contents) |
|
427 |
forClass:cls class |
|
428 |
inCategory:'help specs' |
|
429 |
||
148 | 430 |
! ! |
431 |
||
432 |
!UIHelpTool methodsFor:'aspects'! |
|
433 |
||
434 |
listChannel |
|
435 |
"automatically generated by UIPainter ..." |
|
436 |
||
437 |
|holder| |
|
438 |
||
439 |
(holder := builder bindingAt:#listChannel) isNil ifTrue:[ |
|
440 |
builder aspectAt:#listChannel put:(holder := ValueHolder new). |
|
286 | 441 |
holder value:(OrderedCollection new). |
148 | 442 |
]. |
443 |
^ holder |
|
444 |
! |
|
445 |
||
286 | 446 |
listModel |
148 | 447 |
"automatically generated by UIPainter ..." |
448 |
||
449 |
|holder| |
|
450 |
||
286 | 451 |
(holder := builder bindingAt:#listModel) isNil ifTrue:[ |
452 |
holder := AspectAdaptor new subject:self; forAspect:#listSelection. |
|
453 |
builder aspectAt:#listModel put:holder. |
|
148 | 454 |
]. |
455 |
^ holder |
|
286 | 456 |
! |
148 | 457 |
|
286 | 458 |
selectionListModel |
459 |
"automatically generated by UIPainter ..." |
|
460 |
||
461 |
|holder| |
|
148 | 462 |
|
286 | 463 |
(holder := builder bindingAt:#selectionListModel) isNil ifTrue:[ |
464 |
builder aspectAt:#selectionListModel put:(holder := SelectionInList new). |
|
465 |
holder listHolder:(self listChannel). |
|
466 |
holder selectionIndexHolder:(self listModel). |
|
467 |
]. |
|
468 |
^ holder |
|
148 | 469 |
! ! |
470 |
||
471 |
!UIHelpTool methodsFor:'initialization'! |
|
472 |
||
473 |
initialize |
|
474 |
"setup instance attributes |
|
475 |
" |
|
476 |
super initialize. |
|
286 | 477 |
dictionary := IdentityDictionary new. |
478 |
! ! |
|
479 |
||
480 |
!UIHelpTool methodsFor:'private'! |
|
481 |
||
482 |
editTextView |
|
483 |
"get the editTextView or nil. |
|
484 |
" |
|
485 |
|view| |
|
486 |
||
487 |
(view := builder componentAt:#textView) notNil ifTrue:[ |
|
488 |
view := view scrolledView. |
|
489 |
||
490 |
view acceptAction isNil ifTrue:[ |
|
491 |
view acceptAction:[:aList| self accept ]. |
|
492 |
]. |
|
493 |
||
494 |
view left ~~ 0 ifTrue:[ |
|
495 |
(maxCharsPerLine := view extent x // view font width) < 10 ifTrue:[ |
|
496 |
maxCharsPerLine := nil |
|
497 |
] |
|
498 |
]. |
|
499 |
]. |
|
500 |
^ view |
|
501 |
! ! |
|
502 |
||
503 |
!UIHelpTool methodsFor:'selection'! |
|
504 |
||
505 |
listSelection |
|
506 |
"returns current selection |
|
507 |
" |
|
508 |
^ listSelection |
|
509 |
! |
|
510 |
||
511 |
listSelection:aSelection |
|
512 |
"current selection changed |
|
513 |
" |
|
299 | 514 |
|txt view sel| |
286 | 515 |
|
516 |
aSelection isNumber ifTrue:[ |
|
517 |
aSelection ~~ 0 ifTrue:[ |
|
518 |
sel := self listChannel value at:aSelection |
|
519 |
] |
|
520 |
] ifFalse:[ |
|
521 |
aSelection size ~~ 0 ifTrue:[ |
|
522 |
sel := aSelection withoutSeparators. |
|
523 |
sel size == 0 ifTrue:[ |
|
524 |
sel := nil |
|
525 |
] |
|
526 |
] |
|
527 |
]. |
|
528 |
||
299 | 529 |
listSelection = sel ifFalse:[ |
530 |
listSelection := sel. |
|
286 | 531 |
|
299 | 532 |
modifiedHolder notNil ifTrue:[ |
533 |
modifiedHolder value:true. |
|
534 |
]. |
|
286 | 535 |
|
299 | 536 |
(view := self editTextView) notNil ifTrue:[ |
537 |
listSelection notNil ifTrue:[ |
|
538 |
txt := dictionary at:(listSelection asSymbol) ifAbsent:nil. |
|
286 | 539 |
|
299 | 540 |
(txt isNil or:[maxCharsPerLine isNil]) ifFalse:[ |
541 |
txt := UIPainter convertString:(txt asString) maxLineSize:maxCharsPerLine. |
|
286 | 542 |
] |
543 |
]. |
|
299 | 544 |
view contents:txt. |
545 |
] |
|
546 |
] |
|
286 | 547 |
|
548 |
! ! |
|
549 |
||
550 |
!UIHelpTool methodsFor:'user interactions'! |
|
551 |
||
552 |
doFromClass |
|
553 |
"setup new specification from a class accessed through to a dialog |
|
554 |
" |
|
555 |
|cls accepted| |
|
556 |
||
557 |
specClass notNil ifTrue:[cls := specClass name asValue] |
|
558 |
ifFalse:[cls := '' asValue]. |
|
559 |
||
560 |
[true] whileTrue:[ |
|
561 |
accepted := |
|
562 |
(DialogBox new |
|
563 |
addTextLabel:'Classes name:'; |
|
564 |
addInputFieldOn:cls; |
|
565 |
addAbortButton; |
|
566 |
addOkButton; |
|
567 |
open |
|
568 |
) accepted. |
|
569 |
||
570 |
accepted ifFalse:[^ self]. |
|
571 |
cls := self class applicationClassAssociatedWith:cls value. |
|
572 |
||
573 |
cls notNil ifTrue:[ |
|
574 |
^ self helpSpecFrom:cls |
|
575 |
]. |
|
576 |
self warn:'no such class'. |
|
577 |
] |
|
578 |
! |
|
579 |
||
580 |
doInstallHelpSpec |
|
581 |
"install help spec |
|
582 |
" |
|
583 |
self installHelpSpecInto:specClass |
|
584 |
! |
|
585 |
||
586 |
doReload |
|
587 |
"reload specification |
|
588 |
" |
|
589 |
|oldSel model| |
|
590 |
||
591 |
model := self listModel. |
|
592 |
oldSel := model value. |
|
593 |
model value:nil. |
|
594 |
self helpSpecFrom:specClass. |
|
595 |
model value:oldSel. |
|
148 | 596 |
! ! |
597 |
||
598 |
!UIHelpTool class methodsFor:'documentation'! |
|
599 |
||
600 |
version |
|
601 |
^ '$Header$' |
|
602 |
! ! |