author | Claus Gittinger <cg@exept.de> |
Fri, 09 Jul 1999 16:56:18 +0200 | |
changeset 2246 | 34262ef77055 |
parent 2240 | eb2688b9cf45 |
child 2260 | 2c093fe9ddb1 |
permissions | -rw-r--r-- |
36 | 1 |
" |
2 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
45 | 3 |
All Rights Reserved |
36 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
TwoColumnTextView subclass:#DiffTextView |
|
313
c143d37be2e9
lines which differ only in blanks (indent) are shown light-blue
Claus Gittinger <cg@exept.de>
parents:
242
diff
changeset
|
14 |
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
|
15 |
removedBgColor changedColor changedBgColor changedSpacesOnlyColor |
507 | 16 |
changedSpacesOnlyBgColor diffLineNumbers' |
1440
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
17 |
classVariableNames:'DiffCommandTemplate' |
313
c143d37be2e9
lines which differ only in blanks (indent) are shown light-blue
Claus Gittinger <cg@exept.de>
parents:
242
diff
changeset
|
18 |
poolDictionaries:'' |
c143d37be2e9
lines which differ only in blanks (indent) are shown light-blue
Claus Gittinger <cg@exept.de>
parents:
242
diff
changeset
|
19 |
category:'Views-Text' |
36 | 20 |
! |
21 |
||
22 |
!DiffTextView class methodsFor:'documentation'! |
|
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
45 | 27 |
All Rights Reserved |
36 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
507 | 40 |
a view showing diff output (see unix manual pages) |
41 |
in a user-friendly form. |
|
36 | 42 |
The view is created and opened with: |
43 |
||
507 | 44 |
d := DiffTextView openOn:text1 and:text2 |
45 |
||
46 |
or: |
|
47 |
d := DiffTextView openOn:text1 label:l1 |
|
48 |
and:text2 label:l2 |
|
36 | 49 |
|
507 | 50 |
and it will show the differences side-by-side. |
533 | 51 |
|
2240 | 52 |
The colors mean: |
53 |
red - removed |
|
54 |
green - added |
|
55 |
blue - changed |
|
56 |
light-blue changed, but not really (i.e. spaces only) |
|
57 |
||
58 |
For a real world application and use of this widget, |
|
59 |
see the ChangesBrowsers `compare', |
|
60 |
or the browsers 'compare with repository' functions. |
|
507 | 61 |
|
2246
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
62 |
Notice: |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
63 |
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
|
64 |
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
|
65 |
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
|
66 |
|
507 | 67 |
[see also:] |
1276 | 68 |
TextView EditTextView Diff3TextView |
519 | 69 |
|
70 |
[author:] |
|
71 |
Claus Gittinger |
|
36 | 72 |
" |
1276 | 73 |
! |
74 |
||
75 |
examples |
|
76 |
" |
|
77 |
[exBegin] |
|
78 |
|text1 text2| |
|
79 |
||
80 |
text1 := 'hello world |
|
81 |
here is some difference |
|
82 |
more text |
|
83 |
this line has been removed |
|
84 |
more text |
|
85 |
more text |
|
86 |
'. |
|
87 |
||
88 |
text2 := 'hello world |
|
89 |
where is the difference ? |
|
90 |
more text |
|
91 |
more text |
|
92 |
more text |
|
93 |
this line has been added |
|
94 |
'. |
|
95 |
||
96 |
DiffTextView openOn:text1 label:'text1' |
|
97 |
and:text2 label:'text2' |
|
98 |
[exEnd] |
|
99 |
" |
|
242 | 100 |
! ! |
36 | 101 |
|
45 | 102 |
!DiffTextView class methodsFor:'defaults'! |
103 |
||
104 |
diffCommand |
|
1440
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
105 |
"return the diff-command (with argument placeHolders)" |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
106 |
|
2246
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
107 |
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
|
108 |
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
|
109 |
(OperatingSystem canExecuteCommand:'diff') ifFalse:[ |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
110 |
'DiffTextView [warning]: no diff command found' errorPrintCR. |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
111 |
^ nil |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
112 |
]. |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
113 |
DiffCommandTemplate := 'diff %1 %2' |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
114 |
] ifFalse:[ |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
115 |
DiffCommandTemplate := 'diff -b %1 %2' |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
116 |
] |
1440
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
117 |
]. |
2246
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
118 |
^ DiffCommandTemplate |
1440
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
119 |
|
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
120 |
"Modified: / 30.1.1998 / 12:12:49 / cg" |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
121 |
! |
507 | 122 |
|
1440
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
123 |
diffCommandTemplate:aCommandTemplateString |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
124 |
"set the diff-command template" |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
125 |
|
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
126 |
OperatingSystem isMSDOSlike ifTrue:[ |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
127 |
^ DiffCommandTemplate ? 'diff %1 %2' |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
128 |
]. |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
129 |
|
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
130 |
^ DiffCommandTemplate ? 'diff -b %1 %2' |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
131 |
|
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
132 |
"Modified: / 30.1.1998 / 12:10:34 / cg" |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
133 |
"Created: / 30.1.1998 / 12:12:37 / cg" |
45 | 134 |
! ! |
135 |
||
36 | 136 |
!DiffTextView methodsFor:'accessing'! |
137 |
||
138 |
text1:t1 text2:t2 |
|
1440
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
139 |
"set the two texts which are to be diffed; |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
140 |
execute DiffCommand and update the two textViews." |
507 | 141 |
|
1440
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
142 |
|tmpFile1 tmpFile2 name1 tmpName2 stream line |
2246
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
143 |
text1 text2 diffList pidString diffTemplate diffCmd| |
36 | 144 |
|
69 | 145 |
text1 := t1 asStringCollection. |
146 |
text2 := t2 asStringCollection. |
|
36 | 147 |
|
2246
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
148 |
diffTemplate := self class diffCommand. |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
149 |
diffTemplate 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
|
150 |
"/ self warn:'no diff command available'. |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
151 |
] ifFalse:[ |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
152 |
" |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
153 |
save them texts in two temporary files ... |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
154 |
" |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
155 |
tmpFile1 := Filename newTemporary. |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
156 |
stream := tmpFile1 writeStream. |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
157 |
text1 do:[:line | |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
158 |
line notNil ifTrue:[ |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
159 |
stream nextPutAll:line. |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
160 |
]. |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
161 |
stream cr |
2141 | 162 |
]. |
2246
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
163 |
stream close. |
36 | 164 |
|
2246
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
165 |
tmpFile2 := Filename newTemporary. |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
166 |
stream := tmpFile2 writeStream. |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
167 |
text2 do:[:line | |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
168 |
line notNil 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 |
stream nextPutAll:line. |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
170 |
]. |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
171 |
stream cr |
2141 | 172 |
]. |
2246
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
173 |
stream close. |
36 | 174 |
|
2246
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
175 |
" |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
176 |
start diff on it ... |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
177 |
" |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
178 |
diffCmd := diffTemplate |
1440
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
179 |
bindWith:tmpFile1 asString |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
180 |
with:tmpFile2 asString. |
6a68adba9c33
allow configuration of diff command;
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
181 |
|
2246
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
182 |
stream := PipeStream readingFrom:diffCmd. |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
183 |
stream 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
|
184 |
stream := PipeStream readingFrom:('support' , Filename separator asString , diffCmd). |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
185 |
]. |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
186 |
stream 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
|
187 |
self error:'cannot execute diff'. |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
188 |
text1 := text2 := nil. |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
189 |
] ifFalse:[ |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
190 |
diffList := OrderedCollection new. |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
191 |
[stream atEnd] whileFalse:[ |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
192 |
line := stream nextLine. |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
193 |
line notNil ifTrue:[diffList add:line] |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
194 |
]. |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
195 |
stream close. |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
196 |
]. |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
197 |
|
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
198 |
tmpFile1 delete. |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
199 |
tmpFile2 delete. |
2141 | 200 |
]. |
36 | 201 |
|
202 |
self updateListsFrom:text1 and:text2 diffs:diffList |
|
203 |
||
204 |
" |
|
205 |
|v| |
|
206 |
||
207 |
v := HVScrollableView for:DiffTextView. |
|
208 |
v scrolledView text1:('../libview/Color.st' asFilename readStream contents) |
|
507 | 209 |
text2:('../libview/Color.st.old' asFilename readStream contents). |
36 | 210 |
v open |
211 |
" |
|
212 |
||
213 |
" |
|
214 |
|v t1 t2| |
|
215 |
||
216 |
t1 := ' |
|
217 |
one |
|
218 |
two |
|
219 |
three |
|
220 |
four |
|
221 |
'. |
|
222 |
t2 := ' |
|
223 |
one |
|
224 |
two-a |
|
225 |
two-b |
|
226 |
three |
|
227 |
three-b |
|
228 |
four |
|
229 |
'. |
|
230 |
||
231 |
v := DiffTextView new. |
|
232 |
v text1:t1 text2:t2. |
|
69 | 233 |
v open |
36 | 234 |
" |
507 | 235 |
|
2141 | 236 |
"Modified: / 5.5.1999 / 16:07:13 / cg" |
36 | 237 |
! ! |
183 | 238 |
|
239 |
!DiffTextView methodsFor:'initialization'! |
|
240 |
||
2246
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
241 |
addNextPreviousButtons |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
242 |
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
|
243 |
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
|
244 |
! |
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
245 |
|
183 | 246 |
initStyle |
247 |
super initStyle. |
|
248 |
||
249 |
showSeparators := false. |
|
250 |
||
544
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
251 |
(useColors := device hasColors) ifTrue:[ |
2240 | 252 |
addedColor := Color white. |
253 |
addedBgColor := Color red. |
|
183 | 254 |
|
2240 | 255 |
removedColor := Color black. |
256 |
removedBgColor := Color green. |
|
183 | 257 |
|
544
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
258 |
changedColor := Color white. |
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
259 |
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
|
260 |
|
544
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
261 |
changedSpacesOnlyColor := Color white. |
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
262 |
changedSpacesOnlyBgColor := Color blue lightened. |
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
263 |
] ifFalse:[ |
623 | 264 |
showSeparators := true. |
265 |
||
266 |
(useColors := device hasGreyscales) ifTrue:[ |
|
267 |
addedBgColor := removedBgColor := changedBgColor := Color grey:80. |
|
268 |
addedColor := removedColor := changedColor := Color black. |
|
269 |
] ifFalse:[ |
|
270 |
addedBgColor := removedBgColor := changedBgColor := Color black. |
|
271 |
addedColor := removedColor := changedColor := Color white. |
|
272 |
]. |
|
273 |
||
274 |
changedSpacesOnlyColor := Color white. |
|
275 |
changedSpacesOnlyBgColor := Color black. |
|
183 | 276 |
]. |
277 |
||
278 |
"Created: 16.11.1995 / 16:59:48 / cg" |
|
623 | 279 |
"Modified: 14.6.1996 / 16:14:39 / cg" |
183 | 280 |
! ! |
281 |
||
282 |
!DiffTextView methodsFor:'private'! |
|
283 |
||
284 |
updateListsFrom:text1 and:text2 diffs:diffList |
|
285 |
"given the two texts in text1 and text2, and the diff-output in diffList, |
|
286 |
update my views contents" |
|
287 |
||
288 |
|idx1 idx2 dIdx dEnd state s nr1 nr2 nr3 op entry c l1 l2 any delta |
|
318 | 289 |
textView1 textView2 s1 s2| |
183 | 290 |
|
507 | 291 |
diffLineNumbers := OrderedCollection new. |
292 |
||
183 | 293 |
textView1 := textViews at:1. |
294 |
textView2 := textViews at:2. |
|
295 |
||
296 |
l1 := OrderedCollection new. |
|
297 |
l2 := OrderedCollection new. |
|
298 |
||
299 |
idx1 := 1. |
|
300 |
idx2 := 1. |
|
301 |
||
302 |
dIdx := 1. |
|
303 |
dEnd := diffList size + 1. |
|
304 |
state := #initial. |
|
305 |
[dIdx <= dEnd] whileTrue:[ |
|
306 |
dIdx == dEnd ifTrue:[ |
|
307 |
"dummy cleanup entry" |
|
308 |
entry := nil. |
|
309 |
state := #initial. |
|
310 |
] ifFalse:[ |
|
311 |
entry := diffList at:dIdx. |
|
312 |
]. |
|
313 |
||
314 |
state == #initial ifTrue:[ |
|
315 |
"entry is of the form <nr> <op> <offs> [<offs2>]" |
|
316 |
||
317 |
" |
|
318 |
fill up to size difference from previous change |
|
319 |
" |
|
320 |
delta := l1 size - l2 size. |
|
321 |
delta > 0 ifTrue:[ |
|
322 |
delta timesRepeat:[l2 add:nil] |
|
323 |
] ifFalse:[ |
|
324 |
delta < 0 ifTrue:[ |
|
325 |
delta negated timesRepeat:[l1 add:nil] |
|
326 |
] |
|
327 |
]. |
|
328 |
||
329 |
" |
|
330 |
except for the first chunk, add a separating line |
|
331 |
" |
|
332 |
l1 size ~~ 0 ifTrue:[ |
|
333 |
showSeparators ifTrue:[ |
|
334 |
l1 add:'--------'. |
|
335 |
l2 add:'--------'. |
|
336 |
] |
|
337 |
]. |
|
338 |
" |
|
339 |
in cleanup ? |
|
340 |
" |
|
341 |
entry isNil ifTrue:[ |
|
342 |
nr1 := text1 size + 1. |
|
343 |
nr2 := text2 size + 1. |
|
344 |
state := #finish. |
|
345 |
] ifFalse:[ |
|
507 | 346 |
diffLineNumbers add:l1 size. |
347 |
||
183 | 348 |
s := ReadStream on:entry. |
349 |
nr1 := Integer readFrom:s. |
|
350 |
s peek == $, ifTrue:[ |
|
351 |
s next. |
|
352 |
Integer readFrom:s |
|
353 |
]. |
|
354 |
op := s next. |
|
355 |
nr2 := Integer readFrom:s. |
|
356 |
s peek == $, ifTrue:[ |
|
357 |
s next. |
|
358 |
nr3 := Integer readFrom:s |
|
359 |
] ifFalse:[ |
|
360 |
nr3 := nil |
|
361 |
]. |
|
362 |
||
363 |
op == $c ifTrue:[ |
|
364 |
state := #changed. |
|
365 |
] 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
|
366 |
(op == $a) ifTrue:[ |
183 | 367 |
state := #added. |
368 |
] ifFalse:[ |
|
369 |
op == $d ifTrue:[ |
|
370 |
state := #deleted |
|
371 |
] ifFalse:[ |
|
372 |
self halt:'unexpected diff entry'. |
|
373 |
] |
|
374 |
] |
|
375 |
]. |
|
376 |
||
377 |
]. |
|
378 |
||
379 |
"/ nr1 print. ' ' print. op print. ' ' print. nr2 print. ' , ' print. nr3 printNL. |
|
380 |
||
381 |
" |
|
382 |
copy over unchanged lines |
|
383 |
" |
|
384 |
any := false. |
|
385 |
[idx1 < nr1] whileTrue:[ |
|
386 |
"/ '< add:' print. idx1 printNL. |
|
387 |
l1 add:(text1 at:idx1). |
|
388 |
idx1 := idx1 + 1. |
|
389 |
any := true. |
|
390 |
]. |
|
391 |
[idx2 < nr2] whileTrue:[ |
|
392 |
"/ '> add:' print. idx2 printNL. |
|
393 |
l2 add:(text2 at:idx2). |
|
394 |
idx2 := idx2 + 1. |
|
395 |
any := true. |
|
396 |
]. |
|
397 |
||
398 |
state == #added ifTrue:[ |
|
399 |
l1 add:(text1 at:idx1). |
|
400 |
idx1 := idx1 + 1. |
|
401 |
]. |
|
402 |
state == #deleted ifTrue:[ |
|
403 |
l2 add:(text2 at:idx2). |
|
404 |
idx2 := idx2 + 1. |
|
405 |
]. |
|
406 |
||
407 |
||
408 |
" |
|
409 |
add a separating line, except at end |
|
410 |
" |
|
411 |
any ifTrue:[ |
|
412 |
state ~~ #finish ifTrue:[ |
|
413 |
showSeparators ifTrue:[ |
|
414 |
l1 add:'--------'. |
|
415 |
l2 add:'--------'. |
|
416 |
] |
|
417 |
] |
|
418 |
]. |
|
419 |
||
420 |
] ifFalse:[ |
|
421 |
state == #changed ifTrue:[ |
|
422 |
(entry at:1) == $< ifTrue:[ |
|
423 |
useColors ifTrue:[ |
|
313
c143d37be2e9
lines which differ only in blanks (indent) are shown light-blue
Claus Gittinger <cg@exept.de>
parents:
242
diff
changeset
|
424 |
(l2 size >= idx1 |
318 | 425 |
and:[(s2 := l2 at:idx1) notNil |
2141 | 426 |
and:[(s2 asString withoutSeparators = (text1 at:idx1) withoutSeparators) |
427 |
"/ or:[(s2 asString withoutSeparators withTabsExpanded = (text1 at:idx1) withoutSeparators withTabsExpanded)] |
|
428 |
]]) ifTrue:[ |
|
544
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
429 |
l1 add:(Text string:(text1 at:idx1) |
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
430 |
foregroundColor:changedSpacesOnlyColor |
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
431 |
backgroundColor:changedSpacesOnlyBgColor). |
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
432 |
l2 at:idx1 put:(Text string:(l2 at:idx1) asString |
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
433 |
foregroundColor:changedSpacesOnlyColor |
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
434 |
backgroundColor:changedSpacesOnlyBgColor). |
313
c143d37be2e9
lines which differ only in blanks (indent) are shown light-blue
Claus Gittinger <cg@exept.de>
parents:
242
diff
changeset
|
435 |
] ifFalse:[ |
544
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
436 |
l1 add:(Text string:(text1 at:idx1) |
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
437 |
foregroundColor:changedColor |
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
438 |
backgroundColor:changedBgColor). |
313
c143d37be2e9
lines which differ only in blanks (indent) are shown light-blue
Claus Gittinger <cg@exept.de>
parents:
242
diff
changeset
|
439 |
] |
183 | 440 |
] ifFalse:[ |
441 |
l1 add:(text1 at:idx1). |
|
442 |
]. |
|
443 |
idx1 := idx1 + 1 |
|
444 |
] ifFalse:[ |
|
445 |
(entry at:1) == $> ifTrue:[ |
|
446 |
useColors ifTrue:[ |
|
313
c143d37be2e9
lines which differ only in blanks (indent) are shown light-blue
Claus Gittinger <cg@exept.de>
parents:
242
diff
changeset
|
447 |
(l1 size >= idx2 |
318 | 448 |
and:[(s1 := l1 at:idx2) notNil |
2141 | 449 |
and:[(s1 asString withoutSeparators = (text2 at:idx2) withoutSeparators) |
450 |
"/ or:[(s1 asString withoutSeparators withTabsExpanded = (text2 at:idx2) withoutSeparators withTabsExpanded)] |
|
451 |
]]) ifTrue:[ |
|
544
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
452 |
l2 add:(Text string:(text2 at:idx2) foregroundColor:changedSpacesOnlyColor backgroundColor:changedSpacesOnlyBgColor). |
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
453 |
l1 at:idx2 put:(Text string:(l1 at:idx2) asString foregroundColor:changedSpacesOnlyColor backgroundColor:changedSpacesOnlyBgColor). |
313
c143d37be2e9
lines which differ only in blanks (indent) are shown light-blue
Claus Gittinger <cg@exept.de>
parents:
242
diff
changeset
|
454 |
] ifFalse:[ |
544
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
455 |
l2 add:(Text string:(text2 at:idx2) foregroundColor:changedColor backgroundColor:changedBgColor) |
313
c143d37be2e9
lines which differ only in blanks (indent) are shown light-blue
Claus Gittinger <cg@exept.de>
parents:
242
diff
changeset
|
456 |
] |
183 | 457 |
] ifFalse:[ |
458 |
l2 add:(text2 at:idx2). |
|
459 |
]. |
|
460 |
idx2 := idx2 + 1 |
|
461 |
] ifFalse:[ |
|
462 |
(entry at:1) == $- ifTrue:[ |
|
463 |
] ifFalse:[ |
|
464 |
state := #initial. |
|
465 |
dIdx := dIdx - 1 |
|
466 |
] |
|
467 |
] |
|
468 |
] |
|
469 |
] ifFalse:[ |
|
470 |
state == #added ifTrue:[ |
|
471 |
(entry at:1) == $> ifTrue:[ |
|
472 |
useColors ifTrue:[ |
|
544
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
473 |
l2 add:(Text string:(text2 at:idx2) foregroundColor:addedColor backgroundColor:addedBgColor ) |
183 | 474 |
] ifFalse:[ |
475 |
l2 add:(text2 at:idx2). |
|
476 |
]. |
|
477 |
idx2 := idx2 + 1. |
|
478 |
l1 add:nil |
|
479 |
] ifFalse:[ |
|
480 |
state := #initial. |
|
481 |
dIdx := dIdx - 1 |
|
482 |
] |
|
483 |
] ifFalse:[ |
|
484 |
state == #deleted ifTrue:[ |
|
485 |
(entry at:1) == $< ifTrue:[ |
|
486 |
useColors ifTrue:[ |
|
544
dea45065e7f1
use Text instead of ColoredListEntry
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
487 |
l1 add:(Text string:(text1 at:idx1) foregroundColor:removedColor backgroundColor:removedBgColor ). |
183 | 488 |
] ifFalse:[ |
489 |
l1 add:(text1 at:idx1). |
|
490 |
]. |
|
491 |
idx1 := idx1 + 1. |
|
492 |
l2 add:nil |
|
493 |
] ifFalse:[ |
|
494 |
state := #initial. |
|
495 |
dIdx := dIdx - 1 |
|
496 |
] |
|
497 |
] |
|
498 |
"must be in finish otherwise" |
|
499 |
] |
|
500 |
] |
|
501 |
]. |
|
502 |
dIdx := dIdx + 1 |
|
503 |
]. |
|
504 |
[l1 size < l2 size] whileTrue:[ |
|
505 |
l1 add:''. |
|
506 |
]. |
|
507 |
[l2 size < l1 size] whileTrue:[ |
|
508 |
l2 add:''. |
|
509 |
]. |
|
510 |
textView1 list:l1. |
|
511 |
textView2 list:l2 |
|
512 |
||
2141 | 513 |
"Modified: / 5.5.1999 / 16:08:03 / cg" |
183 | 514 |
! ! |
515 |
||
242 | 516 |
!DiffTextView class methodsFor:'documentation'! |
517 |
||
518 |
version |
|
2246
34262ef77055
comment; look if diff is present and handle the bad case gracious (win32)
Claus Gittinger <cg@exept.de>
parents:
2240
diff
changeset
|
519 |
^ '$Header: /cvs/stx/stx/libtool/DiffTextView.st,v 1.25 1999-07-09 14:56:18 cg Exp $'! ! |