author | Claus Gittinger <cg@exept.de> |
Fri, 12 Jun 2009 11:13:25 +0200 | |
changeset 8647 | 136a25126878 |
parent 8545 | e8ab04e3722d |
child 8676 | 7fad1da68ff9 |
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 |
" |
|
2716
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
12 |
"{ Package: 'stx:libtool' }" |
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
13 |
|
36 | 14 |
TwoColumnTextView subclass:#DiffTextView |
313
c143d37be2e9
lines which differ only in blanks (indent) are shown light-blue
Claus Gittinger <cg@exept.de>
parents:
242
diff
changeset
|
15 |
instanceVariableNames:'useColors showSeparators addedColor addedBgColor removedColor |
c143d37be2e9
lines which differ only in blanks (indent) are shown light-blue
Claus Gittinger <cg@exept.de>
parents:
242
diff
changeset
|
16 |
removedBgColor changedColor changedBgColor changedSpacesOnlyColor |
507 | 17 |
changedSpacesOnlyBgColor diffLineNumbers' |
1440
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
18 |
classVariableNames:'DiffCommandTemplate' |
313
c143d37be2e9
lines which differ only in blanks (indent) are shown light-blue
Claus Gittinger <cg@exept.de>
parents:
242
diff
changeset
|
19 |
poolDictionaries:'' |
c143d37be2e9
lines which differ only in blanks (indent) are shown light-blue
Claus Gittinger <cg@exept.de>
parents:
242
diff
changeset
|
20 |
category:'Views-Text' |
36 | 21 |
! |
22 |
||
23 |
!DiffTextView class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
45 | 28 |
All Rights Reserved |
36 | 29 |
|
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
39 |
documentation |
|
40 |
" |
|
507 | 41 |
a view showing diff output (see unix manual pages) |
42 |
in a user-friendly form. |
|
36 | 43 |
The view is created and opened with: |
44 |
||
507 | 45 |
d := DiffTextView openOn:text1 and:text2 |
46 |
||
47 |
or: |
|
48 |
d := DiffTextView openOn:text1 label:l1 |
|
49 |
and:text2 label:l2 |
|
36 | 50 |
|
507 | 51 |
and it will show the differences side-by-side. |
533 | 52 |
|
2240 | 53 |
The colors mean: |
54 |
red - removed |
|
55 |
green - added |
|
56 |
blue - changed |
|
57 |
light-blue changed, but not really (i.e. spaces only) |
|
58 |
||
59 |
For a real world application and use of this widget, |
|
60 |
see the ChangesBrowsers `compare', |
|
61 |
or the browsers 'compare with repository' functions. |
|
507 | 62 |
|
2246
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
63 |
Notice: |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
64 |
A diff command must be available on your system and found |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
65 |
along the PATH (you will see a warning on stderr, if there is no diff). |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
66 |
We use gnu-diff. |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
67 |
|
507 | 68 |
[see also:] |
1276 | 69 |
TextView EditTextView Diff3TextView |
519 | 70 |
|
71 |
[author:] |
|
72 |
Claus Gittinger |
|
36 | 73 |
" |
1276 | 74 |
! |
75 |
||
76 |
examples |
|
77 |
" |
|
78 |
[exBegin] |
|
79 |
|text1 text2| |
|
80 |
||
81 |
text1 := 'hello world |
|
82 |
here is some difference |
|
83 |
more text |
|
84 |
this line has been removed |
|
85 |
more text |
|
86 |
more text |
|
87 |
'. |
|
88 |
||
89 |
text2 := 'hello world |
|
90 |
where is the difference ? |
|
91 |
more text |
|
92 |
more text |
|
93 |
more text |
|
94 |
this line has been added |
|
95 |
'. |
|
96 |
||
97 |
DiffTextView openOn:text1 label:'text1' |
|
98 |
and:text2 label:'text2' |
|
99 |
[exEnd] |
|
100 |
" |
|
242 | 101 |
! ! |
36 | 102 |
|
2716
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
103 |
!DiffTextView class methodsFor:'instance creation'! |
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
104 |
|
2948
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
105 |
openOnClass:classA labelA:lblA andClass:classB labelB:lblB title:title ifSame:sameAction |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
106 |
"provided for protocol compatibility with the VersionDiffBrowser; |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
107 |
actually, the classes are ignored here" |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
108 |
|
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
109 |
|v aStream sourceA sourceB| |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
110 |
|
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
111 |
aStream := '' writeStream. |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
112 |
Method flushSourceStreamCache. |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
113 |
classA fileOutOn:aStream withTimeStamp:false. |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
114 |
sourceA := aStream contents asString. |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
115 |
|
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
116 |
aStream := '' writeStream. |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
117 |
Method flushSourceStreamCache. |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
118 |
classB fileOutOn:aStream withTimeStamp:false. |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
119 |
sourceB := aStream contents asString. |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
120 |
|
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
121 |
v := self |
3755 | 122 |
openOn:sourceA label:lblA |
123 |
and:sourceB label:lblB. |
|
8334 | 124 |
v topView label:title. |
2948
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
125 |
^ v |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
126 |
! |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
127 |
|
2716
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
128 |
openOnClass:someClass labelA:lblA sourceA:sourceA labelB:lblB sourceB:sourceB |
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
129 |
"provided for protocol compatibility with the VersionDiffBrowser; |
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
130 |
actually, the class is ignored here" |
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
131 |
|
3755 | 132 |
^ self |
133 |
openOnClass:someClass |
|
134 |
labelA:lblA sourceA:sourceA |
|
135 |
labelB:lblB sourceB:sourceB |
|
136 |
title:'Comparing ' , someClass name. |
|
2716
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
137 |
! |
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
138 |
|
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
139 |
openOnClass:someClass labelA:lblA sourceA:sourceA labelB:lblB sourceB:sourceB title:title |
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
140 |
"provided for protocol compatibility with the VersionDiffBrowser; |
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
141 |
actually, the class is ignored here" |
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
142 |
|
2848 | 143 |
^ self |
3755 | 144 |
openOnClass:someClass |
145 |
labelA:lblA sourceA:sourceA |
|
146 |
labelB:lblB sourceB:sourceB |
|
147 |
title:title ifSame:nil |
|
2848 | 148 |
! |
149 |
||
150 |
openOnClass:someClass labelA:lblA sourceA:sourceA labelB:lblB sourceB:sourceB title:title ifSame:sameAction |
|
151 |
"provided for protocol compatibility with the VersionDiffBrowser; |
|
152 |
actually, the class is ignored here" |
|
153 |
||
2716
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
154 |
|v| |
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
155 |
|
2750 | 156 |
v := self |
3755 | 157 |
openOn:sourceA label:lblA |
158 |
and:sourceB label:lblB. |
|
3050 | 159 |
v topView label:title. |
2716
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
160 |
^ v |
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
161 |
! ! |
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
162 |
|
45 | 163 |
!DiffTextView class methodsFor:'defaults'! |
164 |
||
165 |
diffCommand |
|
1440
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
166 |
"return the diff-command (with argument placeHolders)" |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
167 |
|
2246
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
168 |
DiffCommandTemplate isNil ifTrue:[ |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
169 |
OperatingSystem isMSDOSlike ifTrue:[ |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
170 |
(OperatingSystem canExecuteCommand:'diff') ifFalse:[ |
6397 | 171 |
'DiffTextView [warning]: no diff command found (please download and unzip "UnxUtils.zip" from "unxutils.sourceforge.net")' infoPrintCR. |
2246
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
172 |
^ nil |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
173 |
]. |
6231 | 174 |
^ 'diff %1 %2' |
175 |
]. |
|
176 |
^ 'diff -b %1 %2' |
|
1440
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
177 |
]. |
2246
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
178 |
^ DiffCommandTemplate |
1440
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
179 |
|
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
180 |
"Modified: / 30.1.1998 / 12:12:49 / cg" |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
181 |
! |
507 | 182 |
|
1440
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
183 |
diffCommandTemplate:aCommandTemplateString |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
184 |
"set the diff-command template" |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
185 |
|
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
186 |
OperatingSystem isMSDOSlike ifTrue:[ |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
187 |
^ DiffCommandTemplate ? 'diff %1 %2' |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
188 |
]. |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
189 |
|
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
190 |
^ DiffCommandTemplate ? 'diff -b %1 %2' |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
191 |
|
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
192 |
"Modified: / 30.1.1998 / 12:10:34 / cg" |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
193 |
"Created: / 30.1.1998 / 12:12:37 / cg" |
45 | 194 |
! ! |
195 |
||
36 | 196 |
!DiffTextView methodsFor:'accessing'! |
197 |
||
198 |
text1:t1 text2:t2 |
|
1440
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
199 |
"set the two texts which are to be diffed; |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
200 |
execute DiffCommand and update the two textViews." |
507 | 201 |
|
6577
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
202 |
|text1 text2 diffList| |
36 | 203 |
|
7768 | 204 |
text1 := (t1 copyReplaceAll:Character return with:Character cr) asStringCollection. |
205 |
text2 := (t2 copyReplaceAll:Character return with:Character cr) asStringCollection. |
|
36 | 206 |
|
7768 | 207 |
diffList := self diffListFor:text1 and:text2. |
36 | 208 |
|
209 |
self updateListsFrom:text1 and:text2 diffs:diffList |
|
210 |
||
211 |
" |
|
212 |
|v| |
|
213 |
||
214 |
v := HVScrollableView for:DiffTextView. |
|
215 |
v scrolledView text1:('../libview/Color.st' asFilename readStream contents) |
|
507 | 216 |
text2:('../libview/Color.st.old' asFilename readStream contents). |
36 | 217 |
v open |
218 |
" |
|
219 |
||
220 |
" |
|
221 |
|v t1 t2| |
|
222 |
||
223 |
t1 := ' |
|
224 |
one |
|
225 |
two |
|
226 |
three |
|
227 |
four |
|
228 |
'. |
|
229 |
t2 := ' |
|
230 |
one |
|
231 |
two-a |
|
232 |
two-b |
|
233 |
three |
|
234 |
three-b |
|
235 |
four |
|
236 |
'. |
|
237 |
||
238 |
v := DiffTextView new. |
|
239 |
v text1:t1 text2:t2. |
|
69 | 240 |
v open |
36 | 241 |
" |
507 | 242 |
|
7768 | 243 |
"Modified: / 27-03-2007 / 12:06:46 / cg" |
36 | 244 |
! ! |
183 | 245 |
|
246 |
!DiffTextView methodsFor:'initialization'! |
|
247 |
||
2246
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
248 |
addNextPreviousButtons |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
249 |
super addNextPreviousButtons. |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
250 |
nextPrevButtonPanel beVisible. |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
251 |
! |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
252 |
|
183 | 253 |
initStyle |
254 |
super initStyle. |
|
255 |
||
256 |
showSeparators := false. |
|
257 |
||
544
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
258 |
(useColors := device hasColors) ifTrue:[ |
2240 | 259 |
addedColor := Color white. |
260 |
addedBgColor := Color red. |
|
183 | 261 |
|
2240 | 262 |
removedColor := Color black. |
263 |
removedBgColor := Color green. |
|
183 | 264 |
|
544
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
265 |
changedColor := Color white. |
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
266 |
changedBgColor := Color blue. |
313
c143d37be2e9
lines which differ only in blanks (indent) are shown light-blue
Claus Gittinger <cg@exept.de>
parents:
242
diff
changeset
|
267 |
|
544
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
268 |
changedSpacesOnlyColor := Color white. |
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
269 |
changedSpacesOnlyBgColor := Color blue lightened. |
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
270 |
] ifFalse:[ |
623 | 271 |
showSeparators := true. |
272 |
||
273 |
(useColors := device hasGreyscales) ifTrue:[ |
|
274 |
addedBgColor := removedBgColor := changedBgColor := Color grey:80. |
|
275 |
addedColor := removedColor := changedColor := Color black. |
|
276 |
] ifFalse:[ |
|
277 |
addedBgColor := removedBgColor := changedBgColor := Color black. |
|
278 |
addedColor := removedColor := changedColor := Color white. |
|
279 |
]. |
|
280 |
||
281 |
changedSpacesOnlyColor := Color white. |
|
282 |
changedSpacesOnlyBgColor := Color black. |
|
183 | 283 |
]. |
284 |
||
285 |
"Created: 16.11.1995 / 16:59:48 / cg" |
|
623 | 286 |
"Modified: 14.6.1996 / 16:14:39 / cg" |
183 | 287 |
! ! |
288 |
||
289 |
!DiffTextView methodsFor:'private'! |
|
290 |
||
6577
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
291 |
diffListFor:text1 and:text2 |
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
292 |
"set the two texts which are to be diffed; |
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
293 |
execute DiffCommand and update the two textViews." |
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
294 |
|
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
295 |
|tmpFile1 tmpFile2 stream line |
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
296 |
diffList diffTemplate diffCmd| |
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
297 |
|
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
298 |
diffTemplate := self class diffCommand. |
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
299 |
diffTemplate isNil ifTrue:[ |
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
300 |
"/ self warn:'no diff command available'. |
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
301 |
^ nil |
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
302 |
]. |
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
303 |
|
7602
cf179604a91b
Quick compare if both strings are the same
Stefan Vogel <sv@exept.de>
parents:
7526
diff
changeset
|
304 |
text1 = text2 ifTrue:[ |
cf179604a91b
Quick compare if both strings are the same
Stefan Vogel <sv@exept.de>
parents:
7526
diff
changeset
|
305 |
"no diff" |
cf179604a91b
Quick compare if both strings are the same
Stefan Vogel <sv@exept.de>
parents:
7526
diff
changeset
|
306 |
^ '' |
cf179604a91b
Quick compare if both strings are the same
Stefan Vogel <sv@exept.de>
parents:
7526
diff
changeset
|
307 |
]. |
cf179604a91b
Quick compare if both strings are the same
Stefan Vogel <sv@exept.de>
parents:
7526
diff
changeset
|
308 |
|
6577
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
309 |
" |
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
310 |
save them texts in two temporary files ... |
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
311 |
" |
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
312 |
self save:text1 as:(tmpFile1 := Filename newTemporary). |
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
313 |
self save:text2 as:(tmpFile2 := Filename newTemporary). |
8545 | 314 |
[ |
315 |
" |
|
316 |
start diff on it ... |
|
317 |
" |
|
318 |
diffCmd := diffTemplate |
|
319 |
bindWith:tmpFile1 asString |
|
320 |
with:tmpFile2 asString. |
|
6577
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
321 |
|
8545 | 322 |
stream := PipeStream readingFrom:diffCmd. |
323 |
stream isNil ifTrue:[ |
|
324 |
stream := PipeStream readingFrom:('support' , Filename separator , diffCmd). |
|
325 |
]. |
|
326 |
stream isNil ifTrue:[ |
|
327 |
self error:'cannot execute diff' mayProceed:true. |
|
328 |
^ nil. |
|
329 |
]. |
|
6577
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
330 |
|
8545 | 331 |
diffList := OrderedCollection new. |
8647 | 332 |
(stream readWaitWithTimeout:5) ifTrue:[ |
8545 | 333 |
"/ timeout |
334 |
self error:'cannot execute diff (timeout)' mayProceed:true. |
|
335 |
^ nil. |
|
336 |
]. |
|
337 |
||
338 |
[stream atEnd] whileFalse:[ |
|
339 |
line := stream nextLine. |
|
340 |
line notNil ifTrue:[diffList add:line] |
|
341 |
]. |
|
342 |
stream close. |
|
343 |
^ diffList |
|
344 |
] ensure:[ |
|
6577
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
345 |
tmpFile1 delete. |
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
346 |
tmpFile2 delete. |
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
347 |
]. |
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
348 |
! |
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
349 |
|
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
350 |
save:text as:filename |
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
351 |
|stream| |
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
352 |
|
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
353 |
stream := filename writeStream. |
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
354 |
text do:[:line | |
7177 | 355 |
|lOut| |
356 |
||
8371 | 357 |
line notEmptyOrNil ifTrue:[ |
7177 | 358 |
lOut := line. |
6577
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
359 |
(line includes:Character return) ifTrue: [ |
7177 | 360 |
(line endsWith:Character return) ifTrue:[ |
361 |
lOut := line copyWithoutLast:1. |
|
362 |
] ifFalse:[ |
|
8209 | 363 |
self error:'oops - funny line (includes returns) in text' mayProceed:true. |
7177 | 364 |
] |
6577
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
365 |
]. |
7526
616823c6a3da
care for 16bit string which isn't
Claus Gittinger <cg@exept.de>
parents:
7177
diff
changeset
|
366 |
lOut bitsPerCharacter > 8 ifTrue:[ |
616823c6a3da
care for 16bit string which isn't
Claus Gittinger <cg@exept.de>
parents:
7177
diff
changeset
|
367 |
(lOut first = (Character value:16rFEFF)) ifTrue:[ |
616823c6a3da
care for 16bit string which isn't
Claus Gittinger <cg@exept.de>
parents:
7177
diff
changeset
|
368 |
lOut := (lOut copyFrom:2) asSingleByteStringIfPossible. |
616823c6a3da
care for 16bit string which isn't
Claus Gittinger <cg@exept.de>
parents:
7177
diff
changeset
|
369 |
]. |
8517
cc7558e6bda0
convert saved diff-text-file to 8 bit
Claus Gittinger <cg@exept.de>
parents:
8371
diff
changeset
|
370 |
lOut bitsPerCharacter > 8 ifTrue:[ |
cc7558e6bda0
convert saved diff-text-file to 8 bit
Claus Gittinger <cg@exept.de>
parents:
8371
diff
changeset
|
371 |
lOut := lOut collect:[:ch | ch bitsPerCharacter > 8 |
cc7558e6bda0
convert saved diff-text-file to 8 bit
Claus Gittinger <cg@exept.de>
parents:
8371
diff
changeset
|
372 |
ifTrue:[ Character value:16rFF ] |
cc7558e6bda0
convert saved diff-text-file to 8 bit
Claus Gittinger <cg@exept.de>
parents:
8371
diff
changeset
|
373 |
ifFalse:[ ch ]]. |
cc7558e6bda0
convert saved diff-text-file to 8 bit
Claus Gittinger <cg@exept.de>
parents:
8371
diff
changeset
|
374 |
lOut := lOut asSingleByteStringIfPossible. |
cc7558e6bda0
convert saved diff-text-file to 8 bit
Claus Gittinger <cg@exept.de>
parents:
8371
diff
changeset
|
375 |
]. |
7526
616823c6a3da
care for 16bit string which isn't
Claus Gittinger <cg@exept.de>
parents:
7177
diff
changeset
|
376 |
]. |
7177 | 377 |
stream nextPutAll:lOut. |
6577
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
378 |
]. |
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
379 |
stream cr |
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
380 |
]. |
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
381 |
stream close. |
7526
616823c6a3da
care for 16bit string which isn't
Claus Gittinger <cg@exept.de>
parents:
7177
diff
changeset
|
382 |
|
8371 | 383 |
"Modified: / 22-10-2008 / 17:52:52 / cg" |
6577
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
384 |
! |
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
385 |
|
183 | 386 |
updateListsFrom:text1 and:text2 diffs:diffList |
387 |
"given the two texts in text1 and text2, and the diff-output in diffList, |
|
388 |
update my views contents" |
|
389 |
||
390 |
|idx1 idx2 dIdx dEnd state s nr1 nr2 nr3 op entry c l1 l2 any delta |
|
2260
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
391 |
textView1 textView2 s1 s2 line1 line2| |
183 | 392 |
|
507 | 393 |
diffLineNumbers := OrderedCollection new. |
394 |
||
183 | 395 |
textView1 := textViews at:1. |
396 |
textView2 := textViews at:2. |
|
397 |
||
398 |
l1 := OrderedCollection new. |
|
399 |
l2 := OrderedCollection new. |
|
400 |
||
4413 | 401 |
diffList size == 1 ifTrue:[ |
402 |
textView1 list:diffList. |
|
403 |
textView2 list:diffList. |
|
404 |
^ self. |
|
405 |
]. |
|
406 |
||
183 | 407 |
idx1 := 1. |
408 |
idx2 := 1. |
|
409 |
||
410 |
dIdx := 1. |
|
411 |
dEnd := diffList size + 1. |
|
412 |
state := #initial. |
|
413 |
[dIdx <= dEnd] whileTrue:[ |
|
414 |
dIdx == dEnd ifTrue:[ |
|
415 |
"dummy cleanup entry" |
|
416 |
entry := nil. |
|
417 |
state := #initial. |
|
418 |
] ifFalse:[ |
|
419 |
entry := diffList at:dIdx. |
|
420 |
]. |
|
421 |
||
422 |
state == #initial ifTrue:[ |
|
423 |
"entry is of the form <nr> <op> <offs> [<offs2>]" |
|
424 |
||
425 |
" |
|
426 |
fill up to size difference from previous change |
|
427 |
" |
|
428 |
delta := l1 size - l2 size. |
|
429 |
delta > 0 ifTrue:[ |
|
430 |
delta timesRepeat:[l2 add:nil] |
|
431 |
] ifFalse:[ |
|
432 |
delta < 0 ifTrue:[ |
|
433 |
delta negated timesRepeat:[l1 add:nil] |
|
434 |
] |
|
435 |
]. |
|
436 |
||
437 |
" |
|
438 |
except for the first chunk, add a separating line |
|
439 |
" |
|
440 |
l1 size ~~ 0 ifTrue:[ |
|
441 |
showSeparators ifTrue:[ |
|
442 |
l1 add:'--------'. |
|
443 |
l2 add:'--------'. |
|
444 |
] |
|
445 |
]. |
|
446 |
" |
|
447 |
in cleanup ? |
|
448 |
" |
|
449 |
entry isNil ifTrue:[ |
|
450 |
nr1 := text1 size + 1. |
|
451 |
nr2 := text2 size + 1. |
|
452 |
state := #finish. |
|
453 |
] ifFalse:[ |
|
507 | 454 |
diffLineNumbers add:l1 size. |
455 |
||
183 | 456 |
s := ReadStream on:entry. |
457 |
nr1 := Integer readFrom:s. |
|
458 |
s peek == $, ifTrue:[ |
|
459 |
s next. |
|
460 |
Integer readFrom:s |
|
461 |
]. |
|
462 |
op := s next. |
|
463 |
nr2 := Integer readFrom:s. |
|
464 |
s peek == $, ifTrue:[ |
|
465 |
s next. |
|
466 |
nr3 := Integer readFrom:s |
|
467 |
] ifFalse:[ |
|
468 |
nr3 := nil |
|
469 |
]. |
|
470 |
||
471 |
op == $c ifTrue:[ |
|
472 |
state := #changed. |
|
473 |
] ifFalse:[ |
|
2246
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
474 |
(op == $a) ifTrue:[ |
183 | 475 |
state := #added. |
476 |
] ifFalse:[ |
|
477 |
op == $d ifTrue:[ |
|
478 |
state := #deleted |
|
479 |
] ifFalse:[ |
|
480 |
self halt:'unexpected diff entry'. |
|
481 |
] |
|
482 |
] |
|
483 |
]. |
|
484 |
||
485 |
]. |
|
486 |
||
487 |
"/ nr1 print. ' ' print. op print. ' ' print. nr2 print. ' , ' print. nr3 printNL. |
|
488 |
||
489 |
" |
|
490 |
copy over unchanged lines |
|
491 |
" |
|
492 |
any := false. |
|
493 |
[idx1 < nr1] whileTrue:[ |
|
494 |
"/ '< add:' print. idx1 printNL. |
|
495 |
l1 add:(text1 at:idx1). |
|
496 |
idx1 := idx1 + 1. |
|
497 |
any := true. |
|
498 |
]. |
|
499 |
[idx2 < nr2] whileTrue:[ |
|
500 |
"/ '> add:' print. idx2 printNL. |
|
501 |
l2 add:(text2 at:idx2). |
|
502 |
idx2 := idx2 + 1. |
|
503 |
any := true. |
|
504 |
]. |
|
505 |
||
506 |
state == #added ifTrue:[ |
|
4489 | 507 |
l1 add:(text1 at:idx1 ifAbsent:''). |
183 | 508 |
idx1 := idx1 + 1. |
509 |
]. |
|
510 |
state == #deleted ifTrue:[ |
|
4489 | 511 |
l2 add:(text2 at:idx2 ifAbsent:''). |
183 | 512 |
idx2 := idx2 + 1. |
513 |
]. |
|
514 |
||
515 |
||
516 |
" |
|
517 |
add a separating line, except at end |
|
518 |
" |
|
519 |
any ifTrue:[ |
|
520 |
state ~~ #finish ifTrue:[ |
|
521 |
showSeparators ifTrue:[ |
|
522 |
l1 add:'--------'. |
|
523 |
l2 add:'--------'. |
|
524 |
] |
|
525 |
] |
|
526 |
]. |
|
527 |
||
528 |
] ifFalse:[ |
|
529 |
state == #changed ifTrue:[ |
|
2260
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
530 |
line1 := line2 := nil. |
183 | 531 |
(entry at:1) == $< ifTrue:[ |
532 |
useColors ifTrue:[ |
|
313
c143d37be2e9
lines which differ only in blanks (indent) are shown light-blue
Claus Gittinger <cg@exept.de>
parents:
242
diff
changeset
|
533 |
(l2 size >= idx1 |
2260
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
534 |
and:[(s2 := line2 := l2 at:idx1) notNil |
2141 | 535 |
and:[(s2 asString withoutSeparators = (text1 at:idx1) withoutSeparators) |
536 |
"/ or:[(s2 asString withoutSeparators withTabsExpanded = (text1 at:idx1) withoutSeparators withTabsExpanded)] |
|
537 |
]]) ifTrue:[ |
|
2260
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
538 |
line1 := Text string:(text1 at:idx1) |
544
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
539 |
foregroundColor:changedSpacesOnlyColor |
2260
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
540 |
backgroundColor:changedSpacesOnlyBgColor. |
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
541 |
line2 := Text string:line2 asString |
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
542 |
foregroundColor:changedSpacesOnlyColor |
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
543 |
backgroundColor:changedSpacesOnlyBgColor. |
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
544 |
|
2262
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
545 |
line1 string withoutTrailingSeparators = line2 string withoutTrailingSeparators ifTrue:[ |
2260
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
546 |
line1 := line1 string. |
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
547 |
line2 := line2 string. |
6413 | 548 |
] ifFalse:[ |
549 |
line1 withoutSeparators withTabsExpanded = line2 withoutSeparators withTabsExpanded |
|
550 |
ifTrue:[ |
|
551 |
line1 := line1 string. |
|
552 |
line2 := line2 string. |
|
553 |
] |
|
2260
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
554 |
]. |
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
555 |
l1 add:line1. |
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
556 |
l2 at:idx1 put:line2. |
313
c143d37be2e9
lines which differ only in blanks (indent) are shown light-blue
Claus Gittinger <cg@exept.de>
parents:
242
diff
changeset
|
557 |
] ifFalse:[ |
2260
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
558 |
line1 := Text string:(text1 at:idx1) |
544
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
559 |
foregroundColor:changedColor |
2260
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
560 |
backgroundColor:changedBgColor. |
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
561 |
l1 add:line1. |
313
c143d37be2e9
lines which differ only in blanks (indent) are shown light-blue
Claus Gittinger <cg@exept.de>
parents:
242
diff
changeset
|
562 |
] |
183 | 563 |
] ifFalse:[ |
564 |
l1 add:(text1 at:idx1). |
|
565 |
]. |
|
566 |
idx1 := idx1 + 1 |
|
567 |
] ifFalse:[ |
|
568 |
(entry at:1) == $> ifTrue:[ |
|
569 |
useColors ifTrue:[ |
|
313
c143d37be2e9
lines which differ only in blanks (indent) are shown light-blue
Claus Gittinger <cg@exept.de>
parents:
242
diff
changeset
|
570 |
(l1 size >= idx2 |
2260
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
571 |
and:[(s1 := line1 := l1 at:idx2) notNil |
2141 | 572 |
and:[(s1 asString withoutSeparators = (text2 at:idx2) withoutSeparators) |
573 |
"/ or:[(s1 asString withoutSeparators withTabsExpanded = (text2 at:idx2) withoutSeparators withTabsExpanded)] |
|
574 |
]]) ifTrue:[ |
|
2260
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
575 |
line2 := Text string:(text2 at:idx2) |
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
576 |
foregroundColor:changedSpacesOnlyColor |
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
577 |
backgroundColor:changedSpacesOnlyBgColor. |
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
578 |
line1 := Text string:line1 asString |
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
579 |
foregroundColor:changedSpacesOnlyColor |
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
580 |
backgroundColor:changedSpacesOnlyBgColor. |
2262
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
581 |
line1 string withoutTrailingSeparators = line2 string withoutTrailingSeparators ifTrue:[ |
2260
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
582 |
line1 := line1 string. |
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
583 |
line2 := line2 string. |
6413 | 584 |
] ifFalse:[ |
585 |
line1 withoutSeparators withTabsExpanded = line2 withoutSeparators withTabsExpanded |
|
586 |
ifTrue:[ |
|
587 |
line1 := line1 string. |
|
588 |
line2 := line2 string. |
|
589 |
] |
|
2260
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
590 |
]. |
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
591 |
l2 add:line2. |
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
592 |
l1 at:idx2 put:line1. |
313
c143d37be2e9
lines which differ only in blanks (indent) are shown light-blue
Claus Gittinger <cg@exept.de>
parents:
242
diff
changeset
|
593 |
] ifFalse:[ |
2260
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
594 |
line2 := Text string:(text2 at:idx2) foregroundColor:changedColor backgroundColor:changedBgColor. |
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
595 |
l2 add:line2 |
313
c143d37be2e9
lines which differ only in blanks (indent) are shown light-blue
Claus Gittinger <cg@exept.de>
parents:
242
diff
changeset
|
596 |
] |
183 | 597 |
] ifFalse:[ |
598 |
l2 add:(text2 at:idx2). |
|
599 |
]. |
|
600 |
idx2 := idx2 + 1 |
|
601 |
] ifFalse:[ |
|
602 |
(entry at:1) == $- ifTrue:[ |
|
603 |
] ifFalse:[ |
|
604 |
state := #initial. |
|
605 |
dIdx := dIdx - 1 |
|
606 |
] |
|
607 |
] |
|
2260
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
608 |
]. |
183 | 609 |
] ifFalse:[ |
610 |
state == #added ifTrue:[ |
|
611 |
(entry at:1) == $> ifTrue:[ |
|
612 |
useColors ifTrue:[ |
|
544
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
613 |
l2 add:(Text string:(text2 at:idx2) foregroundColor:addedColor backgroundColor:addedBgColor ) |
183 | 614 |
] ifFalse:[ |
615 |
l2 add:(text2 at:idx2). |
|
616 |
]. |
|
617 |
idx2 := idx2 + 1. |
|
618 |
l1 add:nil |
|
619 |
] ifFalse:[ |
|
620 |
state := #initial. |
|
621 |
dIdx := dIdx - 1 |
|
622 |
] |
|
623 |
] ifFalse:[ |
|
624 |
state == #deleted ifTrue:[ |
|
625 |
(entry at:1) == $< ifTrue:[ |
|
626 |
useColors ifTrue:[ |
|
544
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
627 |
l1 add:(Text string:(text1 at:idx1) foregroundColor:removedColor backgroundColor:removedBgColor ). |
183 | 628 |
] ifFalse:[ |
629 |
l1 add:(text1 at:idx1). |
|
630 |
]. |
|
631 |
idx1 := idx1 + 1. |
|
632 |
l2 add:nil |
|
633 |
] ifFalse:[ |
|
634 |
state := #initial. |
|
635 |
dIdx := dIdx - 1 |
|
636 |
] |
|
637 |
] |
|
638 |
"must be in finish otherwise" |
|
639 |
] |
|
640 |
] |
|
641 |
]. |
|
642 |
dIdx := dIdx + 1 |
|
643 |
]. |
|
644 |
[l1 size < l2 size] whileTrue:[ |
|
645 |
l1 add:''. |
|
646 |
]. |
|
647 |
[l2 size < l1 size] whileTrue:[ |
|
648 |
l2 add:''. |
|
649 |
]. |
|
2262
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
650 |
|
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
651 |
"/ fixup - diff -b is ignoring lines which differ in leading space only ... |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
652 |
1 to:l1 size do:[:idx | |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
653 |
|line1 line2| |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
654 |
|
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
655 |
line1 := l1 at:idx. |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
656 |
line2 := l2 at:idx. |
2268 | 657 |
(line1 notNil and:[line1 hasChangeOfEmphasis not]) ifTrue:[ |
658 |
(line2 notNil and:[line2 hasChangeOfEmphasis not]) ifTrue:[ |
|
2262
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
659 |
line1 withTabsExpanded withoutTrailingSeparators |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
660 |
~= line2 withTabsExpanded withoutTrailingSeparators |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
661 |
ifTrue:[ |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
662 |
line1 := Text string:line1 |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
663 |
foregroundColor:changedSpacesOnlyColor |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
664 |
backgroundColor:changedSpacesOnlyBgColor. |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
665 |
line2 := Text string:line2 |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
666 |
foregroundColor:changedSpacesOnlyColor |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
667 |
backgroundColor:changedSpacesOnlyBgColor. |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
668 |
l1 at:idx put:line1. |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
669 |
l2 at:idx put:line2. |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
670 |
] |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
671 |
] |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
672 |
] |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
673 |
]. |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
674 |
|
183 | 675 |
textView1 list:l1. |
676 |
textView2 list:l2 |
|
677 |
||
2260
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
678 |
"Modified: / 13.7.1999 / 14:12:11 / cg" |
183 | 679 |
! ! |
680 |
||
242 | 681 |
!DiffTextView class methodsFor:'documentation'! |
682 |
||
683 |
version |
|
8647 | 684 |
^ '$Header: /cvs/stx/stx/libtool/DiffTextView.st,v 1.54 2009-06-12 09:13:25 cg Exp $' |
2268 | 685 |
! ! |