author | ca |
Wed, 15 Oct 1997 15:39:41 +0200 | |
changeset 334 | 3f632e9711e8 |
parent 331 | aa1663b8c2ab |
child 335 | 9f048ededd7d |
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 |
||
331 | 286 |
cls := self resolveName:aClass. |
196 | 287 |
|
331 | 288 |
(cls notNil and:[cls includesBehavior:UISpecification]) ifTrue:[ |
289 |
^ UISpecificationTool |
|
196 | 290 |
]. |
291 |
^ cls |
|
292 |
||
293 |
! ! |
|
294 |
||
148 | 295 |
!UIHelpTool methodsFor:'accessing'! |
296 |
||
151 | 297 |
dictionary |
298 |
"return the value of the instance variable 'dictionary' (automatically generated)" |
|
299 |
||
300 |
^ dictionary! |
|
301 |
||
302 |
dictionary:aDictionary |
|
303 |
"set the value of the instance variable 'dictionary' (automatically generated)" |
|
304 |
||
286 | 305 |
(dictionary := aDictionary) isNil ifTrue:[ |
204 | 306 |
dictionary := IdentityDictionary new. |
286 | 307 |
]. |
308 |
self updateList |
|
309 |
! |
|
310 |
||
311 |
helpKey |
|
312 |
listSelection size ~~ 0 ifTrue:[ |
|
313 |
^ listSelection asSymbol |
|
151 | 314 |
]. |
286 | 315 |
^ nil |
316 |
! |
|
317 |
||
318 |
helpKey:aKey |
|
319 |
|key| |
|
320 |
||
321 |
aKey size ~~ 0 ifTrue:[ |
|
322 |
key := aKey asString |
|
323 |
]. |
|
324 |
self listModel value:key |
|
151 | 325 |
! |
326 |
||
196 | 327 |
helpSpecFrom:aClass |
328 |
"read help text from an application associated with the class |
|
329 |
" |
|
286 | 330 |
|help| |
331 |
||
332 |
specClass := self class applicationClassAssociatedWith:aClass. |
|
196 | 333 |
|
286 | 334 |
(specClass respondsTo:#helpSpec) ifTrue:[ |
335 |
help := specClass helpSpec |
|
336 |
] ifFalse:[ |
|
337 |
specClass := nil |
|
196 | 338 |
]. |
339 |
self dictionary:help |
|
340 |
! |
|
341 |
||
286 | 342 |
modifiedHolder:aValueHolder |
343 |
"set the value holder set to true in case of modifying attributes |
|
148 | 344 |
" |
286 | 345 |
modifiedHolder notNil ifTrue:[ |
346 |
modifiedHolder removeDependent:self. |
|
347 |
]. |
|
148 | 348 |
|
286 | 349 |
(modifiedHolder := aValueHolder) notNil ifTrue:[ |
350 |
modifiedHolder addDependent:self. |
|
148 | 351 |
]. |
286 | 352 |
|
353 |
||
148 | 354 |
! |
355 |
||
286 | 356 |
updateList |
357 |
"update list from dictionary |
|
148 | 358 |
" |
286 | 359 |
self listChannel value:(dictionary keys asSortedCollection) |
148 | 360 |
! ! |
361 |
||
362 |
!UIHelpTool methodsFor:'actions'! |
|
363 |
||
364 |
accept |
|
365 |
"accept the text |
|
366 |
" |
|
286 | 367 |
|view key txt list| |
148 | 368 |
|
286 | 369 |
(listSelection size == 0 or:[(view := self editTextView) isNil]) ifFalse:[ |
370 |
txt := view contents asString. |
|
371 |
key := listSelection asSymbol. |
|
372 |
list := self listChannel value. |
|
148 | 373 |
|
374 |
(dictionary at:key ifAbsent:nil) isNil ifTrue:[ |
|
375 |
list add:key. |
|
376 |
]. |
|
286 | 377 |
dictionary at:key put:txt |
148 | 378 |
] |
196 | 379 |
! |
380 |
||
381 |
installHelpSpecInto:aClass |
|
382 |
"install help text |
|
383 |
" |
|
384 |
|cls src| |
|
385 |
||
386 |
cls := self class applicationClassAssociatedWith:aClass. |
|
387 |
||
388 |
cls isNil ifTrue:[ |
|
389 |
^ self information:'no application class defined'. |
|
390 |
]. |
|
391 |
dictionary isEmpty ifTrue:[ |
|
392 |
^ self information:'no help text defined' |
|
393 |
]. |
|
394 |
src := '' writeStream. |
|
395 |
||
396 |
src nextPutAll: |
|
397 |
||
398 |
'helpSpec |
|
399 |
"return a dictionary filled with helpKey -> helptext associations. |
|
292 | 400 |
These are used by the activeHelp tool." |
401 |
||
196 | 402 |
" |
292 | 403 |
UIHelpTool openOnClass:', cls name asString ,' |
404 |
" |
|
405 |
||
196 | 406 |
^ super helpSpec addPairsFrom:#( |
407 |
||
408 |
'. |
|
409 |
||
410 |
dictionary keysAndValuesDo:[:key :txt| |
|
411 |
|t| |
|
412 |
src nextPutLine:key storeString. |
|
413 |
||
319
f16aa0e8541e
dont crash with nonexisting bitmaps
Claus Gittinger <cg@exept.de>
parents:
299
diff
changeset
|
414 |
t := txt asString replaceAll:(Character cr) with:(Character space). |
286 | 415 |
|
416 |
(t endsWith:Character space) ifTrue:[ |
|
196 | 417 |
t := t copyWithoutLast:1 |
418 |
]. |
|
419 |
src nextPutLine:t storeString; cr. |
|
420 |
]. |
|
421 |
src nextPutLine:')'. |
|
422 |
||
423 |
Compiler compile:(src contents) |
|
424 |
forClass:cls class |
|
425 |
inCategory:'help specs' |
|
426 |
||
148 | 427 |
! ! |
428 |
||
429 |
!UIHelpTool methodsFor:'aspects'! |
|
430 |
||
431 |
listChannel |
|
432 |
"automatically generated by UIPainter ..." |
|
433 |
||
434 |
|holder| |
|
435 |
||
436 |
(holder := builder bindingAt:#listChannel) isNil ifTrue:[ |
|
437 |
builder aspectAt:#listChannel put:(holder := ValueHolder new). |
|
286 | 438 |
holder value:(OrderedCollection new). |
148 | 439 |
]. |
440 |
^ holder |
|
441 |
! |
|
442 |
||
286 | 443 |
listModel |
148 | 444 |
"automatically generated by UIPainter ..." |
445 |
||
446 |
|holder| |
|
447 |
||
286 | 448 |
(holder := builder bindingAt:#listModel) isNil ifTrue:[ |
449 |
holder := AspectAdaptor new subject:self; forAspect:#listSelection. |
|
450 |
builder aspectAt:#listModel put:holder. |
|
148 | 451 |
]. |
452 |
^ holder |
|
286 | 453 |
! |
148 | 454 |
|
286 | 455 |
selectionListModel |
456 |
"automatically generated by UIPainter ..." |
|
457 |
||
458 |
|holder| |
|
148 | 459 |
|
286 | 460 |
(holder := builder bindingAt:#selectionListModel) isNil ifTrue:[ |
461 |
builder aspectAt:#selectionListModel put:(holder := SelectionInList new). |
|
462 |
holder listHolder:(self listChannel). |
|
463 |
holder selectionIndexHolder:(self listModel). |
|
464 |
]. |
|
465 |
^ holder |
|
148 | 466 |
! ! |
467 |
||
468 |
!UIHelpTool methodsFor:'initialization'! |
|
469 |
||
470 |
initialize |
|
471 |
"setup instance attributes |
|
472 |
" |
|
473 |
super initialize. |
|
286 | 474 |
dictionary := IdentityDictionary new. |
475 |
! ! |
|
476 |
||
477 |
!UIHelpTool methodsFor:'private'! |
|
478 |
||
479 |
editTextView |
|
480 |
"get the editTextView or nil. |
|
481 |
" |
|
482 |
|view| |
|
483 |
||
484 |
(view := builder componentAt:#textView) notNil ifTrue:[ |
|
485 |
view := view scrolledView. |
|
486 |
||
487 |
view acceptAction isNil ifTrue:[ |
|
488 |
view acceptAction:[:aList| self accept ]. |
|
489 |
]. |
|
490 |
||
491 |
view left ~~ 0 ifTrue:[ |
|
492 |
(maxCharsPerLine := view extent x // view font width) < 10 ifTrue:[ |
|
493 |
maxCharsPerLine := nil |
|
494 |
] |
|
495 |
]. |
|
496 |
]. |
|
497 |
^ view |
|
498 |
! ! |
|
499 |
||
500 |
!UIHelpTool methodsFor:'selection'! |
|
501 |
||
502 |
listSelection |
|
503 |
"returns current selection |
|
504 |
" |
|
505 |
^ listSelection |
|
506 |
! |
|
507 |
||
508 |
listSelection:aSelection |
|
509 |
"current selection changed |
|
510 |
" |
|
299 | 511 |
|txt view sel| |
286 | 512 |
|
513 |
aSelection isNumber ifTrue:[ |
|
514 |
aSelection ~~ 0 ifTrue:[ |
|
515 |
sel := self listChannel value at:aSelection |
|
516 |
] |
|
517 |
] ifFalse:[ |
|
518 |
aSelection size ~~ 0 ifTrue:[ |
|
519 |
sel := aSelection withoutSeparators. |
|
520 |
sel size == 0 ifTrue:[ |
|
521 |
sel := nil |
|
522 |
] |
|
523 |
] |
|
524 |
]. |
|
525 |
||
299 | 526 |
listSelection = sel ifFalse:[ |
527 |
listSelection := sel. |
|
286 | 528 |
|
299 | 529 |
modifiedHolder notNil ifTrue:[ |
530 |
modifiedHolder value:true. |
|
531 |
]. |
|
286 | 532 |
|
299 | 533 |
(view := self editTextView) notNil ifTrue:[ |
534 |
listSelection notNil ifTrue:[ |
|
535 |
txt := dictionary at:(listSelection asSymbol) ifAbsent:nil. |
|
286 | 536 |
|
299 | 537 |
(txt isNil or:[maxCharsPerLine isNil]) ifFalse:[ |
538 |
txt := UIPainter convertString:(txt asString) maxLineSize:maxCharsPerLine. |
|
286 | 539 |
] |
540 |
]. |
|
299 | 541 |
view contents:txt. |
542 |
] |
|
543 |
] |
|
286 | 544 |
|
545 |
! ! |
|
546 |
||
547 |
!UIHelpTool methodsFor:'user interactions'! |
|
548 |
||
549 |
doFromClass |
|
550 |
"setup new specification from a class accessed through to a dialog |
|
551 |
" |
|
552 |
|cls accepted| |
|
553 |
||
554 |
specClass notNil ifTrue:[cls := specClass name asValue] |
|
555 |
ifFalse:[cls := '' asValue]. |
|
556 |
||
557 |
[true] whileTrue:[ |
|
558 |
accepted := |
|
559 |
(DialogBox new |
|
560 |
addTextLabel:'Classes name:'; |
|
561 |
addInputFieldOn:cls; |
|
562 |
addAbortButton; |
|
563 |
addOkButton; |
|
564 |
open |
|
565 |
) accepted. |
|
566 |
||
567 |
accepted ifFalse:[^ self]. |
|
568 |
cls := self class applicationClassAssociatedWith:cls value. |
|
569 |
||
570 |
cls notNil ifTrue:[ |
|
571 |
^ self helpSpecFrom:cls |
|
572 |
]. |
|
573 |
self warn:'no such class'. |
|
574 |
] |
|
575 |
! |
|
576 |
||
577 |
doInstallHelpSpec |
|
578 |
"install help spec |
|
579 |
" |
|
580 |
self installHelpSpecInto:specClass |
|
581 |
! |
|
582 |
||
583 |
doReload |
|
584 |
"reload specification |
|
585 |
" |
|
586 |
|oldSel model| |
|
587 |
||
588 |
model := self listModel. |
|
589 |
oldSel := model value. |
|
590 |
model value:nil. |
|
591 |
self helpSpecFrom:specClass. |
|
592 |
model value:oldSel. |
|
148 | 593 |
! ! |
594 |
||
595 |
!UIHelpTool class methodsFor:'documentation'! |
|
596 |
||
597 |
version |
|
598 |
^ '$Header$' |
|
599 |
! ! |