author | Claus Gittinger <cg@exept.de> |
Thu, 16 Nov 1995 17:27:16 +0100 | |
changeset 177 | 36c5c99b9ffb |
parent 165 | df29ee4514c1 |
child 178 | 609b67e6140a |
permissions | -rw-r--r-- |
36 | 1 |
" |
2 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
45 | 3 |
All Rights Reserved |
36 | 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 |
TwoColumnTextView subclass:#DiffTextView |
|
177
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
14 |
instanceVariableNames:'useColors showSeparators addedColor addedBgColor removedColor |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
15 |
removedBgColor changedColor changedBgColor' |
45 | 16 |
classVariableNames:'' |
17 |
poolDictionaries:'' |
|
18 |
category:'Views-Text' |
|
36 | 19 |
! |
20 |
||
21 |
!DiffTextView class methodsFor:'documentation'! |
|
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
45 | 26 |
All Rights Reserved |
36 | 27 |
|
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
37 |
version |
|
177
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
38 |
^ '$Header: /cvs/stx/stx/libtool/DiffTextView.st,v 1.10 1995-11-16 16:27:16 cg Exp $' |
36 | 39 |
! |
40 |
||
41 |
documentation |
|
42 |
" |
|
45 | 43 |
a view showing diff (see unix manual pages) output in a |
44 |
user-friendly form. |
|
36 | 45 |
The view is created and opened with: |
46 |
||
47 |
d := DiffTextView openOn:text1 and:text2. |
|
48 |
||
49 |
and it will show the differences side-by-side |
|
45 | 50 |
For a real world application, see the ChangesBrowsers |
51 |
compare function. |
|
36 | 52 |
" |
53 |
! ! |
|
54 |
||
45 | 55 |
!DiffTextView class methodsFor:'defaults'! |
56 |
||
57 |
diffCommand |
|
58 |
^ 'diff -b' |
|
59 |
! ! |
|
60 |
||
177
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
61 |
|
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
62 |
!DiffTextView methodsFor:'initialization'! |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
63 |
|
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
64 |
initStyle |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
65 |
super initStyle. |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
66 |
|
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
67 |
showSeparators := false. |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
68 |
|
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
69 |
useColors := ColoredListEntry notNil. |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
70 |
useColors ifTrue:[ |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
71 |
device hasColors ifTrue:[ |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
72 |
addedColor := Color black. |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
73 |
addedBgColor := Color green. |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
74 |
|
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
75 |
removedColor := Color white. |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
76 |
removedBgColor := Color red. |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
77 |
|
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
78 |
changedColor := Color white. |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
79 |
changedBgColor := Color blue. |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
80 |
] ifFalse:[ |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
81 |
addedBgColor := removedBgColor := changedBgColor := Color black. |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
82 |
addedColor := removedColor := changedColor := Color white. |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
83 |
] |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
84 |
]. |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
85 |
|
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
86 |
"Created: 16.11.1995 / 16:59:48 / cg" |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
87 |
! ! |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
88 |
|
36 | 89 |
!DiffTextView methodsFor:'private'! |
90 |
||
91 |
updateListsFrom:text1 and:text2 diffs:diffList |
|
69 | 92 |
"given the two texts in text1 and text2, and the diff-output in diffList, |
93 |
update my views contents" |
|
94 |
||
36 | 95 |
|idx1 idx2 dIdx dEnd state s nr1 nr2 nr3 op entry c l1 l2 any delta| |
96 |
||
97 |
l1 := OrderedCollection new. |
|
98 |
l2 := OrderedCollection new. |
|
99 |
||
100 |
idx1 := 1. |
|
101 |
idx2 := 1. |
|
102 |
||
103 |
dIdx := 1. |
|
104 |
dEnd := diffList size + 1. |
|
105 |
state := #initial. |
|
106 |
[dIdx <= dEnd] whileTrue:[ |
|
45 | 107 |
dIdx == dEnd ifTrue:[ |
108 |
"dummy cleanup entry" |
|
109 |
entry := nil. |
|
110 |
state := #initial. |
|
111 |
] ifFalse:[ |
|
112 |
entry := diffList at:dIdx. |
|
113 |
]. |
|
36 | 114 |
|
45 | 115 |
state == #initial ifTrue:[ |
116 |
"entry is of the form <nr> <op> <offs> [<offs2>]" |
|
36 | 117 |
|
45 | 118 |
" |
119 |
fill up to size difference from previous change |
|
120 |
" |
|
121 |
delta := l1 size - l2 size. |
|
122 |
delta > 0 ifTrue:[ |
|
123 |
delta timesRepeat:[l2 add:nil] |
|
124 |
] ifFalse:[ |
|
125 |
delta < 0 ifTrue:[ |
|
126 |
delta negated timesRepeat:[l1 add:nil] |
|
127 |
] |
|
128 |
]. |
|
36 | 129 |
|
45 | 130 |
" |
131 |
except for the first chunk, add a separating line |
|
132 |
" |
|
133 |
l1 size ~~ 0 ifTrue:[ |
|
177
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
134 |
showSeparators ifTrue:[ |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
135 |
l1 add:'--------'. |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
136 |
l2 add:'--------'. |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
137 |
] |
45 | 138 |
]. |
36 | 139 |
|
45 | 140 |
" |
141 |
in cleanup ? |
|
142 |
" |
|
143 |
entry isNil ifTrue:[ |
|
144 |
nr1 := text1 size + 1. |
|
145 |
nr2 := text2 size + 1. |
|
146 |
state := #finish. |
|
147 |
] ifFalse:[ |
|
148 |
s := ReadStream on:entry. |
|
149 |
nr1 := Integer readFrom:s. |
|
150 |
s peek == $, ifTrue:[ |
|
151 |
s next. |
|
152 |
Integer readFrom:s |
|
153 |
]. |
|
154 |
op := s next. |
|
155 |
nr2 := Integer readFrom:s. |
|
156 |
s peek == $, ifTrue:[ |
|
157 |
s next. |
|
158 |
nr3 := Integer readFrom:s |
|
159 |
] ifFalse:[ |
|
160 |
nr3 := nil |
|
161 |
]. |
|
36 | 162 |
|
45 | 163 |
op == $c ifTrue:[ |
164 |
state := #changed. |
|
165 |
] ifFalse:[ |
|
166 |
op == $a ifTrue:[ |
|
167 |
state := #added. |
|
168 |
] ifFalse:[ |
|
169 |
op == $d ifTrue:[ |
|
170 |
state := #deleted |
|
177
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
171 |
] ifFalse:[ |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
172 |
self halt:'unexpected diff entry'. |
45 | 173 |
] |
174 |
] |
|
175 |
]. |
|
36 | 176 |
|
45 | 177 |
]. |
36 | 178 |
|
177
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
179 |
nr1 print. ' ' print. op print. ' ' print. nr2 print. ' , ' print. nr3 printNL. |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
180 |
|
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
181 |
"/ state == #added ifTrue:[ |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
182 |
"/ l1 add:(text1 at:idx1). |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
183 |
"/ idx1 := idx1 + 1. |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
184 |
"/ ]. |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
185 |
|
45 | 186 |
" |
187 |
copy over unchanged lines |
|
188 |
" |
|
189 |
any := false. |
|
190 |
[idx1 < nr1] whileTrue:[ |
|
177
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
191 |
'< add:' print. idx1 printNL. |
45 | 192 |
l1 add:(text1 at:idx1). |
193 |
idx1 := idx1 + 1. |
|
194 |
any := true. |
|
195 |
]. |
|
196 |
[idx2 < nr2] whileTrue:[ |
|
177
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
197 |
'> add:' print. idx2 printNL. |
45 | 198 |
l2 add:(text2 at:idx2). |
199 |
idx2 := idx2 + 1. |
|
200 |
any := true. |
|
201 |
]. |
|
36 | 202 |
|
177
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
203 |
state == #added ifTrue:[ |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
204 |
l1 add:(text1 at:idx1). |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
205 |
idx1 := idx1 + 1. |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
206 |
]. |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
207 |
state == #deleted ifTrue:[ |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
208 |
l2 add:(text2 at:idx2). |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
209 |
idx2 := idx2 + 1. |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
210 |
]. |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
211 |
|
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
212 |
|
45 | 213 |
" |
214 |
add a separating line, except at end |
|
215 |
" |
|
216 |
any ifTrue:[ |
|
217 |
state ~~ #finish ifTrue:[ |
|
177
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
218 |
showSeparators ifTrue:[ |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
219 |
l1 add:'--------'. |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
220 |
l2 add:'--------'. |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
221 |
] |
45 | 222 |
] |
223 |
]. |
|
36 | 224 |
|
45 | 225 |
] ifFalse:[ |
226 |
state == #changed ifTrue:[ |
|
227 |
(entry at:1) == $< ifTrue:[ |
|
177
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
228 |
useColors ifTrue:[ |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
229 |
l1 add:(ColoredListEntry string:(text1 at:idx1) foregroundColor:changedColor backgroundColor:changedBgColor). |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
230 |
] ifFalse:[ |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
231 |
l1 add:(text1 at:idx1). |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
232 |
]. |
45 | 233 |
idx1 := idx1 + 1 |
234 |
] ifFalse:[ |
|
235 |
(entry at:1) == $> ifTrue:[ |
|
177
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
236 |
useColors ifTrue:[ |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
237 |
l2 add:(ColoredListEntry string:(text2 at:idx2) foregroundColor:changedColor backgroundColor:changedBgColor) |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
238 |
] ifFalse:[ |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
239 |
l2 add:(text2 at:idx2). |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
240 |
]. |
45 | 241 |
idx2 := idx2 + 1 |
242 |
] ifFalse:[ |
|
243 |
(entry at:1) == $- ifTrue:[ |
|
244 |
] ifFalse:[ |
|
245 |
state := #initial. |
|
246 |
dIdx := dIdx - 1 |
|
247 |
] |
|
248 |
] |
|
249 |
] |
|
250 |
] ifFalse:[ |
|
251 |
state == #added ifTrue:[ |
|
252 |
(entry at:1) == $> ifTrue:[ |
|
177
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
253 |
useColors ifTrue:[ |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
254 |
l2 add:(ColoredListEntry string:(text2 at:idx2) foregroundColor:addedColor backgroundColor:addedBgColor ) |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
255 |
] ifFalse:[ |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
256 |
l2 add:(text2 at:idx2). |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
257 |
]. |
45 | 258 |
idx2 := idx2 + 1. |
259 |
l1 add:nil |
|
260 |
] ifFalse:[ |
|
261 |
state := #initial. |
|
262 |
dIdx := dIdx - 1 |
|
263 |
] |
|
264 |
] ifFalse:[ |
|
265 |
state == #deleted ifTrue:[ |
|
266 |
(entry at:1) == $< ifTrue:[ |
|
177
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
267 |
useColors ifTrue:[ |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
268 |
l1 add:(ColoredListEntry string:(text1 at:idx1) foregroundColor:removedColor backgroundColor:removedBgColor ). |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
269 |
] ifFalse:[ |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
270 |
l1 add:(text1 at:idx1). |
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
271 |
]. |
45 | 272 |
idx1 := idx1 + 1. |
273 |
l2 add:nil |
|
274 |
] ifFalse:[ |
|
275 |
state := #initial. |
|
276 |
dIdx := dIdx - 1 |
|
277 |
] |
|
278 |
] |
|
279 |
"must be in finish otherwise" |
|
280 |
] |
|
281 |
] |
|
282 |
]. |
|
283 |
dIdx := dIdx + 1 |
|
36 | 284 |
]. |
285 |
[l1 size < l2 size] whileTrue:[ |
|
45 | 286 |
l1 add:''. |
36 | 287 |
]. |
288 |
[l2 size < l1 size] whileTrue:[ |
|
45 | 289 |
l2 add:''. |
36 | 290 |
]. |
291 |
textView1 list:l1. |
|
292 |
textView2 list:l2 |
|
177
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
293 |
|
36c5c99b9ffb
fixed off-by-one error / added color marking of changes
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
294 |
"Modified: 16.11.1995 / 17:09:35 / cg" |
36 | 295 |
! ! |
296 |
||
297 |
!DiffTextView methodsFor:'accessing'! |
|
298 |
||
299 |
text1:t1 text2:t2 |
|
110 | 300 |
|tmpFile1 tmpFile2 name1 tmpName2 stream line text1 text2 diffList pidString| |
36 | 301 |
|
69 | 302 |
text1 := t1 asStringCollection. |
303 |
text2 := t2 asStringCollection. |
|
36 | 304 |
|
305 |
" |
|
306 |
save them texts in two temporary files ... |
|
307 |
" |
|
69 | 308 |
tmpFile1 := Filename newTemporary. |
309 |
stream := tmpFile1 writeStream. |
|
36 | 310 |
text1 do:[:line | |
45 | 311 |
stream nextPutAll:line; cr |
36 | 312 |
]. |
313 |
stream close. |
|
314 |
||
69 | 315 |
tmpFile2 := Filename newTemporary. |
316 |
stream := tmpFile2 writeStream. |
|
36 | 317 |
text2 do:[:line | |
45 | 318 |
stream nextPutAll:line; cr |
36 | 319 |
]. |
320 |
stream close. |
|
321 |
||
322 |
" |
|
323 |
start diff on it ... |
|
324 |
" |
|
45 | 325 |
stream := PipeStream |
326 |
readingFrom:self class diffCommand , ' ' , |
|
69 | 327 |
tmpFile1 asString, ' ' , tmpFile2 asString. |
36 | 328 |
stream isNil ifTrue:[ |
45 | 329 |
self error:'cannot execute diff'. |
330 |
text1 := text2 := nil. |
|
331 |
] ifFalse:[ |
|
332 |
diffList := OrderedCollection new. |
|
333 |
[stream atEnd] whileFalse:[ |
|
334 |
line := stream nextLine. |
|
335 |
line notNil ifTrue:[diffList add:line] |
|
336 |
]. |
|
337 |
stream close. |
|
36 | 338 |
]. |
45 | 339 |
|
69 | 340 |
tmpFile1 delete. |
341 |
tmpFile2 delete. |
|
36 | 342 |
|
343 |
self updateListsFrom:text1 and:text2 diffs:diffList |
|
344 |
||
345 |
" |
|
346 |
|v| |
|
347 |
||
348 |
v := HVScrollableView for:DiffTextView. |
|
349 |
v scrolledView text1:('../libview/Color.st' asFilename readStream contents) |
|
45 | 350 |
text2:('../libview/Color.st.old' asFilename readStream contents). |
36 | 351 |
v open |
352 |
" |
|
353 |
||
354 |
" |
|
355 |
|v t1 t2| |
|
356 |
||
357 |
t1 := ' |
|
358 |
one |
|
359 |
two |
|
360 |
three |
|
361 |
four |
|
362 |
'. |
|
363 |
t2 := ' |
|
364 |
one |
|
365 |
two-a |
|
366 |
two-b |
|
367 |
three |
|
368 |
three-b |
|
369 |
four |
|
370 |
'. |
|
371 |
||
372 |
v := DiffTextView new. |
|
373 |
v text1:t1 text2:t2. |
|
69 | 374 |
v open |
36 | 375 |
" |
376 |
! ! |