author | claus |
Mon, 10 Oct 1994 04:03:47 +0100 | |
changeset 59 | 450ce95a72a4 |
parent 52 | e69fade0aa8e |
child 60 | f3c738c24ce6 |
permissions | -rw-r--r-- |
0 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
59 | 3 |
All Rights Reserved |
0 | 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 |
EditTextView subclass:#TextCollector |
|
14 |
instanceVariableNames:'entryStream lineLimit destroyAction |
|
59 | 15 |
outstandingLines outstandingLine |
16 |
flushBlock flushPending collecting timeDelay access' |
|
0 | 17 |
classVariableNames:'' |
18 |
poolDictionaries:'' |
|
19 |
category:'Views-Text' |
|
20 |
! |
|
21 |
||
22 |
TextCollector comment:' |
|
5 | 23 |
COPYRIGHT (c) 1989 by Claus Gittinger |
59 | 24 |
All Rights Reserved |
0 | 25 |
|
59 | 26 |
$Header: /cvs/stx/stx/libwidg/Attic/TextColl.st,v 1.10 1994-10-10 03:03:08 claus Exp $ |
15 | 27 |
'! |
28 |
||
29 |
!TextCollector class methodsFor:'documentation'! |
|
30 |
||
34
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
31 |
copyright |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
32 |
" |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
33 |
COPYRIGHT (c) 1989 by Claus Gittinger |
59 | 34 |
All Rights Reserved |
34
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
35 |
|
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
36 |
This software is furnished under a license and may be used |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
37 |
only in accordance with the terms of that license and with the |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
38 |
inclusion of the above copyright notice. This software may not |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
39 |
be provided or otherwise made available to, or used by, any |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
40 |
other person. No title to or ownership of the software is |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
41 |
hereby transferred. |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
42 |
" |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
43 |
! |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
44 |
|
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
45 |
version |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
46 |
" |
59 | 47 |
$Header: /cvs/stx/stx/libwidg/Attic/TextColl.st,v 1.10 1994-10-10 03:03:08 claus Exp $ |
34
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
48 |
" |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
49 |
! |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
50 |
|
15 | 51 |
documentation |
52 |
" |
|
34
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
53 |
a view for editable text, which also understands some stream messages. |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
54 |
Instances of this view can take the place of a stream and display the |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
55 |
received text. |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
56 |
Its main use in the system is the Transcript, but it can also be used for |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
57 |
things like trace-windows etc. |
0 | 58 |
|
34
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
59 |
If collecting is turned on, a Textcollector will not immediately display |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
60 |
entered text, but wait for some short time (timeDelay) and collect incoming |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
61 |
data - finally updating the whole chunk in one piece. |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
62 |
This helps slow display devices, which would otherwise scroll a lot. |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
63 |
(on fast displays this is less of a problem). |
15 | 64 |
|
34
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
65 |
The total number of lines kept is controlled by lineLimit, if more lines are |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
66 |
entered at the bottom, the textcollector will forget lines at the top. |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
67 |
Linelimit can also be set to nil (i.e. no limit), but you may need a lot |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
68 |
of memory then ... |
15 | 69 |
" |
70 |
! ! |
|
0 | 71 |
|
72 |
!TextCollector class methodsFor:'defaults'! |
|
73 |
||
74 |
defaultLineLimit |
|
15 | 75 |
"the number of lines remembered by default" |
76 |
||
77 |
^ 600 |
|
78 |
! |
|
79 |
||
80 |
defaultTimeDelay |
|
81 |
"the time in seconds to wait & collect by default" |
|
82 |
||
34
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
83 |
^ 0.3 |
0 | 84 |
! ! |
85 |
||
86 |
!TextCollector class methodsFor:'instance creation'! |
|
87 |
||
88 |
newTranscript |
|
59 | 89 |
|topView transcript f v fg bg cFg cBg| |
0 | 90 |
|
7 | 91 |
topView := StandardSystemView label:'Transcript' minExtent:(100 @ 100). |
34
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
92 |
topView icon:(Form fromFile:'SmalltalkX.xbm'). |
0 | 93 |
|
94 |
v := ScrollableView for:self in:topView. |
|
95 |
v origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
96 |
transcript := v scrolledView. |
|
97 |
"transcript partialLines:false." |
|
98 |
||
99 |
f := transcript font. |
|
100 |
topView extent:(((f widthOf:'x') * 70) @ (f height * 10)). |
|
101 |
||
102 |
Smalltalk at:#Transcript put:transcript. |
|
103 |
||
104 |
"fancy feature: whenever Transcript is closed, reset to StdError" |
|
105 |
transcript destroyAction:[Smalltalk at:#Transcript put:Stderr]. |
|
106 |
||
59 | 107 |
fg := StyleSheet at:'transcriptForegroundColor' default:transcript foregroundColor. |
108 |
bg := StyleSheet at:'transcriptBackgroundColor' default:transcript backgroundColor. |
|
109 |
transcript foregroundColor:fg backgroundColor:bg. |
|
110 |
||
111 |
cFg := StyleSheet at:'transcriptCursorForegroundColor' default:bg. |
|
112 |
cBg := StyleSheet at:'transcriptCursorBackgroundColor' default:fg. |
|
113 |
transcript cursorForegroundColor:cFg backgroundColor:cBg. |
|
114 |
||
22 | 115 |
topView open. |
15 | 116 |
"transcript lineLimit:1000. " "or whatever you think makes sense" |
117 |
||
0 | 118 |
^ transcript |
119 |
! ! |
|
120 |
||
121 |
!TextCollector methodsFor:'initialize / release'! |
|
122 |
||
123 |
initialize |
|
124 |
super initialize. |
|
125 |
||
126 |
outstandingLines := OrderedCollection new. |
|
34
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
127 |
|
0 | 128 |
flushBlock := [self endEntry]. |
129 |
flushPending := false. |
|
15 | 130 |
collecting := true. |
131 |
timeDelay := self class defaultTimeDelay. |
|
34
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
132 |
access := Semaphore forMutualExclusion. |
0 | 133 |
|
134 |
lineLimit := self class defaultLineLimit. |
|
135 |
entryStream := ActorStream new. |
|
136 |
entryStream nextPutBlock:[:something | self nextPut:something]. |
|
137 |
entryStream nextPutAllBlock:[:something | self nextPutAll:something] |
|
138 |
! |
|
139 |
||
59 | 140 |
initializeMiddleButtonMenu |
141 |
|idx| |
|
142 |
||
143 |
super initializeMiddleButtonMenu. |
|
144 |
||
145 |
" |
|
146 |
textcollectors do not support #accept |
|
147 |
remove it from the menu (and the preceeding separating line) |
|
148 |
" |
|
149 |
idx := middleButtonMenu indexOf:#accept. |
|
150 |
idx ~~ 0 ifTrue:[ |
|
151 |
middleButtonMenu remove:idx. |
|
152 |
(middleButtonMenu labels at:(idx - 1)) = '-' ifTrue:[ |
|
153 |
middleButtonMenu remove:idx - 1 |
|
154 |
]. |
|
155 |
]. |
|
156 |
! |
|
157 |
||
36 | 158 |
reinitialize |
159 |
"recreate access-semaphore; image could have been save (theoretically) |
|
160 |
with the semaphore locked - int this case, we had a deadlock" |
|
161 |
||
162 |
flushPending := false. |
|
163 |
access := Semaphore forMutualExclusion. |
|
164 |
super reinitialize. |
|
165 |
! |
|
166 |
||
34
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
167 |
mapped |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
168 |
"view became visible - show collected lines (if any)" |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
169 |
|
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
170 |
super mapped. |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
171 |
self endEntry |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
172 |
! |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
173 |
|
0 | 174 |
destroy |
175 |
destroyAction notNil ifTrue:[ |
|
59 | 176 |
destroyAction value |
0 | 177 |
]. |
34
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
178 |
Processor removeTimedBlock:flushBlock. |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
179 |
flushBlock := nil. |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
180 |
outstandingLines := OrderedCollection new. |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
181 |
outstandingLine := ''. |
0 | 182 |
super destroy |
183 |
! ! |
|
184 |
||
185 |
!TextCollector methodsFor:'accessing'! |
|
186 |
||
187 |
collect:aBoolean |
|
34
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
188 |
"turn on/off collecting - if on, do not output immediately |
15 | 189 |
but collect text and output en-bloque after some time delta" |
0 | 190 |
|
191 |
collecting := aBoolean |
|
192 |
! |
|
193 |
||
194 |
lineLimit:aNumber |
|
195 |
"define the number of text-lines I am supposed to hold" |
|
196 |
||
197 |
lineLimit := aNumber |
|
198 |
! |
|
199 |
||
200 |
destroyAction:aBlock |
|
34
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
201 |
"define the action to be performed when I get destroyed. |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
202 |
This is a special feature, to allow resetting Transcript to Stderr |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
203 |
when closed. (see TextCollectorclass>>newTranscript)" |
0 | 204 |
|
205 |
destroyAction := aBlock |
|
206 |
! |
|
207 |
||
208 |
endEntry |
|
209 |
"flush collected output" |
|
210 |
||
36 | 211 |
|nLines lines| |
0 | 212 |
|
34
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
213 |
shown ifFalse:[^ self]. |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
214 |
|
15 | 215 |
Processor removeTimedBlock:flushBlock. |
59 | 216 |
flushPending ifFalse:[^ self]. |
15 | 217 |
|
52 | 218 |
access critical:[ |
59 | 219 |
flushPending := false. |
220 |
outstandingLines size ~~ 0 ifTrue:[ |
|
221 |
"insert the bunch of lines - if any" |
|
222 |
lines := outstandingLines. |
|
223 |
outstandingLines := OrderedCollection new. |
|
36 | 224 |
|
59 | 225 |
nLines := lines size. |
226 |
(nLines ~~ 0) ifTrue:[ |
|
227 |
self insertLines:lines withCr:true. |
|
228 |
self withCursorOffDo:[ |
|
229 |
(cursorLine >= (firstLineShown + nFullLinesShown)) ifTrue:[ |
|
230 |
self scrollDown:nLines |
|
231 |
] |
|
232 |
]. |
|
233 |
]. |
|
234 |
]. |
|
235 |
"and the last partial line - if any" |
|
236 |
outstandingLine notNil ifTrue:[ |
|
237 |
self insertStringAtCursor:outstandingLine. |
|
238 |
outstandingLine := ''. |
|
239 |
]. |
|
240 |
self checkLineLimit |
|
34
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
241 |
] |
0 | 242 |
! ! |
243 |
||
244 |
!TextCollector methodsFor:'private'! |
|
245 |
||
246 |
checkLineLimit |
|
247 |
"this method checks if the text has become too large (> lineLimit) |
|
248 |
and cuts off some lines at the top if so; it must be called whenever lines |
|
249 |
have been added to the bottom" |
|
250 |
||
251 |
|nDel| |
|
252 |
||
253 |
lineLimit notNil ifTrue:[ |
|
59 | 254 |
(cursorLine > lineLimit) ifTrue:[ |
255 |
nDel := list size - lineLimit. |
|
256 |
list removeFromIndex:1 toIndex:nDel. |
|
257 |
cursorLine := cursorLine - nDel. |
|
258 |
firstLineShown := firstLineShown - nDel. |
|
259 |
(firstLineShown < 1) ifTrue:[ |
|
260 |
cursorLine := cursorLine - firstLineShown + 1. |
|
261 |
firstLineShown := 1 |
|
262 |
]. |
|
263 |
self contentsChanged |
|
264 |
] |
|
0 | 265 |
] |
34
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
266 |
! |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
267 |
|
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
268 |
installDelayedUpdate |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
269 |
"arrange for collecting input for some time, |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
270 |
and output all buffered strings at once after a while. |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
271 |
This makes output to the transcript much faster on systems |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
272 |
with poor scrolling performance (i.e. dump vga cards ...)." |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
273 |
|
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
274 |
|wg p| |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
275 |
|
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
276 |
flushPending ifFalse:[ |
59 | 277 |
flushPending := true. |
278 |
" |
|
279 |
we could run under a process, which dies in the meantime; |
|
280 |
therefore, we have to arrange for the transcript process to |
|
281 |
be interrupted and do the update. |
|
282 |
" |
|
283 |
wg := self windowGroup. |
|
284 |
wg isNil ifTrue:[ |
|
285 |
p := Processor activeProcess |
|
286 |
] ifFalse:[ |
|
287 |
p := wg process |
|
288 |
]. |
|
289 |
Processor addTimedBlock:flushBlock for:p afterSeconds:timeDelay. |
|
34
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
290 |
] |
0 | 291 |
! ! |
292 |
||
293 |
!TextCollector methodsFor:'stream messages'! |
|
294 |
||
295 |
lineLength |
|
296 |
^ width // (font width) |
|
297 |
! |
|
298 |
||
299 |
nextPut:something |
|
300 |
"this allows TextCollectors to be used Stream-wise" |
|
301 |
||
302 |
flushPending ifTrue:[ |
|
59 | 303 |
self endEntry |
0 | 304 |
]. |
305 |
(something isMemberOf:Character) ifTrue:[ |
|
59 | 306 |
((something == Character cr) or:[something == Character nl]) ifTrue:[ |
307 |
^ self cr |
|
308 |
]. |
|
309 |
self insertCharAtCursor:something |
|
0 | 310 |
] ifFalse:[ |
59 | 311 |
self insertStringAtCursor:(something printString). |
312 |
self checkLineLimit |
|
0 | 313 |
]. |
314 |
device synchronizeOutput |
|
315 |
! |
|
316 |
||
317 |
nextPutAll:something |
|
318 |
"this allows TextCollectors to be used Stream-wise" |
|
319 |
||
320 |
^ self nextPut:something |
|
321 |
! |
|
322 |
||
323 |
cr |
|
15 | 324 |
"output a carriage return, finishing the current line" |
325 |
||
34
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
326 |
|wasBlocked| |
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
327 |
|
0 | 328 |
collecting ifTrue:[ |
59 | 329 |
access critical:[ |
330 |
outstandingLine notNil ifTrue:[ |
|
331 |
outstandingLines add:outstandingLine. |
|
332 |
]. |
|
333 |
outstandingLine := ''. |
|
334 |
]. |
|
335 |
flushPending ifFalse:[ |
|
336 |
self installDelayedUpdate |
|
337 |
] |
|
0 | 338 |
] ifFalse:[ |
59 | 339 |
access critical:[ |
340 |
self cursorReturn. |
|
341 |
self checkLineLimit. |
|
342 |
]. |
|
0 | 343 |
] |
344 |
! |
|
345 |
||
346 |
show:anObject |
|
347 |
"insert the argument aString at current cursor position" |
|
348 |
||
34
c4b386a8cc57
critical-lock; allows show:/showCr: from multiple processes
claus
parents:
22
diff
changeset
|
349 |
|aString wasBlocked| |
0 | 350 |
|
351 |
aString := anObject printString. |
|
352 |
collecting ifTrue:[ |
|
59 | 353 |
access critical:[ |
354 |
outstandingLine notNil ifTrue:[ |
|
355 |
outstandingLine := outstandingLine , aString |
|
356 |
] ifFalse:[ |
|
357 |
outstandingLine := aString |
|
358 |
]. |
|
359 |
]. |
|
360 |
flushPending ifFalse:[ |
|
361 |
self installDelayedUpdate |
|
362 |
] |
|
0 | 363 |
] ifFalse:[ |
59 | 364 |
access critical:[ |
365 |
self nextPut:aString. |
|
366 |
]. |
|
0 | 367 |
] |
368 |
! |
|
369 |
||
370 |
showCr:aString |
|
371 |
"insert the argument aString followed by a newline |
|
372 |
at current cursor position" |
|
373 |
||
374 |
self show:aString. |
|
375 |
self cr |
|
376 |
! |
|
377 |
||
378 |
doesNotUnderstand:aMessage |
|
379 |
"this is funny: all message we do not understand, are passed |
|
380 |
on to the stream which will send the characters via nextPut: |
|
381 |
This way, we understand all Stream messages - great isn't it !! |
|
382 |
" |
|
15 | 383 |
^ entryStream perform:(aMessage selector) withArguments:(aMessage arguments) |
0 | 384 |
! ! |