53 |
54 |
54 !DiffTextView class methodsFor:'defaults'! |
55 !DiffTextView class methodsFor:'defaults'! |
55 |
56 |
56 diffCommand |
57 diffCommand |
57 ^ 'diff -b' |
58 ^ 'diff -b' |
|
59 ! ! |
|
60 |
|
61 |
|
62 !DiffTextView methodsFor:'initialization'! |
|
63 |
|
64 initStyle |
|
65 super initStyle. |
|
66 |
|
67 showSeparators := false. |
|
68 |
|
69 useColors := ColoredListEntry notNil. |
|
70 useColors ifTrue:[ |
|
71 device hasColors ifTrue:[ |
|
72 addedColor := Color black. |
|
73 addedBgColor := Color green. |
|
74 |
|
75 removedColor := Color white. |
|
76 removedBgColor := Color red. |
|
77 |
|
78 changedColor := Color white. |
|
79 changedBgColor := Color blue. |
|
80 ] ifFalse:[ |
|
81 addedBgColor := removedBgColor := changedBgColor := Color black. |
|
82 addedColor := removedColor := changedColor := Color white. |
|
83 ] |
|
84 ]. |
|
85 |
|
86 "Created: 16.11.1995 / 16:59:48 / cg" |
58 ! ! |
87 ! ! |
59 |
88 |
60 !DiffTextView methodsFor:'private'! |
89 !DiffTextView methodsFor:'private'! |
61 |
90 |
62 updateListsFrom:text1 and:text2 diffs:diffList |
91 updateListsFrom:text1 and:text2 diffs:diffList |
132 op == $c ifTrue:[ |
163 op == $c ifTrue:[ |
133 state := #changed. |
164 state := #changed. |
134 ] ifFalse:[ |
165 ] ifFalse:[ |
135 op == $a ifTrue:[ |
166 op == $a ifTrue:[ |
136 state := #added. |
167 state := #added. |
137 l1 add:(text1 at:idx1). |
|
138 idx1 := idx1 + 1. |
|
139 ] ifFalse:[ |
168 ] ifFalse:[ |
140 op == $d ifTrue:[ |
169 op == $d ifTrue:[ |
141 state := #deleted |
170 state := #deleted |
|
171 ] ifFalse:[ |
|
172 self halt:'unexpected diff entry'. |
142 ] |
173 ] |
143 ] |
174 ] |
144 ]. |
175 ]. |
145 |
176 |
146 ]. |
177 ]. |
147 |
178 |
|
179 nr1 print. ' ' print. op print. ' ' print. nr2 print. ' , ' print. nr3 printNL. |
|
180 |
|
181 "/ state == #added ifTrue:[ |
|
182 "/ l1 add:(text1 at:idx1). |
|
183 "/ idx1 := idx1 + 1. |
|
184 "/ ]. |
|
185 |
148 " |
186 " |
149 copy over unchanged lines |
187 copy over unchanged lines |
150 " |
188 " |
151 any := false. |
189 any := false. |
152 [idx1 < nr1] whileTrue:[ |
190 [idx1 < nr1] whileTrue:[ |
|
191 '< add:' print. idx1 printNL. |
153 l1 add:(text1 at:idx1). |
192 l1 add:(text1 at:idx1). |
154 idx1 := idx1 + 1. |
193 idx1 := idx1 + 1. |
155 any := true. |
194 any := true. |
156 ]. |
195 ]. |
157 [idx2 < nr2] whileTrue:[ |
196 [idx2 < nr2] whileTrue:[ |
|
197 '> add:' print. idx2 printNL. |
158 l2 add:(text2 at:idx2). |
198 l2 add:(text2 at:idx2). |
159 idx2 := idx2 + 1. |
199 idx2 := idx2 + 1. |
160 any := true. |
200 any := true. |
161 ]. |
201 ]. |
162 |
202 |
|
203 state == #added ifTrue:[ |
|
204 l1 add:(text1 at:idx1). |
|
205 idx1 := idx1 + 1. |
|
206 ]. |
|
207 state == #deleted ifTrue:[ |
|
208 l2 add:(text2 at:idx2). |
|
209 idx2 := idx2 + 1. |
|
210 ]. |
|
211 |
|
212 |
163 " |
213 " |
164 add a separating line, except at end |
214 add a separating line, except at end |
165 " |
215 " |
166 any ifTrue:[ |
216 any ifTrue:[ |
167 state ~~ #finish ifTrue:[ |
217 state ~~ #finish ifTrue:[ |
168 l1 add:'--------'. |
218 showSeparators ifTrue:[ |
169 l2 add:'--------'. |
219 l1 add:'--------'. |
|
220 l2 add:'--------'. |
|
221 ] |
170 ] |
222 ] |
171 ]. |
223 ]. |
172 |
224 |
173 ] ifFalse:[ |
225 ] ifFalse:[ |
174 state == #changed ifTrue:[ |
226 state == #changed ifTrue:[ |
175 (entry at:1) == $< ifTrue:[ |
227 (entry at:1) == $< ifTrue:[ |
176 l1 add:(text1 at:idx1). |
228 useColors ifTrue:[ |
|
229 l1 add:(ColoredListEntry string:(text1 at:idx1) foregroundColor:changedColor backgroundColor:changedBgColor). |
|
230 ] ifFalse:[ |
|
231 l1 add:(text1 at:idx1). |
|
232 ]. |
177 idx1 := idx1 + 1 |
233 idx1 := idx1 + 1 |
178 ] ifFalse:[ |
234 ] ifFalse:[ |
179 (entry at:1) == $> ifTrue:[ |
235 (entry at:1) == $> ifTrue:[ |
180 l2 add:(text2 at:idx2). |
236 useColors ifTrue:[ |
|
237 l2 add:(ColoredListEntry string:(text2 at:idx2) foregroundColor:changedColor backgroundColor:changedBgColor) |
|
238 ] ifFalse:[ |
|
239 l2 add:(text2 at:idx2). |
|
240 ]. |
181 idx2 := idx2 + 1 |
241 idx2 := idx2 + 1 |
182 ] ifFalse:[ |
242 ] ifFalse:[ |
183 (entry at:1) == $- ifTrue:[ |
243 (entry at:1) == $- ifTrue:[ |
184 ] ifFalse:[ |
244 ] ifFalse:[ |
185 state := #initial. |
245 state := #initial. |
188 ] |
248 ] |
189 ] |
249 ] |
190 ] ifFalse:[ |
250 ] ifFalse:[ |
191 state == #added ifTrue:[ |
251 state == #added ifTrue:[ |
192 (entry at:1) == $> ifTrue:[ |
252 (entry at:1) == $> ifTrue:[ |
193 l2 add:(text2 at:idx2). |
253 useColors ifTrue:[ |
|
254 l2 add:(ColoredListEntry string:(text2 at:idx2) foregroundColor:addedColor backgroundColor:addedBgColor ) |
|
255 ] ifFalse:[ |
|
256 l2 add:(text2 at:idx2). |
|
257 ]. |
194 idx2 := idx2 + 1. |
258 idx2 := idx2 + 1. |
195 l1 add:nil |
259 l1 add:nil |
196 ] ifFalse:[ |
260 ] ifFalse:[ |
197 state := #initial. |
261 state := #initial. |
198 dIdx := dIdx - 1 |
262 dIdx := dIdx - 1 |
199 ] |
263 ] |
200 ] ifFalse:[ |
264 ] ifFalse:[ |
201 state == #deleted ifTrue:[ |
265 state == #deleted ifTrue:[ |
202 (entry at:1) == $< ifTrue:[ |
266 (entry at:1) == $< ifTrue:[ |
203 l1 add:(text1 at:idx1). |
267 useColors ifTrue:[ |
|
268 l1 add:(ColoredListEntry string:(text1 at:idx1) foregroundColor:removedColor backgroundColor:removedBgColor ). |
|
269 ] ifFalse:[ |
|
270 l1 add:(text1 at:idx1). |
|
271 ]. |
204 idx1 := idx1 + 1. |
272 idx1 := idx1 + 1. |
205 l2 add:nil |
273 l2 add:nil |
206 ] ifFalse:[ |
274 ] ifFalse:[ |
207 state := #initial. |
275 state := #initial. |
208 dIdx := dIdx - 1 |
276 dIdx := dIdx - 1 |