author | Claus Gittinger <cg@exept.de> |
Mon, 15 Jul 2019 18:53:35 +0200 | |
changeset 18903 | b0d007a5e683 |
parent 18278 | 0aafdc282b1c |
child 19289 | 12fbc454fa61 |
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 |
|
16246 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
36 | 16 |
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
|
17 |
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
|
18 |
removedBgColor changedColor changedBgColor changedSpacesOnlyColor |
507 | 19 |
changedSpacesOnlyBgColor diffLineNumbers' |
1440
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
20 |
classVariableNames:'DiffCommandTemplate' |
313
c143d37be2e9
lines which differ only in blanks (indent) are shown light-blue
Claus Gittinger <cg@exept.de>
parents:
242
diff
changeset
|
21 |
poolDictionaries:'' |
c143d37be2e9
lines which differ only in blanks (indent) are shown light-blue
Claus Gittinger <cg@exept.de>
parents:
242
diff
changeset
|
22 |
category:'Views-Text' |
36 | 23 |
! |
24 |
||
13793 | 25 |
AbstractBackground subclass:#DiffTextScrollerBackground |
26 |
instanceVariableNames:'diffView' |
|
27 |
classVariableNames:'' |
|
28 |
poolDictionaries:'' |
|
29 |
privateIn:DiffTextView |
|
30 |
! |
|
31 |
||
36 | 32 |
!DiffTextView class methodsFor:'documentation'! |
33 |
||
34 |
copyright |
|
35 |
" |
|
36 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
45 | 37 |
All Rights Reserved |
36 | 38 |
|
39 |
This software is furnished under a license and may be used |
|
40 |
only in accordance with the terms of that license and with the |
|
41 |
inclusion of the above copyright notice. This software may not |
|
42 |
be provided or otherwise made available to, or used by, any |
|
43 |
other person. No title to or ownership of the software is |
|
44 |
hereby transferred. |
|
45 |
" |
|
46 |
! |
|
47 |
||
48 |
documentation |
|
49 |
" |
|
507 | 50 |
a view showing diff output (see unix manual pages) |
51 |
in a user-friendly form. |
|
36 | 52 |
The view is created and opened with: |
53 |
||
507 | 54 |
d := DiffTextView openOn:text1 and:text2 |
55 |
||
56 |
or: |
|
57 |
d := DiffTextView openOn:text1 label:l1 |
|
58 |
and:text2 label:l2 |
|
36 | 59 |
|
507 | 60 |
and it will show the differences side-by-side. |
533 | 61 |
|
2240 | 62 |
The colors mean: |
63 |
red - removed |
|
64 |
green - added |
|
65 |
blue - changed |
|
66 |
light-blue changed, but not really (i.e. spaces only) |
|
67 |
||
68 |
For a real world application and use of this widget, |
|
69 |
see the ChangesBrowsers `compare', |
|
70 |
or the browsers 'compare with repository' functions. |
|
507 | 71 |
|
2246
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
72 |
Notice: |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
73 |
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
|
74 |
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
|
75 |
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
|
76 |
|
507 | 77 |
[see also:] |
1276 | 78 |
TextView EditTextView Diff3TextView |
519 | 79 |
|
80 |
[author:] |
|
81 |
Claus Gittinger |
|
36 | 82 |
" |
1276 | 83 |
! |
84 |
||
85 |
examples |
|
86 |
" |
|
87 |
[exBegin] |
|
88 |
|text1 text2| |
|
89 |
||
90 |
text1 := 'hello world |
|
91 |
here is some difference |
|
92 |
more text |
|
93 |
this line has been removed |
|
94 |
more text |
|
95 |
more text |
|
96 |
'. |
|
97 |
||
98 |
text2 := 'hello world |
|
99 |
where is the difference ? |
|
100 |
more text |
|
101 |
more text |
|
102 |
more text |
|
103 |
this line has been added |
|
104 |
'. |
|
105 |
||
106 |
DiffTextView openOn:text1 label:'text1' |
|
107 |
and:text2 label:'text2' |
|
108 |
[exEnd] |
|
109 |
" |
|
242 | 110 |
! ! |
36 | 111 |
|
2716
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
112 |
!DiffTextView class methodsFor:'instance creation'! |
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
113 |
|
2948
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
114 |
openOnClass:classA labelA:lblA andClass:classB labelB:lblB title:title ifSame:sameAction |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
115 |
"provided for protocol compatibility with the VersionDiffBrowser; |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
116 |
actually, the classes are ignored here" |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
117 |
|
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
118 |
|v aStream sourceA sourceB| |
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 |
aStream := '' writeStream. |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
121 |
Method flushSourceStreamCache. |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
122 |
classA fileOutOn:aStream withTimeStamp:false. |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
123 |
sourceA := aStream contents asString. |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
124 |
|
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
125 |
aStream := '' writeStream. |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
126 |
Method flushSourceStreamCache. |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
127 |
classB fileOutOn:aStream withTimeStamp:false. |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
128 |
sourceB := aStream contents asString. |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
129 |
|
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
130 |
v := self |
3755 | 131 |
openOn:sourceA label:lblA |
132 |
and:sourceB label:lblB. |
|
8334 | 133 |
v topView label:title. |
2948
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
134 |
^ v |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
135 |
! |
cf5b7f232536
VersionDIffBrowser compatibility
Claus Gittinger <cg@exept.de>
parents:
2848
diff
changeset
|
136 |
|
2716
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
137 |
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
|
138 |
"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
|
139 |
actually, the class is ignored here" |
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
140 |
|
3755 | 141 |
^ self |
142 |
openOnClass:someClass |
|
143 |
labelA:lblA sourceA:sourceA |
|
144 |
labelB:lblB sourceB:sourceB |
|
145 |
title:'Comparing ' , someClass name. |
|
2716
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
146 |
! |
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
147 |
|
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
148 |
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
|
149 |
"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
|
150 |
actually, the class is ignored here" |
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
151 |
|
2848 | 152 |
^ self |
3755 | 153 |
openOnClass:someClass |
154 |
labelA:lblA sourceA:sourceA |
|
155 |
labelB:lblB sourceB:sourceB |
|
156 |
title:title ifSame:nil |
|
2848 | 157 |
! |
158 |
||
159 |
openOnClass:someClass labelA:lblA sourceA:sourceA labelB:lblB sourceB:sourceB title:title ifSame:sameAction |
|
160 |
"provided for protocol compatibility with the VersionDiffBrowser; |
|
161 |
actually, the class is ignored here" |
|
162 |
||
2716
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
163 |
|v| |
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
164 |
|
2750 | 165 |
v := self |
3755 | 166 |
openOn:sourceA label:lblA |
167 |
and:sourceB label:lblB. |
|
3050 | 168 |
v topView label:title. |
2716
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
169 |
^ v |
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
170 |
! ! |
8451e7057f00
some common startup protocol between DiffViewer and VersionDiffBrowser
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
171 |
|
45 | 172 |
!DiffTextView class methodsFor:'defaults'! |
173 |
||
174 |
diffCommand |
|
1440
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
175 |
"return the diff-command (with argument placeHolders)" |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
176 |
|
8934
7cc2affd9bb9
started to refactor into DiffListUtility
Claus Gittinger <cg@exept.de>
parents:
8676
diff
changeset
|
177 |
"/ forwarded, for backward compatibility... |
7cc2affd9bb9
started to refactor into DiffListUtility
Claus Gittinger <cg@exept.de>
parents:
8676
diff
changeset
|
178 |
^ DiffListUtility diffCommand |
1440
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
179 |
! |
507 | 180 |
|
1440
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
181 |
diffCommandTemplate:aCommandTemplateString |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
182 |
"set the diff-command template" |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
183 |
|
8934
7cc2affd9bb9
started to refactor into DiffListUtility
Claus Gittinger <cg@exept.de>
parents:
8676
diff
changeset
|
184 |
"/ forwarded for backward compatibility |
7cc2affd9bb9
started to refactor into DiffListUtility
Claus Gittinger <cg@exept.de>
parents:
8676
diff
changeset
|
185 |
DiffListUtility diffCommandTemplate:aCommandTemplateString |
45 | 186 |
! ! |
187 |
||
36 | 188 |
!DiffTextView methodsFor:'accessing'! |
189 |
||
190 |
text1:t1 text2:t2 |
|
1440
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
191 |
"set the two texts which are to be diffed; |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
192 |
execute DiffCommand and update the two textViews." |
507 | 193 |
|
6577
51b89422d7de
be more robust w.r.t. errors while diffing
Claus Gittinger <cg@exept.de>
parents:
6413
diff
changeset
|
194 |
|text1 text2 diffList| |
36 | 195 |
|
12383 | 196 |
text1 := t1 asStringCollection. |
197 |
text2 := t2 asStringCollection. |
|
15014 | 198 |
text1 = text2 ifTrue:[ |
199 |
diffList := #() |
|
200 |
] ifFalse:[ |
|
201 |
diffList := self diffListFor:text1 and:text2. |
|
202 |
]. |
|
36 | 203 |
self updateListsFrom:text1 and:text2 diffs:diffList |
204 |
||
205 |
" |
|
206 |
|v| |
|
207 |
||
208 |
v := HVScrollableView for:DiffTextView. |
|
209 |
v scrolledView text1:('../libview/Color.st' asFilename readStream contents) |
|
507 | 210 |
text2:('../libview/Color.st.old' asFilename readStream contents). |
36 | 211 |
v open |
212 |
" |
|
213 |
||
214 |
" |
|
215 |
|v t1 t2| |
|
216 |
||
217 |
t1 := ' |
|
218 |
one |
|
219 |
two |
|
220 |
three |
|
221 |
four |
|
222 |
'. |
|
223 |
t2 := ' |
|
224 |
one |
|
225 |
two-a |
|
226 |
two-b |
|
227 |
three |
|
228 |
three-b |
|
229 |
four |
|
230 |
'. |
|
231 |
||
232 |
v := DiffTextView new. |
|
233 |
v text1:t1 text2:t2. |
|
69 | 234 |
v open |
36 | 235 |
" |
507 | 236 |
|
7768 | 237 |
"Modified: / 27-03-2007 / 12:06:46 / cg" |
36 | 238 |
! ! |
183 | 239 |
|
240 |
!DiffTextView methodsFor:'initialization'! |
|
241 |
||
2246
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
242 |
addNextPreviousButtons |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
243 |
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
|
244 |
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
|
245 |
! |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
246 |
|
183 | 247 |
initStyle |
248 |
super initStyle. |
|
249 |
||
250 |
showSeparators := false. |
|
251 |
||
16246 | 252 |
(useColors := device hasColors) ifTrue:[ |
16744 | 253 |
addedColor := self whiteColor. |
2240 | 254 |
addedBgColor := Color red. |
183 | 255 |
|
16744 | 256 |
removedColor := self blackColor. |
2240 | 257 |
removedBgColor := Color green. |
183 | 258 |
|
16744 | 259 |
changedColor := self whiteColor. |
544
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
260 |
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
|
261 |
|
16744 | 262 |
changedSpacesOnlyColor := self whiteColor. |
544
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
263 |
changedSpacesOnlyBgColor := Color blue lightened. |
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
264 |
] ifFalse:[ |
623 | 265 |
showSeparators := true. |
266 |
||
16246 | 267 |
(useColors := device hasGreyscales) ifTrue:[ |
623 | 268 |
addedBgColor := removedBgColor := changedBgColor := Color grey:80. |
16744 | 269 |
addedColor := removedColor := changedColor := self blackColor. |
623 | 270 |
] ifFalse:[ |
16744 | 271 |
addedBgColor := removedBgColor := changedBgColor := self blackColor. |
272 |
addedColor := removedColor := changedColor := self whiteColor. |
|
623 | 273 |
]. |
274 |
||
16744 | 275 |
changedSpacesOnlyColor := self whiteColor. |
276 |
changedSpacesOnlyBgColor := self blackColor. |
|
183 | 277 |
]. |
278 |
||
279 |
"Created: 16.11.1995 / 16:59:48 / cg" |
|
623 | 280 |
"Modified: 14.6.1996 / 16:14:39 / cg" |
14431 | 281 |
! |
282 |
||
283 |
postRealize |
|
284 |
super postRealize. |
|
18278 | 285 |
self moveToNextChangedAfter:1 |
286 |
||
287 |
"Modified: / 23-07-2018 / 09:47:19 / Claus Gittinger" |
|
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 |
|
17817 | 302 |
|idx1 idx2 dIdx dEnd state s nr1 nr2 nr3 op entry l1 l2 any delta s1 s2 line1 line2 common| |
8934
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 |
17817 | 438 |
and:[(line2 asString string withTabsExpanded withoutSeparators = (line1 := text1 at:idx1) asString string withTabsExpanded 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 |
17817 | 475 |
and:[(s1 asString string withTabsExpanded withoutSeparators = (text2 at:idx2) string withTabsExpanded 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:[ |
17817 | 497 |
line2 := text2 at:idx2. |
498 |
line1 notNil ifTrue:[ |
|
499 |
common := line1 string commonPrefixWith: line2 string. |
|
500 |
] ifFalse:[ |
|
501 |
common := nil |
|
502 |
]. |
|
503 |
common size > 0 ifTrue:[ |
|
504 |
line2 := (Text string:common foregroundColor:changedSpacesOnlyColor backgroundColor:changedSpacesOnlyBgColor) |
|
505 |
, (Text string:(line2 copyFrom:common size+1) foregroundColor:changedColor backgroundColor:changedBgColor). |
|
506 |
] ifFalse:[ |
|
507 |
line2 := Text string:line2 foregroundColor:changedColor backgroundColor:changedBgColor. |
|
508 |
]. |
|
2260
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
509 |
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
|
510 |
] |
183 | 511 |
] ifFalse:[ |
17817 | 512 |
l2 add:line2. |
183 | 513 |
]. |
514 |
idx2 := idx2 + 1 |
|
515 |
] ifFalse:[ |
|
516 |
(entry at:1) == $- ifTrue:[ |
|
517 |
] ifFalse:[ |
|
518 |
state := #initial. |
|
519 |
dIdx := dIdx - 1 |
|
520 |
] |
|
521 |
] |
|
2260
2c093fe9ddb1
fix for win32 diff (which does not support -b option)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
522 |
]. |
183 | 523 |
] ifFalse:[ |
524 |
state == #added ifTrue:[ |
|
525 |
(entry at:1) == $> ifTrue:[ |
|
526 |
useColors ifTrue:[ |
|
544
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
527 |
l2 add:(Text string:(text2 at:idx2) foregroundColor:addedColor backgroundColor:addedBgColor ) |
183 | 528 |
] ifFalse:[ |
529 |
l2 add:(text2 at:idx2). |
|
530 |
]. |
|
531 |
idx2 := idx2 + 1. |
|
532 |
l1 add:nil |
|
533 |
] ifFalse:[ |
|
534 |
state := #initial. |
|
535 |
dIdx := dIdx - 1 |
|
536 |
] |
|
537 |
] ifFalse:[ |
|
538 |
state == #deleted ifTrue:[ |
|
539 |
(entry at:1) == $< ifTrue:[ |
|
540 |
useColors ifTrue:[ |
|
544
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
541 |
l1 add:(Text string:(text1 at:idx1) foregroundColor:removedColor backgroundColor:removedBgColor ). |
183 | 542 |
] ifFalse:[ |
543 |
l1 add:(text1 at:idx1). |
|
544 |
]. |
|
545 |
idx1 := idx1 + 1. |
|
546 |
l2 add:nil |
|
547 |
] ifFalse:[ |
|
548 |
state := #initial. |
|
549 |
dIdx := dIdx - 1 |
|
550 |
] |
|
551 |
] |
|
552 |
"must be in finish otherwise" |
|
553 |
] |
|
13784 | 554 |
]. |
183 | 555 |
]. |
556 |
dIdx := dIdx + 1 |
|
557 |
]. |
|
558 |
[l1 size < l2 size] whileTrue:[ |
|
559 |
l1 add:''. |
|
560 |
]. |
|
561 |
[l2 size < l1 size] whileTrue:[ |
|
562 |
l2 add:''. |
|
563 |
]. |
|
2262
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
564 |
|
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
565 |
"/ 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
|
566 |
1 to:l1 size do:[:idx | |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
567 |
|line1 line2| |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
568 |
|
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
569 |
line1 := l1 at:idx. |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
570 |
line2 := l2 at:idx. |
2268 | 571 |
(line1 notNil and:[line1 hasChangeOfEmphasis not]) ifTrue:[ |
572 |
(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
|
573 |
line1 withTabsExpanded withoutTrailingSeparators |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
574 |
~= line2 withTabsExpanded withoutTrailingSeparators |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
575 |
ifTrue:[ |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
576 |
line1 := Text string:line1 |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
577 |
foregroundColor:changedSpacesOnlyColor |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
578 |
backgroundColor:changedSpacesOnlyBgColor. |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
579 |
line2 := Text string:line2 |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
580 |
foregroundColor:changedSpacesOnlyColor |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
581 |
backgroundColor:changedSpacesOnlyBgColor. |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
582 |
l1 at:idx put:line1. |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
583 |
l2 at:idx put:line2. |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
584 |
] |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
585 |
] |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
586 |
] |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
587 |
]. |
75d490e87d95
oops - care for diff -b space differences
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
588 |
|
8934
7cc2affd9bb9
started to refactor into DiffListUtility
Claus Gittinger <cg@exept.de>
parents:
8676
diff
changeset
|
589 |
^ { l1. l2 } |
183 | 590 |
|
17817 | 591 |
"Modified: / 29-11-2017 / 11:06:54 / cg" |
8934
7cc2affd9bb9
started to refactor into DiffListUtility
Claus Gittinger <cg@exept.de>
parents:
8676
diff
changeset
|
592 |
! |
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 |
updateListsFrom:text1 and:text2 diffs:diffList |
7cc2affd9bb9
started to refactor into DiffListUtility
Claus Gittinger <cg@exept.de>
parents:
8676
diff
changeset
|
595 |
"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
|
596 |
update my views contents" |
7cc2affd9bb9
started to refactor into DiffListUtility
Claus Gittinger <cg@exept.de>
parents:
8676
diff
changeset
|
597 |
|
7cc2affd9bb9
started to refactor into DiffListUtility
Claus Gittinger <cg@exept.de>
parents:
8676
diff
changeset
|
598 |
|lists textView1 textView2| |
7cc2affd9bb9
started to refactor into DiffListUtility
Claus Gittinger <cg@exept.de>
parents:
8676
diff
changeset
|
599 |
|
7cc2affd9bb9
started to refactor into DiffListUtility
Claus Gittinger <cg@exept.de>
parents:
8676
diff
changeset
|
600 |
textView1 := textViews at:1. |
7cc2affd9bb9
started to refactor into DiffListUtility
Claus Gittinger <cg@exept.de>
parents:
8676
diff
changeset
|
601 |
textView2 := textViews at:2. |
7cc2affd9bb9
started to refactor into DiffListUtility
Claus Gittinger <cg@exept.de>
parents:
8676
diff
changeset
|
602 |
|
7cc2affd9bb9
started to refactor into DiffListUtility
Claus Gittinger <cg@exept.de>
parents:
8676
diff
changeset
|
603 |
lists := self processDiffList:diffList from:text1 and:text2. |
7cc2affd9bb9
started to refactor into DiffListUtility
Claus Gittinger <cg@exept.de>
parents:
8676
diff
changeset
|
604 |
|
7cc2affd9bb9
started to refactor into DiffListUtility
Claus Gittinger <cg@exept.de>
parents:
8676
diff
changeset
|
605 |
textView1 list:lists first. |
7cc2affd9bb9
started to refactor into DiffListUtility
Claus Gittinger <cg@exept.de>
parents:
8676
diff
changeset
|
606 |
textView2 list:lists second. |
13784 | 607 |
|
608 |
self updateScrollbarBackground |
|
609 |
! |
|
610 |
||
611 |
updateScrollbarBackground |
|
612 |
"define a background in the scroller allowing quick positioning to changes" |
|
613 |
||
614 |
|container vScroller thumb| |
|
615 |
||
16329 | 616 |
((container := self container) notNil |
617 |
and:[container isScrollWrapper]) ifTrue:[ |
|
13784 | 618 |
(vScroller := container verticalScrollBar) notNil ifTrue:[ |
619 |
(thumb := vScroller thumb) notNil ifTrue:[ |
|
13793 | 620 |
thumb viewBackground:(DiffTextScrollerBackground new diffView:self). |
13784 | 621 |
] |
622 |
] |
|
623 |
]. |
|
183 | 624 |
! ! |
625 |
||
14984 | 626 |
!DiffTextView::DiffTextScrollerBackground class methodsFor:'documentation'! |
627 |
||
628 |
documentation |
|
629 |
" |
|
630 |
I am a scroller background used by the diff-text-viewers. |
|
17396 | 631 |
I draw line-markers at positions where differences between two texts are. |
14984 | 632 |
" |
633 |
! ! |
|
634 |
||
13793 | 635 |
!DiffTextView::DiffTextScrollerBackground methodsFor:'accessing'! |
636 |
||
17396 | 637 |
diffView:aDiffTextView |
638 |
diffView := aDiffTextView. |
|
639 |
||
640 |
"Modified (format): / 12-02-2017 / 12:53:09 / cg" |
|
13793 | 641 |
! ! |
642 |
||
643 |
!DiffTextView::DiffTextScrollerBackground methodsFor:'drawing'! |
|
644 |
||
645 |
fillRectangleX:x y:y width:w height:h in:aScroller |
|
646 |
|leftTextView rightTextView overAllHeight| |
|
647 |
||
648 |
leftTextView := diffView textViews first. |
|
649 |
rightTextView := diffView textViews second. |
|
650 |
||
651 |
overAllHeight := leftTextView numberOfLines. |
|
652 |
1 to:overAllHeight do:[:lineNr | |
|
17396 | 653 |
|l1 l2 yThumb clr e| |
13793 | 654 |
|
655 |
yThumb := (aScroller height * (lineNr / overAllHeight)) rounded. |
|
17396 | 656 |
(yThumb between:y and:(y + h)) ifTrue:[ |
13793 | 657 |
l1 := leftTextView listAt:lineNr. |
658 |
l2 := rightTextView listAt:lineNr. |
|
659 |
(l1 notNil and:[l1 isText]) ifTrue:[ |
|
660 |
e := l1 emphasis |
|
661 |
] ifFalse:[ |
|
662 |
(l2 notNil and:[l2 isText ]) ifTrue:[ |
|
663 |
e := l2 emphasis |
|
664 |
] |
|
665 |
]. |
|
17396 | 666 |
e notEmptyOrNil ifTrue:[ |
13793 | 667 |
|el| |
668 |
||
669 |
el := e detect:[:el | (Text extractEmphasis:#backgroundColor from:el) notNil] ifNone:nil. |
|
670 |
el notNil ifTrue:[ |
|
671 |
clr := Text extractEmphasis:#backgroundColor from:el. |
|
672 |
(clr brightness > 0.5) ifTrue:[ clr := clr darkened ]. |
|
673 |
aScroller paint:clr. |
|
674 |
aScroller displayLineFromX:1 y:yThumb toX:aScroller width-2 y:yThumb. |
|
675 |
]. |
|
676 |
]. |
|
677 |
]. |
|
678 |
] |
|
17396 | 679 |
|
680 |
"Modified: / 12-02-2017 / 12:54:36 / cg" |
|
13793 | 681 |
! ! |
682 |
||
683 |
!DiffTextView::DiffTextScrollerBackground methodsFor:'ignored conversion'! |
|
684 |
||
685 |
asFormOn:aDevice |
|
686 |
"superclass AbstractBackground says that I am responsible to implement this method" |
|
687 |
||
688 |
^ self |
|
689 |
! |
|
690 |
||
691 |
onDevice:aDevice |
|
692 |
"superclass AbstractBackground says that I am responsible to implement this method" |
|
693 |
||
694 |
^ self |
|
695 |
! ! |
|
696 |
||
242 | 697 |
!DiffTextView class methodsFor:'documentation'! |
698 |
||
699 |
version |
|
16246 | 700 |
^ '$Header$' |
8934
7cc2affd9bb9
started to refactor into DiffListUtility
Claus Gittinger <cg@exept.de>
parents:
8676
diff
changeset
|
701 |
! |
7cc2affd9bb9
started to refactor into DiffListUtility
Claus Gittinger <cg@exept.de>
parents:
8676
diff
changeset
|
702 |
|
7cc2affd9bb9
started to refactor into DiffListUtility
Claus Gittinger <cg@exept.de>
parents:
8676
diff
changeset
|
703 |
version_CVS |
16246 | 704 |
^ '$Header$' |
2268 | 705 |
! ! |
12383 | 706 |