0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
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 |
EditTextView subclass:#TextCollector
|
|
14 |
instanceVariableNames:'entryStream lineLimit destroyAction
|
|
15 |
outstandingLines outstandingLine
|
|
16 |
flushBlock flushPending collecting'
|
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Views-Text'
|
|
20 |
!
|
|
21 |
|
|
22 |
TextCollector comment:'
|
|
23 |
|
5
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
25 |
All Rights Reserved
|
|
26 |
|
|
27 |
a view for editable text, which also understands some stream messages.
|
|
28 |
Instances of this view can take the place of a stream and display the received
|
|
29 |
text; it is used especially for Transcript.
|
|
30 |
|
7
|
31 |
$Header: /cvs/stx/stx/libwidg/TextCollector.st,v 1.4 1993-12-11 01:49:53 claus Exp $
|
0
|
32 |
written winter-89 by claus
|
|
33 |
'!
|
|
34 |
|
|
35 |
!TextCollector class methodsFor:'defaults'!
|
|
36 |
|
|
37 |
defaultLineLimit
|
|
38 |
^ nil
|
|
39 |
! !
|
|
40 |
|
|
41 |
!TextCollector class methodsFor:'instance creation'!
|
|
42 |
|
|
43 |
newTranscript
|
|
44 |
|topView transcript f v|
|
|
45 |
|
|
46 |
Display initialize.
|
7
|
47 |
topView := StandardSystemView label:'Transcript' minExtent:(100 @ 100).
|
0
|
48 |
|
|
49 |
v := ScrollableView for:self in:topView.
|
|
50 |
v origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
|
|
51 |
transcript := v scrolledView.
|
|
52 |
transcript lineLimit:600.
|
|
53 |
transcript collect:true.
|
|
54 |
"transcript partialLines:false."
|
|
55 |
|
|
56 |
f := transcript font.
|
|
57 |
topView extent:(((f widthOf:'x') * 70) @ (f height * 10)).
|
|
58 |
|
|
59 |
Smalltalk at:#Transcript put:transcript.
|
|
60 |
|
|
61 |
"fancy feature: whenever Transcript is closed, reset to StdError"
|
|
62 |
transcript destroyAction:[Smalltalk at:#Transcript put:Stderr].
|
|
63 |
|
|
64 |
topView realize.
|
|
65 |
^ transcript
|
|
66 |
! !
|
|
67 |
|
|
68 |
!TextCollector methodsFor:'initialize / release'!
|
|
69 |
|
|
70 |
initialize
|
|
71 |
super initialize.
|
|
72 |
|
|
73 |
outstandingLines := OrderedCollection new.
|
|
74 |
flushBlock := [self endEntry].
|
|
75 |
flushPending := false.
|
|
76 |
collecting := false.
|
|
77 |
|
|
78 |
lineLimit := self class defaultLineLimit.
|
|
79 |
entryStream := ActorStream new.
|
|
80 |
entryStream nextPutBlock:[:something | self nextPut:something].
|
|
81 |
entryStream nextPutAllBlock:[:something | self nextPutAll:something]
|
|
82 |
!
|
|
83 |
|
|
84 |
destroy
|
|
85 |
destroyAction notNil ifTrue:[
|
|
86 |
destroyAction value
|
|
87 |
].
|
|
88 |
flushBlock notNil ifTrue:[
|
7
|
89 |
Processor removeTimedBlock:flushBlock
|
0
|
90 |
].
|
|
91 |
super destroy
|
|
92 |
! !
|
|
93 |
|
|
94 |
!TextCollector methodsFor:'accessing'!
|
|
95 |
|
|
96 |
collect:aBoolean
|
|
97 |
"turn on collecting - i.e. do not output immediately
|
|
98 |
but collect text and output en-bloque after some time
|
|
99 |
delta"
|
|
100 |
|
|
101 |
collecting := aBoolean
|
|
102 |
!
|
|
103 |
|
|
104 |
lineLimit:aNumber
|
|
105 |
"define the number of text-lines I am supposed to hold"
|
|
106 |
|
|
107 |
lineLimit := aNumber
|
|
108 |
!
|
|
109 |
|
|
110 |
destroyAction:aBlock
|
|
111 |
"define the action to be performed when I get destroyed"
|
|
112 |
|
|
113 |
destroyAction := aBlock
|
|
114 |
!
|
|
115 |
|
|
116 |
endEntry
|
|
117 |
"flush collected output"
|
|
118 |
|
|
119 |
|nLines|
|
|
120 |
|
|
121 |
"insert the bunch of lines - if any"
|
|
122 |
nLines := outstandingLines size.
|
|
123 |
(nLines ~~ 0) ifTrue:[
|
3
|
124 |
"
|
0
|
125 |
outstandingLines do:[:line |
|
|
126 |
self insertStringAtCursor:line.
|
|
127 |
self insertCharAtCursor:(Character cr)
|
|
128 |
].
|
|
129 |
"
|
3
|
130 |
" "
|
0
|
131 |
self insertLines:outstandingLines withCr:true.
|
3
|
132 |
" "
|
0
|
133 |
self withCursorOffDo:[
|
|
134 |
(cursorLine >= (firstLineShown + nFullLinesShown)) ifTrue:[
|
|
135 |
self scrollDown:nLines
|
|
136 |
]
|
|
137 |
].
|
|
138 |
outstandingLines grow:0
|
|
139 |
].
|
|
140 |
"and the last partial line - if any"
|
|
141 |
outstandingLine notNil ifTrue:[
|
|
142 |
flushPending := false.
|
|
143 |
self nextPut:outstandingLine.
|
|
144 |
outstandingLine := nil
|
|
145 |
].
|
7
|
146 |
Processor removeTimedBlock:flushBlock.
|
0
|
147 |
flushPending := false
|
|
148 |
! !
|
|
149 |
|
|
150 |
!TextCollector methodsFor:'private'!
|
|
151 |
|
|
152 |
checkLineLimit
|
|
153 |
"this method checks if the text has become too large (> lineLimit)
|
|
154 |
and cuts off some lines at the top if so; it must be called whenever lines
|
|
155 |
have been added to the bottom"
|
|
156 |
|
|
157 |
|nDel|
|
|
158 |
|
|
159 |
lineLimit notNil ifTrue:[
|
|
160 |
(cursorLine > lineLimit) ifTrue:[
|
|
161 |
nDel := list size - lineLimit.
|
|
162 |
list removeFromIndex:1 toIndex:nDel.
|
|
163 |
cursorLine := cursorLine - nDel.
|
|
164 |
firstLineShown := firstLineShown - nDel.
|
|
165 |
(firstLineShown < 1) ifTrue:[
|
|
166 |
cursorLine := cursorLine - firstLineShown + 1.
|
|
167 |
firstLineShown := 1
|
|
168 |
].
|
|
169 |
self contentsChanged
|
|
170 |
]
|
|
171 |
]
|
|
172 |
! !
|
|
173 |
|
|
174 |
!TextCollector methodsFor:'stream messages'!
|
|
175 |
|
|
176 |
lineLength
|
|
177 |
^ width // (font width)
|
|
178 |
!
|
|
179 |
|
|
180 |
nextPut:something
|
|
181 |
"this allows TextCollectors to be used Stream-wise"
|
|
182 |
|
|
183 |
flushPending ifTrue:[
|
|
184 |
self endEntry
|
|
185 |
].
|
|
186 |
(something isMemberOf:Character) ifTrue:[
|
|
187 |
((something == Character cr) or:[something == Character nl]) ifTrue:[
|
|
188 |
^ self cr
|
|
189 |
].
|
|
190 |
self insertCharAtCursor:something
|
|
191 |
] ifFalse:[
|
|
192 |
self insertStringAtCursor:(something printString).
|
|
193 |
self checkLineLimit
|
|
194 |
].
|
|
195 |
device synchronizeOutput
|
|
196 |
!
|
|
197 |
|
|
198 |
nextPutAll:something
|
|
199 |
"this allows TextCollectors to be used Stream-wise"
|
|
200 |
|
|
201 |
^ self nextPut:something
|
|
202 |
!
|
|
203 |
|
|
204 |
cr
|
|
205 |
collecting ifTrue:[
|
|
206 |
outstandingLines add:outstandingLine.
|
|
207 |
outstandingLine := nil.
|
|
208 |
flushPending ifFalse:[
|
7
|
209 |
Processor addTimedBlock:flushBlock after:0.2.
|
0
|
210 |
flushPending := true
|
|
211 |
] ifTrue:[
|
7
|
212 |
Processor evaluateTimeouts
|
0
|
213 |
]
|
|
214 |
] ifFalse:[
|
|
215 |
self cursorReturn.
|
|
216 |
self checkLineLimit
|
|
217 |
]
|
|
218 |
!
|
|
219 |
|
|
220 |
show:anObject
|
|
221 |
"insert the argument aString at current cursor position"
|
|
222 |
|
|
223 |
|aString|
|
|
224 |
|
|
225 |
aString := anObject printString.
|
|
226 |
collecting ifTrue:[
|
|
227 |
outstandingLine notNil ifTrue:[
|
|
228 |
outstandingLine := outstandingLine , aString
|
|
229 |
] ifFalse:[
|
|
230 |
outstandingLine := aString
|
|
231 |
].
|
|
232 |
flushPending ifFalse:[
|
7
|
233 |
Processor addTimedBlock:flushBlock after:0.2.
|
0
|
234 |
flushPending := true
|
|
235 |
]
|
|
236 |
] ifFalse:[
|
|
237 |
self nextPut:aString
|
|
238 |
]
|
|
239 |
!
|
|
240 |
|
|
241 |
showCr:aString
|
|
242 |
"insert the argument aString followed by a newline
|
|
243 |
at current cursor position"
|
|
244 |
|
|
245 |
self show:aString.
|
|
246 |
self cr
|
|
247 |
!
|
|
248 |
|
|
249 |
doesNotUnderstand:aMessage
|
|
250 |
"this is funny: all message we do not understand, are passed
|
|
251 |
on to the stream which will send the characters via nextPut:
|
|
252 |
This way, we understand all Stream messages - great isn't it !!
|
|
253 |
"
|
|
254 |
^ entryStream perform:(aMessage selector)
|
|
255 |
withArguments:(aMessage arguments)
|
|
256 |
! !
|