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