28
|
1 |
"{ Package: 'Programming Tools' }"
|
|
2 |
|
0
|
3 |
"
|
4
|
4 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
0
|
5 |
All Rights Reserved
|
|
6 |
|
|
7 |
This software is furnished under a license and may be used
|
|
8 |
only in accordance with the terms of that license and with the
|
|
9 |
inclusion of the above copyright notice. This software may not
|
|
10 |
be provided or otherwise made available to, or used by, any
|
|
11 |
other person. No title to or ownership of the software is
|
|
12 |
hereby transferred.
|
|
13 |
"
|
|
14 |
|
|
15 |
StandardSystemView subclass:#ChangesBrowser
|
|
16 |
instanceVariableNames:'changeListView codeView changeFileName
|
|
17 |
changeChunks changePositions
|
|
18 |
changeClassNames
|
|
19 |
anyChanges changeNrShown changeNrProcessed
|
28
|
20 |
fileBox'
|
0
|
21 |
classVariableNames:''
|
|
22 |
poolDictionaries:''
|
|
23 |
category:'Interface-Browsers'
|
|
24 |
!
|
|
25 |
|
|
26 |
ChangesBrowser comment:'
|
4
|
27 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
0
|
28 |
All Rights Reserved
|
|
29 |
|
29
|
30 |
$Header: /cvs/stx/stx/libtool/ChangesBrowser.st,v 1.12 1994-08-05 01:38:27 claus Exp $
|
|
31 |
'!
|
|
32 |
|
|
33 |
!ChangesBrowser class methodsFor:'documentation'!
|
|
34 |
|
|
35 |
copyright
|
|
36 |
"
|
|
37 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
|
38 |
All Rights Reserved
|
0
|
39 |
|
29
|
40 |
This software is furnished under a license and may be used
|
|
41 |
only in accordance with the terms of that license and with the
|
|
42 |
inclusion of the above copyright notice. This software may not
|
|
43 |
be provided or otherwise made available to, or used by, any
|
|
44 |
other person. No title to or ownership of the software is
|
|
45 |
hereby transferred.
|
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
version
|
|
50 |
"
|
|
51 |
$Header: /cvs/stx/stx/libtool/ChangesBrowser.st,v 1.12 1994-08-05 01:38:27 claus Exp $
|
|
52 |
!
|
|
53 |
|
|
54 |
documentation
|
|
55 |
"
|
|
56 |
this implements a browser for the changes-file.
|
|
57 |
See the extra document 'doc/misc/cbrowser.doc' for how to use this browser.
|
|
58 |
|
|
59 |
written jan 90 by claus
|
|
60 |
"
|
|
61 |
! !
|
0
|
62 |
|
|
63 |
!ChangesBrowser class methodsFor:'behavior'!
|
|
64 |
|
|
65 |
autoSelectNext
|
|
66 |
"returning true here, makes a Delete operation automatically
|
|
67 |
select the next change"
|
|
68 |
|
|
69 |
^ true
|
|
70 |
! !
|
|
71 |
|
|
72 |
!ChangesBrowser class methodsFor:'instance creation'!
|
|
73 |
|
|
74 |
new
|
|
75 |
"create a new changes browser"
|
|
76 |
|
|
77 |
^ super label:'Changes Browser'
|
|
78 |
icon:(Form fromFile:'CBrowser.xbm' resolution:100)
|
|
79 |
!
|
|
80 |
|
28
|
81 |
openOn:aFileName
|
0
|
82 |
"create c changes browser on a change file"
|
|
83 |
|
6
|
84 |
^ ((self new label:'Changes Browser:', aFileName) changeFileName:aFileName) open
|
0
|
85 |
! !
|
|
86 |
|
|
87 |
!ChangesBrowser methodsFor:'initialize / release'!
|
|
88 |
|
|
89 |
initialize
|
|
90 |
|frame v|
|
|
91 |
|
|
92 |
super initialize.
|
|
93 |
|
|
94 |
changeFileName := 'changes'.
|
|
95 |
|
|
96 |
frame := VariableVerticalPanel origin:(0.0 @ 0.0)
|
|
97 |
corner:(1.0 @ 1.0)
|
|
98 |
borderWidth:0
|
|
99 |
in:self.
|
|
100 |
|
|
101 |
v := ScrollableView for:SelectionInListView in:frame.
|
|
102 |
v origin:(0.0 @ 0.0) corner:(1.0 @ 0.3).
|
|
103 |
changeListView := v scrolledView.
|
|
104 |
|
28
|
105 |
v := HVScrollableView for:CodeView miniScrollerH:true miniScrollerV:false in:frame.
|
0
|
106 |
v origin:(0.0 @ 0.3) corner:(1.0 @ 1.0).
|
|
107 |
codeView := v scrolledView.
|
|
108 |
|
|
109 |
anyChanges := false.
|
28
|
110 |
ObjectMemory addDependent:self. "to get shutdown-update"
|
0
|
111 |
!
|
|
112 |
|
|
113 |
initializeMiddleButtonMenu
|
|
114 |
|labels|
|
|
115 |
|
1
|
116 |
labels := resources array:#(
|
0
|
117 |
'apply change'
|
|
118 |
'apply changes to end'
|
|
119 |
'apply all changes'
|
|
120 |
'-'
|
|
121 |
'delete'
|
|
122 |
'delete to end'
|
|
123 |
'delete changes for this class to end'
|
|
124 |
'delete all changes for this class'
|
|
125 |
'-'
|
|
126 |
'update'
|
|
127 |
'compress'
|
|
128 |
'compare with current version'
|
|
129 |
'-'
|
|
130 |
'make change a patch'
|
28
|
131 |
'save change in a file'
|
0
|
132 |
'update sourcefile from change'
|
|
133 |
'-'
|
|
134 |
'writeback changeFile').
|
|
135 |
|
|
136 |
changeListView
|
|
137 |
middleButtonMenu:(PopUpMenu
|
|
138 |
labels:labels
|
|
139 |
selectors:#(
|
|
140 |
doApply
|
|
141 |
doApplyRest
|
|
142 |
doApplyAll
|
|
143 |
nil
|
|
144 |
doDelete
|
|
145 |
doDeleteRest
|
|
146 |
doDeleteClassRest
|
|
147 |
doDeleteClassAll
|
|
148 |
nil
|
|
149 |
doUpdate
|
|
150 |
doCompress
|
|
151 |
doCompare
|
|
152 |
nil
|
|
153 |
doMakePatch
|
28
|
154 |
doSaveChangeInFile
|
0
|
155 |
doMakePermanent
|
|
156 |
nil
|
|
157 |
doWriteBack)
|
|
158 |
receiver:self
|
|
159 |
for:changeListView)
|
|
160 |
!
|
|
161 |
|
|
162 |
realize
|
|
163 |
super realize.
|
|
164 |
self readChangesFile.
|
28
|
165 |
self setChangeList.
|
15
|
166 |
changeListView action:[:lineNr | self changeSelection:lineNr].
|
|
167 |
self disableMenuEntries.
|
0
|
168 |
!
|
|
169 |
|
28
|
170 |
update:what
|
|
171 |
|box|
|
27
|
172 |
|
|
173 |
(what == #aboutToExit) ifTrue:[
|
28
|
174 |
"
|
|
175 |
smalltalk is about to shut down -
|
|
176 |
- if change list was modified, ask user and save if requested.
|
|
177 |
"
|
27
|
178 |
anyChanges ifTrue:[
|
|
179 |
shown ifFalse:[
|
|
180 |
self unrealize.
|
|
181 |
self realize
|
|
182 |
].
|
|
183 |
self raise.
|
28
|
184 |
|
|
185 |
box := YesNoBox new.
|
|
186 |
box title:(resources at:'ChangesBrowser:\changefile has not been updated from the modified changelist.\\Update before exiting ?') withCRs.
|
|
187 |
box noText:(resources at:'don''t update').
|
|
188 |
box okText:(resources at:'update').
|
|
189 |
box yesAction:[self writeBackChanges]
|
|
190 |
noAction:[].
|
|
191 |
box showAtPointer
|
27
|
192 |
].
|
28
|
193 |
^ self
|
27
|
194 |
].
|
|
195 |
super update:what
|
0
|
196 |
! !
|
|
197 |
|
28
|
198 |
!ChangesBrowser methodsFor:'termination'!
|
|
199 |
|
|
200 |
destroy
|
|
201 |
"destroy the receiver; make certain, that boxes are destroyed too"
|
|
202 |
|
|
203 |
ObjectMemory removeDependent:self.
|
|
204 |
fileBox notNil ifTrue:[fileBox destroy. fileBox := nil].
|
|
205 |
super destroy
|
|
206 |
!
|
|
207 |
|
|
208 |
saveAndTerminate
|
|
209 |
"update the changes file and quit.
|
|
210 |
Dont depend on this being sent, not all window managers
|
|
211 |
send it; instead, they simply destroy the view."
|
|
212 |
|
|
213 |
anyChanges ifTrue:[
|
|
214 |
self writeBackChanges.
|
|
215 |
].
|
|
216 |
self destroy
|
|
217 |
!
|
|
218 |
|
|
219 |
terminate
|
|
220 |
"window manager wants us to go away"
|
|
221 |
|
|
222 |
|box|
|
|
223 |
|
|
224 |
anyChanges ifTrue:[
|
|
225 |
box := OptionBox title:'' numberOfOptions:3.
|
|
226 |
box title:(resources at:'ChangesBrowser:\changefile has not been updated from the modified changelist.\\Update before exiting ?') withCRs.
|
|
227 |
box buttonTitles:(resources array:#('abort' 'dont''t update' 'update')).
|
|
228 |
box actions:(Array with:[^ self]
|
|
229 |
with:[self destroy]
|
|
230 |
with:[self writeBackChanges. self destroy]
|
|
231 |
).
|
|
232 |
box showAtPointer.
|
|
233 |
] ifFalse:[
|
|
234 |
self destroy
|
|
235 |
]
|
|
236 |
! !
|
|
237 |
|
0
|
238 |
!ChangesBrowser methodsFor:'private'!
|
|
239 |
|
15
|
240 |
enableMenuEntries
|
|
241 |
"enable all entries refering to a class"
|
|
242 |
|
28
|
243 |
#(doApply doApplyRest doDelete doDeleteRest doDeleteClassRest
|
|
244 |
doDeleteClassAll doCompare doMakePatch doSaveChangeInFile doMakePermanent)
|
|
245 |
do:[:sel |
|
|
246 |
changeListView middleButtonMenu enable:sel
|
|
247 |
].
|
15
|
248 |
!
|
|
249 |
|
|
250 |
disableMenuEntries
|
|
251 |
"enable all entries refering to a class"
|
|
252 |
|
28
|
253 |
#(doApply doApplyRest doDelete doDeleteRest doDeleteClassRest
|
|
254 |
doDeleteClassAll doCompare doMakePatch doSaveChangeInFile doMakePermanent)
|
|
255 |
do:[:sel |
|
|
256 |
changeListView middleButtonMenu disable:sel
|
|
257 |
].
|
15
|
258 |
!
|
|
259 |
|
|
260 |
unselect
|
|
261 |
"common unselect"
|
|
262 |
|
|
263 |
changeListView deselect.
|
|
264 |
self disableMenuEntries
|
|
265 |
!
|
|
266 |
|
6
|
267 |
queryCloseText
|
15
|
268 |
"made this a method for easy redefinition in subclasses"
|
|
269 |
|
6
|
270 |
^ 'Quit without updating changeFile ?'
|
|
271 |
!
|
|
272 |
|
0
|
273 |
changeFileName:aFileName
|
|
274 |
changeFileName := aFileName
|
|
275 |
!
|
|
276 |
|
|
277 |
withCursor:aCursor do:aBlock
|
|
278 |
"evaluate aBlock while showing another cursor"
|
|
279 |
|
|
280 |
|oldListCursor oldCodeViewCursor|
|
|
281 |
|
|
282 |
oldListCursor := changeListView cursor.
|
|
283 |
oldCodeViewCursor := codeView cursor.
|
|
284 |
|
|
285 |
changeListView cursor:aCursor.
|
|
286 |
codeView cursor:aCursor.
|
|
287 |
|
|
288 |
aBlock valueNowOrOnUnwindDo:[
|
|
289 |
changeListView cursor:oldListCursor.
|
|
290 |
codeView cursor:oldCodeViewCursor
|
|
291 |
]
|
|
292 |
!
|
|
293 |
|
|
294 |
classNameOfChange:changeNr
|
|
295 |
"return the classname of a change (for xxx class - changes xxx is returned)
|
|
296 |
- since parsing ascii methods is slow, keep result cached in
|
|
297 |
changeClassNames for the next query"
|
|
298 |
|
|
299 |
|chunk aParseTree recTree sel name arg1Tree|
|
|
300 |
|
|
301 |
changeNr notNil ifTrue:[
|
28
|
302 |
"
|
|
303 |
first look, if not already known
|
|
304 |
"
|
0
|
305 |
name := changeClassNames at:changeNr.
|
|
306 |
name notNil ifTrue:[^ name].
|
|
307 |
|
28
|
308 |
"
|
|
309 |
get the chunk
|
|
310 |
"
|
0
|
311 |
chunk := changeChunks at:changeNr.
|
|
312 |
chunk notNil ifTrue:[
|
28
|
313 |
"
|
|
314 |
use parser to construct a parseTree
|
|
315 |
"
|
0
|
316 |
aParseTree := Parser parseExpression:chunk.
|
28
|
317 |
(aParseTree notNil and:[aParseTree isMessage]) ifTrue:[
|
|
318 |
"
|
|
319 |
ask parser for selector
|
|
320 |
"
|
0
|
321 |
sel := aParseTree selector.
|
28
|
322 |
"
|
|
323 |
is it a method-change, methodRemove or comment-change ?
|
|
324 |
"
|
|
325 |
(#(methodsFor: privateMethodsFor: publicMethodsFor:
|
|
326 |
removeSelector: comment:) includes:sel) ifTrue:[
|
|
327 |
"
|
|
328 |
yes, the className is the receiver
|
|
329 |
"
|
0
|
330 |
recTree := aParseTree receiver.
|
28
|
331 |
(recTree notNil and:[recTree ~~ #Error]) ifTrue:[
|
|
332 |
recTree isUnaryMessage ifTrue:[
|
|
333 |
(recTree selector ~~ #class) ifTrue:[^ nil].
|
|
334 |
"id class methodsFor:..."
|
|
335 |
recTree := recTree receiver
|
|
336 |
].
|
|
337 |
recTree isPrimary ifTrue:[
|
|
338 |
name := recTree name.
|
|
339 |
changeClassNames at:changeNr put:name.
|
|
340 |
^ name
|
|
341 |
]
|
0
|
342 |
]
|
28
|
343 |
] ifFalse:[
|
|
344 |
"
|
|
345 |
is it a change in a class-description ?
|
|
346 |
"
|
|
347 |
('subclass:*' match:sel) ifTrue:[
|
|
348 |
arg1Tree := aParseTree arg1.
|
|
349 |
(arg1Tree notNil and:[arg1Tree isConstant]) ifTrue:[
|
|
350 |
name := arg1Tree value asString.
|
|
351 |
changeClassNames at:changeNr put:name.
|
|
352 |
^ name
|
|
353 |
]
|
0
|
354 |
]
|
|
355 |
]
|
|
356 |
]
|
|
357 |
]
|
|
358 |
].
|
|
359 |
^ nil
|
|
360 |
!
|
|
361 |
|
|
362 |
streamForChange:changeNr
|
|
363 |
"answer a stream for change"
|
|
364 |
|
|
365 |
|aStream|
|
|
366 |
|
|
367 |
aStream := FileStream readonlyFileNamed:changeFileName.
|
|
368 |
aStream isNil ifTrue:[^ nil].
|
|
369 |
aStream position:(changePositions at:changeNr).
|
|
370 |
^ aStream
|
|
371 |
!
|
|
372 |
|
|
373 |
clearCodeView
|
15
|
374 |
self unselect "changeListView deselect".
|
0
|
375 |
codeView contents:nil.
|
|
376 |
changeNrShown := nil
|
|
377 |
!
|
|
378 |
|
|
379 |
autoSelect:changeNr
|
|
380 |
self class autoSelectNext ifTrue:[
|
|
381 |
(changeNr <= changeChunks size) ifTrue:[
|
|
382 |
changeListView selection:changeNr.
|
|
383 |
self changeSelection:changeNr.
|
|
384 |
^ self
|
|
385 |
]
|
|
386 |
].
|
|
387 |
self clearCodeView
|
|
388 |
!
|
|
389 |
|
|
390 |
writeBackChanges
|
|
391 |
"write back the changes file"
|
|
392 |
|
|
393 |
|inStream outStream chunk sawExcla excla done dir|
|
|
394 |
|
|
395 |
outStream := FileStream newFileNamed:'n_changes'.
|
|
396 |
outStream isNil ifTrue:[
|
|
397 |
self warn:'cannot create temporary file'.
|
|
398 |
^ self
|
|
399 |
].
|
|
400 |
|
|
401 |
inStream := FileStream readonlyFileNamed:changeFileName.
|
|
402 |
inStream isNil ifTrue:[^ nil].
|
|
403 |
|
|
404 |
self withCursor:(Cursor write) do:[
|
|
405 |
excla := inStream class chunkSeparator.
|
|
406 |
1 to:(changeChunks size) do:[:index |
|
|
407 |
inStream position:(changePositions at:index).
|
|
408 |
sawExcla := inStream peekFor:excla.
|
|
409 |
chunk := inStream nextChunk.
|
|
410 |
|
|
411 |
sawExcla ifTrue:[
|
|
412 |
outStream nextPut:excla.
|
|
413 |
outStream nextChunkPut:chunk.
|
|
414 |
outStream cr.
|
|
415 |
"a method-definition chunk - skip followups"
|
|
416 |
done := false.
|
|
417 |
[done] whileFalse:[
|
|
418 |
chunk := inStream nextChunk.
|
|
419 |
chunk isNil ifTrue:[
|
|
420 |
done := true
|
|
421 |
] ifFalse:[
|
|
422 |
outStream nextChunkPut:chunk.
|
|
423 |
outStream cr.
|
|
424 |
done := chunk isEmpty
|
|
425 |
]
|
|
426 |
].
|
|
427 |
0 "compiler kludge"
|
|
428 |
] ifFalse:[
|
|
429 |
outStream nextChunkPut:chunk.
|
|
430 |
outStream cr
|
|
431 |
]
|
|
432 |
].
|
|
433 |
outStream close.
|
|
434 |
inStream close.
|
|
435 |
dir := FileDirectory currentDirectory.
|
|
436 |
dir removeFile:changeFileName.
|
|
437 |
dir renameFile:'n_changes' newName:changeFileName.
|
|
438 |
anyChanges := false
|
|
439 |
]
|
|
440 |
!
|
|
441 |
|
28
|
442 |
setChangeList
|
|
443 |
"extract type-information from changes and stuff into top selection
|
|
444 |
view"
|
|
445 |
|
|
446 |
changeListView contents:changeChunks.
|
|
447 |
!
|
|
448 |
|
0
|
449 |
readChangesFile
|
28
|
450 |
"read the changes file, create a list of header-lines (changeChunks)
|
|
451 |
and a list of chunk-positions (changePositions)"
|
0
|
452 |
|
29
|
453 |
|aStream index text done sawExcla chunkPos excla
|
|
454 |
myProcess myPriority p sel cls|
|
0
|
455 |
|
|
456 |
aStream := FileStream readonlyFileNamed:changeFileName.
|
|
457 |
aStream isNil ifTrue:[^ nil].
|
|
458 |
|
|
459 |
self withCursor:(Cursor read) do:[
|
29
|
460 |
"
|
|
461 |
this is a time consuming operation (especially, if reading an
|
|
462 |
NFS-mounted directory; therefore lower my priority ...
|
|
463 |
"
|
|
464 |
myProcess := Processor activeProcess.
|
|
465 |
myPriority := myProcess priority.
|
|
466 |
myProcess priority:(Processor userBackgroundPriority).
|
|
467 |
[
|
|
468 |
|
|
469 |
changeChunks := OrderedCollection new.
|
|
470 |
changePositions := OrderedCollection new.
|
|
471 |
excla := aStream class chunkSeparator.
|
0
|
472 |
|
29
|
473 |
[aStream atEnd] whileFalse:[
|
|
474 |
"
|
|
475 |
get a chunk (separated by excla)
|
|
476 |
"
|
|
477 |
aStream skipSeparators.
|
|
478 |
chunkPos := aStream position.
|
|
479 |
sawExcla := aStream peekFor:excla.
|
|
480 |
text := aStream nextChunk.
|
|
481 |
text notNil ifTrue:[
|
|
482 |
changePositions add:chunkPos.
|
6
|
483 |
|
29
|
484 |
"
|
|
485 |
only first line is saved in changeChunks ...
|
|
486 |
"
|
|
487 |
index := text indexOf:(Character cr).
|
|
488 |
(index ~~ 0) ifTrue:[
|
|
489 |
text := text copyTo:(index - 1).
|
|
490 |
|
|
491 |
"take care for comment changes - must still be a
|
|
492 |
valid expression for classNameOfChange: to work"
|
|
493 |
|
|
494 |
(text endsWith:'comment:''') ifTrue:[
|
|
495 |
text := text , '...'''
|
|
496 |
]
|
|
497 |
|
|
498 |
].
|
6
|
499 |
|
29
|
500 |
sawExcla ifFalse:[
|
|
501 |
(text startsWith:'''---- snap') ifFalse:[
|
|
502 |
"/ text := '(doIt) ' , text.
|
|
503 |
].
|
|
504 |
changeChunks add:text.
|
|
505 |
] ifTrue:[
|
|
506 |
"
|
|
507 |
method definitions actually consist of
|
|
508 |
two (or more) chunks; skip next chunk(s)
|
|
509 |
up to an empty one.
|
|
510 |
(the system currently only writes one chunk,
|
|
511 |
but in theory, more could follow for the same
|
|
512 |
class/category).
|
|
513 |
"
|
|
514 |
cls := nil.
|
|
515 |
p := Parser parseExpression:text.
|
|
516 |
(p notNil and:[p ~~ #Error]) ifTrue:[
|
|
517 |
sel := p selector.
|
|
518 |
(sel == #methodsFor:) ifTrue:[
|
|
519 |
p receiver isUnaryMessage ifTrue:[
|
|
520 |
cls := p receiver receiver name.
|
|
521 |
cls := cls , 'class'
|
|
522 |
] ifFalse:[
|
|
523 |
cls := p receiver name
|
|
524 |
]
|
|
525 |
]
|
|
526 |
].
|
|
527 |
cls isNil ifTrue:[
|
|
528 |
changeChunks add:text , ' (change)'.
|
|
529 |
].
|
6
|
530 |
|
29
|
531 |
done := false.
|
|
532 |
[done] whileFalse:[
|
|
533 |
text := aStream nextChunk.
|
|
534 |
text isNil ifTrue:[
|
|
535 |
done := true
|
|
536 |
] ifFalse:[
|
|
537 |
done := text isEmpty
|
|
538 |
].
|
|
539 |
done ifFalse:[
|
|
540 |
cls notNil ifTrue:[
|
|
541 |
p := Parser parseMethodSpecification:text.
|
|
542 |
(p notNil and:[p ~~ #Error]) ifTrue:[
|
|
543 |
sel := p selector.
|
|
544 |
changeChunks add: cls , ' ' , sel
|
|
545 |
]
|
|
546 |
]
|
|
547 |
]
|
0
|
548 |
]
|
|
549 |
]
|
|
550 |
]
|
29
|
551 |
].
|
|
552 |
changeClassNames := VariableArray new:(changeChunks size).
|
|
553 |
aStream close.
|
|
554 |
anyChanges := false
|
|
555 |
] valueNowOrOnUnwindDo:[
|
|
556 |
myProcess priority:myPriority.
|
0
|
557 |
].
|
|
558 |
]
|
|
559 |
!
|
|
560 |
|
|
561 |
silentDeleteChange:changeNr
|
|
562 |
"delete a change do not update changeListView"
|
|
563 |
|
|
564 |
anyChanges := true.
|
|
565 |
changeChunks removeIndex:changeNr.
|
|
566 |
changePositions removeIndex:changeNr.
|
|
567 |
changeClassNames removeIndex:changeNr
|
|
568 |
!
|
|
569 |
|
|
570 |
|
|
571 |
deleteChange:changeNr
|
|
572 |
"delete a change"
|
|
573 |
|
|
574 |
changeListView deselect.
|
|
575 |
self silentDeleteChange:changeNr.
|
|
576 |
changeListView setContents:changeChunks
|
|
577 |
!
|
|
578 |
|
|
579 |
deleteChangesFrom:start to:stop
|
|
580 |
"delete a range of changes"
|
|
581 |
|
|
582 |
changeListView deselect.
|
|
583 |
stop to:start by:-1 do:[:changeNr |
|
|
584 |
self silentDeleteChange:changeNr
|
|
585 |
].
|
|
586 |
changeListView setContents:changeChunks
|
|
587 |
!
|
|
588 |
|
|
589 |
deleteChangesFor:aClassName from:start to:stop
|
|
590 |
"delete changes for a given class in a range"
|
|
591 |
|
|
592 |
|thisClassName index|
|
|
593 |
|
|
594 |
index := stop.
|
|
595 |
[index >= start] whileTrue:[
|
|
596 |
thisClassName := self classNameOfChange:index.
|
|
597 |
thisClassName = aClassName ifTrue:[
|
|
598 |
self silentDeleteChange:index
|
|
599 |
].
|
|
600 |
index := index - 1
|
|
601 |
]
|
|
602 |
!
|
|
603 |
|
|
604 |
applyChange:changeNr
|
|
605 |
"filein a change"
|
|
606 |
|
29
|
607 |
|aStream chunk sawExcla upd rslt|
|
0
|
608 |
|
|
609 |
aStream := self streamForChange:changeNr.
|
|
610 |
aStream isNil ifTrue:[^ self].
|
|
611 |
sawExcla := aStream peekFor:(aStream class chunkSeparator).
|
|
612 |
chunk := aStream nextChunk.
|
1
|
613 |
upd := Class updateChanges:false.
|
29
|
614 |
|
1
|
615 |
codeView abortAction:[Class updateChanges:upd.
|
0
|
616 |
codeView abortAction:nil.
|
|
617 |
aStream close.
|
|
618 |
^self].
|
22
|
619 |
|
0
|
620 |
changeNrProcessed := changeNr.
|
|
621 |
[
|
22
|
622 |
Object abortSignal catch:[
|
29
|
623 |
|rslt|
|
|
624 |
|
|
625 |
rslt := Compiler evaluate:chunk notifying:self.
|
|
626 |
sawExcla ifTrue:[
|
|
627 |
rslt fileInFrom:aStream notifying:self
|
22
|
628 |
]
|
0
|
629 |
].
|
|
630 |
changeNrProcessed := nil.
|
|
631 |
codeView abortAction:nil
|
29
|
632 |
] valueNowOrOnUnwindDo:[
|
|
633 |
Class updateChanges:upd.
|
|
634 |
aStream close
|
|
635 |
].
|
0
|
636 |
!
|
|
637 |
|
|
638 |
compareChange:changeNr
|
|
639 |
"compare a change with current version"
|
|
640 |
|
|
641 |
|aStream chunk sawExcla parseTree thisClass cat oldSource newSource
|
29
|
642 |
parser sel oldMethod outcome showDiff d|
|
0
|
643 |
|
|
644 |
aStream := self streamForChange:changeNr.
|
|
645 |
aStream isNil ifTrue:[^ self].
|
28
|
646 |
|
0
|
647 |
sawExcla := aStream peekFor:(aStream class chunkSeparator).
|
|
648 |
chunk := aStream nextChunk.
|
|
649 |
sawExcla ifFalse:[
|
28
|
650 |
outcome := 'not comparable ...'
|
0
|
651 |
] ifTrue:[
|
|
652 |
parseTree := Parser parseExpression:chunk.
|
28
|
653 |
(parseTree notNil and:[parseTree isMessage]) ifTrue:[
|
0
|
654 |
(parseTree selector == #methodsFor:) ifTrue:[
|
|
655 |
thisClass := (parseTree receiver evaluate).
|
28
|
656 |
thisClass isBehavior ifTrue:[
|
|
657 |
showDiff := false.
|
0
|
658 |
cat := parseTree arg1 evaluate.
|
|
659 |
newSource := aStream nextChunk.
|
|
660 |
parser := Parser parseMethod:newSource in:thisClass.
|
28
|
661 |
(parser notNil and:[parser ~~ #Error]) ifTrue:[
|
0
|
662 |
sel := parser selector.
|
|
663 |
oldMethod := thisClass compiledMethodAt:sel.
|
|
664 |
oldMethod notNil ifTrue:[
|
|
665 |
(oldMethod category = cat) ifFalse:[
|
28
|
666 |
Transcript showCr:'category changed.'.
|
0
|
667 |
].
|
|
668 |
oldSource := oldMethod source.
|
|
669 |
(oldSource = newSource) ifTrue:[
|
28
|
670 |
outcome := 'same source'
|
0
|
671 |
] ifFalse:[
|
28
|
672 |
outcome := 'source changed.'.
|
|
673 |
showDiff := true
|
0
|
674 |
]
|
|
675 |
] ifFalse:[
|
28
|
676 |
outcome := 'method does not exist.'
|
0
|
677 |
]
|
|
678 |
] ifFalse:[
|
28
|
679 |
outcome := 'change unparsable.'
|
|
680 |
].
|
|
681 |
(showDiff and:[oldSource notNil and:[newSource notNil]]) ifTrue:[
|
29
|
682 |
d := DiffTextView openOn:oldSource and:newSource.
|
|
683 |
d label:'differences (current left; change right)'.
|
0
|
684 |
]
|
|
685 |
] ifFalse:[
|
28
|
686 |
outcome := 'class does not exist.'
|
0
|
687 |
]
|
|
688 |
] ifFalse:[
|
28
|
689 |
outcome := 'not comparable.'
|
0
|
690 |
]
|
|
691 |
] ifFalse:[
|
28
|
692 |
outcome := 'not comparable.'
|
0
|
693 |
]
|
|
694 |
].
|
28
|
695 |
Transcript showCr:outcome.
|
|
696 |
aStream close.
|
0
|
697 |
!
|
|
698 |
|
28
|
699 |
appendChange:changeNr toFile:fileName
|
|
700 |
"append change to a file"
|
0
|
701 |
|
|
702 |
|aStream outStream chunk sawExcla|
|
|
703 |
|
28
|
704 |
outStream := FileStream oldFileNamed:fileName.
|
0
|
705 |
outStream isNil ifTrue:[
|
|
706 |
outStream isNil ifTrue:[
|
28
|
707 |
outStream := FileStream newFileNamed:fileName.
|
0
|
708 |
outStream isNil ifTrue:[
|
28
|
709 |
self warn:'cannot update file ''', fileName , ''''.
|
0
|
710 |
^ self
|
|
711 |
]
|
|
712 |
]
|
|
713 |
].
|
|
714 |
outStream setToEnd.
|
28
|
715 |
|
0
|
716 |
aStream := self streamForChange:changeNr.
|
|
717 |
aStream isNil ifTrue:[^ self].
|
|
718 |
sawExcla := aStream peekFor:(aStream class chunkSeparator).
|
|
719 |
sawExcla ifTrue:[
|
|
720 |
outStream nextPut:$!!
|
|
721 |
].
|
|
722 |
chunk := aStream nextChunk.
|
|
723 |
outStream nextChunkPut:chunk.
|
|
724 |
outStream cr.
|
|
725 |
sawExcla ifTrue:[
|
|
726 |
chunk := aStream nextChunk.
|
|
727 |
outStream nextChunkPut:chunk.
|
|
728 |
outStream space
|
|
729 |
].
|
|
730 |
sawExcla ifTrue:[
|
|
731 |
outStream nextPut:$!!
|
|
732 |
].
|
|
733 |
outStream cr.
|
|
734 |
aStream close.
|
|
735 |
outStream close
|
|
736 |
!
|
|
737 |
|
28
|
738 |
makeChangeAPatch:changeNr
|
|
739 |
"append change to patchfile"
|
|
740 |
|
|
741 |
self appendChange:changeNr toFile:'patches'
|
|
742 |
!
|
|
743 |
|
0
|
744 |
makeChangePermanent:changeNr
|
28
|
745 |
"rewrite the source file where change changeNr lies"
|
0
|
746 |
|
|
747 |
self notify:'this is not yet implemented'
|
|
748 |
! !
|
|
749 |
|
|
750 |
!ChangesBrowser methodsFor:'error handling'!
|
|
751 |
|
|
752 |
correctableError:aString position:relPos to:relEndPos
|
|
753 |
"compiler notifys us of an error - this should really not happen since
|
|
754 |
changes ought to be correct (did someone edit the changes file ??).
|
|
755 |
Show the bad change in the codeView and let codeView hilight the error;
|
|
756 |
no corrections allowed here therefore return false"
|
|
757 |
|
|
758 |
(changeNrProcessed ~~ changeNrShown) ifTrue:[
|
|
759 |
self changeSelection:changeNrProcessed
|
|
760 |
].
|
|
761 |
codeView error:aString position:relPos to:relEndPos.
|
|
762 |
^ false
|
|
763 |
!
|
|
764 |
|
|
765 |
error:aString position:relPos to:relEndPos
|
|
766 |
"compiler notifys us of an error - this should really not happen since
|
|
767 |
changes ought to be correct (did someone edit the changes file ??).
|
|
768 |
Show the bad change in the codeView and let codeView hilight the error"
|
|
769 |
|
|
770 |
(changeNrProcessed ~~ changeNrShown) ifTrue:[
|
|
771 |
self changeSelection:changeNrProcessed
|
|
772 |
].
|
|
773 |
^ codeView error:aString position:relPos to:relEndPos
|
|
774 |
!
|
|
775 |
|
|
776 |
warning:aString position:relPos to:relEndPos
|
|
777 |
"compiler notifys us of a warning - ignore it"
|
|
778 |
|
|
779 |
^ self
|
|
780 |
! !
|
|
781 |
|
|
782 |
!ChangesBrowser methodsFor:'user interaction'!
|
|
783 |
|
|
784 |
noChangesAllowed
|
|
785 |
"show a warning that changes cannot be changed"
|
|
786 |
|
1
|
787 |
self warn:(resources at:'changes are not allowed to be changed')
|
0
|
788 |
!
|
|
789 |
|
|
790 |
changeSelection:lineNr
|
|
791 |
"show a change in the codeView"
|
|
792 |
|
|
793 |
|aStream sawExcla chunk|
|
|
794 |
|
|
795 |
aStream := self streamForChange:lineNr.
|
|
796 |
aStream isNil ifTrue:[^ self].
|
|
797 |
sawExcla := aStream peekFor:(aStream class chunkSeparator).
|
|
798 |
chunk := aStream nextChunk.
|
|
799 |
sawExcla ifTrue:[
|
|
800 |
chunk := aStream nextChunk
|
|
801 |
].
|
|
802 |
aStream close.
|
|
803 |
codeView contents:chunk.
|
13
|
804 |
codeView acceptAction:[:theCode | self doApply "noChangesAllowed"].
|
15
|
805 |
changeNrShown := lineNr.
|
|
806 |
self enableMenuEntries
|
0
|
807 |
!
|
|
808 |
|
28
|
809 |
doSaveChangeInFile
|
|
810 |
"user wants a change to be appended to a file"
|
|
811 |
|
|
812 |
|changeNr|
|
|
813 |
|
|
814 |
changeNr := changeListView selection.
|
|
815 |
changeNr notNil ifTrue:[
|
|
816 |
fileBox isNil ifTrue:[
|
|
817 |
fileBox := FileSelectionBox new.
|
|
818 |
].
|
|
819 |
fileBox title:'append change to:'.
|
|
820 |
fileBox okText:'append'.
|
|
821 |
fileBox abortText:'cancel'.
|
|
822 |
fileBox action:[:fileName |
|
|
823 |
self appendChange:changeNr toFile:fileName.
|
|
824 |
self autoSelect:(changeNr + 1)
|
|
825 |
].
|
|
826 |
|
|
827 |
fileBox pattern:'*.chg'.
|
|
828 |
fileBox showAtPointer
|
|
829 |
]
|
|
830 |
!
|
|
831 |
|
0
|
832 |
doMakePermanent
|
|
833 |
"user wants a change to be made permanent
|
|
834 |
- rewrite the source file where this change has to go"
|
|
835 |
|
|
836 |
|changeNr yesNoBox|
|
|
837 |
|
28
|
838 |
yesNoBox := YesNoBox new.
|
1
|
839 |
yesNoBox title:(resources at:'Warning: this operation cannot be undone').
|
28
|
840 |
yesNoBox okText:(resources at:'continue').
|
1
|
841 |
yesNoBox noText:(resources at:'abort').
|
0
|
842 |
yesNoBox okAction:[
|
28
|
843 |
changeNr := changeListView selection.
|
|
844 |
changeNr notNil ifTrue:[
|
|
845 |
self makeChangePermanent:changeNr.
|
|
846 |
self autoSelect:(changeNr + 1)
|
|
847 |
]
|
|
848 |
].
|
0
|
849 |
yesNoBox showAtPointer
|
|
850 |
!
|
|
851 |
|
|
852 |
doMakePatch
|
|
853 |
"user wants a change to be made a patch
|
|
854 |
- copy it over to the patches file"
|
|
855 |
|
|
856 |
|changeNr|
|
|
857 |
|
|
858 |
changeNr := changeListView selection.
|
|
859 |
changeNr notNil ifTrue:[
|
|
860 |
self makeChangeAPatch:changeNr.
|
|
861 |
self autoSelect:(changeNr + 1)
|
|
862 |
]
|
|
863 |
!
|
|
864 |
|
|
865 |
doApply
|
|
866 |
"user wants a change to be applied"
|
|
867 |
|
|
868 |
|changeNr|
|
|
869 |
|
|
870 |
changeNr := changeListView selection.
|
|
871 |
changeNr notNil ifTrue:[
|
|
872 |
self withCursor:(Cursor execute) do:[
|
|
873 |
self applyChange:changeNr.
|
|
874 |
self autoSelect:(changeNr + 1)
|
|
875 |
]
|
|
876 |
]
|
|
877 |
!
|
|
878 |
|
|
879 |
doApplyAll
|
|
880 |
"user wants all changes to be applied"
|
|
881 |
|
|
882 |
self withCursor:(Cursor execute) do:[
|
|
883 |
self clearCodeView.
|
|
884 |
1 to:(changePositions size) do:[:changeNr |
|
|
885 |
changeListView selection:changeNr.
|
|
886 |
self applyChange:changeNr
|
|
887 |
]
|
|
888 |
]
|
|
889 |
!
|
|
890 |
|
|
891 |
doApplyRest
|
|
892 |
"user wants all changes from changeNr to be applied"
|
|
893 |
|
|
894 |
|changeNr|
|
|
895 |
|
|
896 |
changeNr := changeListView selection.
|
|
897 |
changeNr notNil ifTrue:[
|
|
898 |
self withCursor:(Cursor execute) do:[
|
|
899 |
self clearCodeView.
|
|
900 |
changeNr to:(changePositions size) do:[:changeNr |
|
|
901 |
changeListView selection:changeNr.
|
|
902 |
self applyChange:changeNr
|
|
903 |
]
|
|
904 |
]
|
|
905 |
]
|
|
906 |
!
|
|
907 |
|
|
908 |
doDelete
|
|
909 |
"delete currently selected change"
|
|
910 |
|
|
911 |
|changeNr|
|
|
912 |
|
|
913 |
changeNr := changeListView selection.
|
|
914 |
changeNr notNil ifTrue:[
|
|
915 |
self deleteChange:changeNr.
|
|
916 |
self autoSelect:changeNr
|
|
917 |
]
|
|
918 |
!
|
|
919 |
|
|
920 |
doDeleteClassRest
|
|
921 |
"delete rest of changes with same class as currently selected change"
|
|
922 |
|
|
923 |
|changeNr classNameToDelete|
|
|
924 |
|
|
925 |
changeNr := changeListView selection.
|
|
926 |
changeNr notNil ifTrue:[
|
|
927 |
self withCursor:(Cursor execute) do:[
|
|
928 |
classNameToDelete := self classNameOfChange:changeNr.
|
|
929 |
classNameToDelete notNil ifTrue:[
|
|
930 |
changeListView selection:nil.
|
|
931 |
self deleteChangesFor:classNameToDelete
|
|
932 |
from:changeNr
|
|
933 |
to:(changeChunks size).
|
|
934 |
changeListView setContents:changeChunks.
|
|
935 |
self autoSelect:changeNr
|
|
936 |
]
|
|
937 |
]
|
|
938 |
]
|
|
939 |
!
|
|
940 |
|
|
941 |
doDeleteRest
|
|
942 |
"delete all changes from current to the end"
|
|
943 |
|
|
944 |
|changeNr|
|
|
945 |
|
|
946 |
changeNr := changeListView selection.
|
|
947 |
changeNr notNil ifTrue:[
|
|
948 |
self deleteChangesFrom:changeNr to:(changeChunks size).
|
|
949 |
self clearCodeView
|
|
950 |
]
|
|
951 |
!
|
|
952 |
|
|
953 |
doDeleteClassAll
|
|
954 |
"delete all changes with same class as currently selected change"
|
|
955 |
|
|
956 |
|changeNr classNameToDelete|
|
|
957 |
|
|
958 |
changeNr := changeListView selection.
|
|
959 |
changeNr notNil ifTrue:[
|
|
960 |
self withCursor:(Cursor execute) do:[
|
|
961 |
classNameToDelete := self classNameOfChange:changeNr.
|
|
962 |
classNameToDelete notNil ifTrue:[
|
|
963 |
changeListView selection:nil.
|
|
964 |
self deleteChangesFor:classNameToDelete
|
|
965 |
from:1
|
|
966 |
to:(changeChunks size).
|
|
967 |
changeListView contents:changeChunks.
|
|
968 |
self autoSelect:changeNr
|
|
969 |
]
|
|
970 |
]
|
|
971 |
]
|
|
972 |
!
|
|
973 |
|
|
974 |
doWriteBack
|
15
|
975 |
"write back the list onto the changes file"
|
|
976 |
|
0
|
977 |
anyChanges ifTrue:[
|
|
978 |
self writeBackChanges.
|
|
979 |
self doUpdate
|
|
980 |
]
|
|
981 |
!
|
|
982 |
|
|
983 |
doUpdate
|
15
|
984 |
"reread the changes-file"
|
0
|
985 |
|
|
986 |
self readChangesFile.
|
15
|
987 |
changeListView setContents:changeChunks
|
0
|
988 |
!
|
|
989 |
|
|
990 |
doCompare
|
|
991 |
"compare change with current system version
|
|
992 |
- give a note in transcript"
|
|
993 |
|
|
994 |
|changeNr|
|
|
995 |
|
|
996 |
changeNr := changeListView selection.
|
|
997 |
changeNr notNil ifTrue:[
|
28
|
998 |
self withCursor:(Cursor execute) do:[
|
|
999 |
self compareChange:changeNr
|
|
1000 |
]
|
0
|
1001 |
]
|
|
1002 |
!
|
|
1003 |
|
|
1004 |
doCompress
|
|
1005 |
"compress the change-set; this replaces multiple method-changes by the last
|
|
1006 |
(i.e. the most recent) change"
|
|
1007 |
|
|
1008 |
|classes types selectors thisClass thisSelector
|
|
1009 |
aStream chunk changeNr sawExcla aParseTree codeChunk codeParser
|
|
1010 |
searchIndex anyMore deleteSet index parseTreeChunk numChanges
|
|
1011 |
excla|
|
|
1012 |
|
|
1013 |
aStream := FileStream readonlyFileNamed:changeFileName.
|
|
1014 |
aStream isNil ifTrue:[^ self].
|
|
1015 |
|
|
1016 |
self withCursor:(Cursor execute) do:[
|
|
1017 |
numChanges := changePositions size.
|
|
1018 |
classes := Array new:numChanges.
|
|
1019 |
selectors := Array new:numChanges.
|
|
1020 |
types := Array new:numChanges.
|
|
1021 |
|
|
1022 |
"starting at the end, get the change class and change selector;
|
|
1023 |
collect all in classes / selectors"
|
|
1024 |
|
|
1025 |
changeNr := numChanges.
|
|
1026 |
excla := aStream class chunkSeparator.
|
|
1027 |
|
|
1028 |
[changeNr >= 1] whileTrue:[
|
|
1029 |
aStream position:(changePositions at:changeNr).
|
|
1030 |
sawExcla := aStream peekFor:excla.
|
|
1031 |
chunk := aStream nextChunk.
|
|
1032 |
sawExcla ifTrue:[
|
|
1033 |
"optimize a bit if multiple methods for same category arrive"
|
|
1034 |
(chunk = parseTreeChunk) ifFalse:[
|
|
1035 |
aParseTree := Parser parseExpression:chunk.
|
|
1036 |
parseTreeChunk := chunk
|
|
1037 |
].
|
28
|
1038 |
(aParseTree notNil
|
|
1039 |
and:[(aParseTree ~~ #Error)
|
|
1040 |
and:[aParseTree isMessage]]) ifTrue:[
|
0
|
1041 |
(aParseTree selector == #methodsFor:) ifTrue:[
|
|
1042 |
thisClass := (aParseTree receiver evaluate).
|
|
1043 |
codeChunk := aStream nextChunk.
|
|
1044 |
codeParser := Parser parseMethodSpecification:codeChunk
|
|
1045 |
in:thisClass.
|
|
1046 |
codeParser notNil ifTrue:[
|
|
1047 |
selectors at:changeNr put:(codeParser selector).
|
|
1048 |
classes at:changeNr put:thisClass.
|
|
1049 |
types at:changeNr put:#methodsFor
|
|
1050 |
]
|
|
1051 |
]
|
|
1052 |
]
|
|
1053 |
] ifFalse:[
|
|
1054 |
aParseTree := Parser parseExpression:chunk.
|
|
1055 |
parseTreeChunk := chunk.
|
28
|
1056 |
(aParseTree notNil
|
|
1057 |
and:[(aParseTree ~~ #Error)
|
|
1058 |
and:[aParseTree isMessage]]) ifTrue:[
|
0
|
1059 |
(aParseTree selector == #removeSelector:) ifTrue:[
|
|
1060 |
selectors at:changeNr put:(aParseTree arg1 value ).
|
|
1061 |
classes at:changeNr put:(aParseTree receiver evaluate).
|
|
1062 |
types at:changeNr put:#removeSelector
|
|
1063 |
]
|
|
1064 |
]
|
|
1065 |
].
|
|
1066 |
changeNr := changeNr - 1
|
|
1067 |
].
|
|
1068 |
aStream close.
|
|
1069 |
|
|
1070 |
"for all changes, look for another class/selector occurence and
|
|
1071 |
add change number to delete set if found"
|
|
1072 |
|
|
1073 |
deleteSet := OrderedCollection new.
|
|
1074 |
changeNr := 1.
|
|
1075 |
[changeNr < changePositions size] whileTrue:[
|
|
1076 |
thisClass := classes at:changeNr.
|
|
1077 |
thisSelector := selectors at:changeNr.
|
|
1078 |
searchIndex := changeNr.
|
|
1079 |
anyMore := true.
|
|
1080 |
[anyMore] whileTrue:[
|
|
1081 |
searchIndex := classes indexOf:thisClass
|
|
1082 |
startingAt:(searchIndex + 1).
|
|
1083 |
(searchIndex ~~ 0) ifTrue:[
|
|
1084 |
((selectors at:searchIndex) == thisSelector) ifTrue:[
|
|
1085 |
thisClass notNil ifTrue:[
|
|
1086 |
deleteSet add:changeNr.
|
|
1087 |
anyMore := false
|
|
1088 |
]
|
|
1089 |
]
|
|
1090 |
] ifFalse:[
|
|
1091 |
anyMore := false
|
|
1092 |
]
|
|
1093 |
].
|
|
1094 |
changeNr := changeNr + 1
|
|
1095 |
].
|
|
1096 |
|
|
1097 |
"finally delete what has been found"
|
|
1098 |
|
|
1099 |
(deleteSet size > 0) ifTrue:[
|
|
1100 |
changeListView selection:nil.
|
|
1101 |
index := deleteSet size.
|
|
1102 |
[index > 0] whileTrue:[
|
|
1103 |
self silentDeleteChange:(deleteSet at:index).
|
|
1104 |
index := index - 1
|
|
1105 |
].
|
15
|
1106 |
changeListView setContents:changeChunks.
|
|
1107 |
changeListView firstLineShown > changeChunks size ifTrue:[
|
|
1108 |
changeListView makeLineVisible:changeChunks size
|
|
1109 |
].
|
0
|
1110 |
self clearCodeView
|
|
1111 |
]
|
|
1112 |
]
|
|
1113 |
! !
|