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