author | Claus Gittinger <cg@exept.de> |
Fri, 09 Jul 1999 16:55:32 +0200 | |
changeset 2245 | 0d94b4d7d4bc |
parent 713 | bbed5ec2fbeb |
child 2851 | 1d2fabb348d2 |
permissions | -rw-r--r-- |
271 | 1 |
" |
277 | 2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
3 |
All Rights Reserved |
|
271 | 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 |
ThreeColumnTextView subclass:#Diff3TextView |
|
14 |
instanceVariableNames:'useColors showSeparators addedColor addedBgColor removedColor |
|
15 |
removedBgColor changedColor changedBgColor' |
|
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Views-Text' |
|
19 |
! |
|
20 |
||
2245 | 21 |
!Diff3TextView class methodsFor:'documentation'! |
271 | 22 |
|
23 |
copyright |
|
24 |
" |
|
277 | 25 |
COPYRIGHT (c) 1995 by Claus Gittinger |
26 |
All Rights Reserved |
|
271 | 27 |
|
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
37 |
documentation |
|
38 |
" |
|
277 | 39 |
a view showing merged diff3 (see rcsmerge / merge unix manual pages) output in a |
271 | 40 |
user-friendly form. |
41 |
The view is created and opened with: |
|
42 |
||
277 | 43 |
d := Diff3TextView openOn:text label:l1 label:l2 label:l3. |
271 | 44 |
|
277 | 45 |
and it will show the 3 versions side-by-side |
46 |
Its main use is for the SourceCodeManager, to show merged sources after |
|
47 |
a failed checkin. |
|
2245 | 48 |
|
49 |
Notice: |
|
50 |
This has diff3 output (or cvs diff output) hardwired into it. |
|
51 |
Needs to be adapted, if that format ever changes. |
|
52 |
||
53 |
[see also:] |
|
54 |
TextView EditTextView DiffTextView |
|
55 |
||
56 |
[author:] |
|
57 |
Claus Gittinger |
|
271 | 58 |
" |
59 |
! ! |
|
60 |
||
2245 | 61 |
!Diff3TextView class methodsFor:'instance creation'! |
271 | 62 |
|
63 |
openOnMergedText:text label:firstLabel label:secondLabel label:thirdLabel |
|
64 |
"open up a view showing firstText, secondText and thirdText side-by-side, |
|
65 |
and labels for all views." |
|
66 |
||
67 |
|top v l1 l2 l3| |
|
68 |
||
69 |
top := StandardSystemView label:'three texts'. |
|
70 |
||
71 |
l1 := Label label:firstLabel in:top. |
|
72 |
l1 origin:0.0@0.0 corner:0.33@(l1 height). |
|
73 |
l2 := Label label:secondLabel in:top. |
|
74 |
l2 origin:0.33@0.0 corner:0.67@(l1 height). |
|
75 |
l3 := Label label:thirdLabel in:top. |
|
76 |
l3 origin:0.67@0.0 corner:1.0@(l1 height). |
|
77 |
||
78 |
v := HVScrollableView |
|
79 |
for:self |
|
80 |
miniScrollerH:true miniScrollerV:false |
|
81 |
in:top. |
|
82 |
v origin:0.0 @ (l1 height + ViewSpacing) corner:1.0 @ 1.0. |
|
83 |
v scrolledView updateListsFromMergedText:text. |
|
2245 | 84 |
|
85 |
"/ self addNextPreviousButtons. |
|
271 | 86 |
^ top open |
87 |
||
88 |
" |
|
89 |
ThreeColumnTextView |
|
90 |
openOn:('smalltalk.rc' asFilename contentsOfEntireFile) |
|
91 |
label:'smalltalk.rc' |
|
92 |
and:('display.rc' asFilename contentsOfEntireFile) |
|
93 |
label:'display.rc' |
|
94 |
and:('private.rc' asFilename contentsOfEntireFile) |
|
95 |
label:'private.rc' |
|
96 |
" |
|
97 |
||
98 |
"Modified: 12.12.1995 / 13:09:13 / cg" |
|
99 |
! ! |
|
100 |
||
2245 | 101 |
!Diff3TextView class methodsFor:'public helpers'! |
713 | 102 |
|
103 |
emphasizeMergedDiff3Text:mergedText emphasize1:e1 emphasize2:e2 emphasizeSep:e3 |
|
104 |
"given the merge()/rcsmerge() merged output (as created by 'cvs update'), |
|
105 |
create & return a text object which contains the conflicts |
|
106 |
highlighted. |
|
107 |
CAVEAT: this is a highly specialized method - probably not the right place |
|
108 |
for it here ..." |
|
109 |
||
110 |
|dIdx dEnd state s entry c list skip sep| |
|
111 |
||
112 |
list := OrderedCollection new. |
|
113 |
||
114 |
dIdx := 1. |
|
115 |
dEnd := mergedText size + 1. |
|
116 |
state := #initial. |
|
117 |
[dIdx < dEnd] whileTrue:[ |
|
118 |
dIdx == dEnd ifTrue:[ |
|
119 |
"dummy cleanup entry" |
|
120 |
entry := nil. |
|
121 |
state := #initial. |
|
122 |
] ifFalse:[ |
|
123 |
entry := mergedText at:dIdx. |
|
124 |
dIdx := dIdx + 1. |
|
125 |
]. |
|
126 |
||
127 |
skip := false. |
|
128 |
||
129 |
entry notNil ifTrue:[ |
|
130 |
sep := nil. |
|
131 |
||
132 |
(entry startsWith:'<<<<<<<') ifTrue:[ |
|
133 |
state := 1. skip := true. sep := '----- your version ----'. |
|
134 |
] ifFalse:[ |
|
135 |
(entry startsWith:'|||||||') ifTrue:[ |
|
136 |
state := 2. skip := true. |
|
137 |
] ifFalse:[ |
|
138 |
(entry startsWith:'=======') ifTrue:[ |
|
139 |
state == 2 ifFalse:[ |
|
140 |
state := 23 "/ on both 2 and 3 |
|
141 |
] ifTrue:[ |
|
142 |
state := 3 "/ only in 3 |
|
143 |
]. |
|
144 |
skip := true. |
|
145 |
sep := '----- other version ----'. |
|
146 |
] ifFalse:[ |
|
147 |
(entry startsWith:'>>>>>>>') ifTrue:[ |
|
148 |
state := #initial. |
|
149 |
skip := true. |
|
150 |
sep := '------------------------'. |
|
151 |
] |
|
152 |
] |
|
153 |
] |
|
154 |
]. |
|
155 |
||
156 |
sep notNil ifTrue:[ |
|
157 |
list add:(Text |
|
158 |
string:sep |
|
159 |
emphasis:e3). |
|
160 |
]. |
|
161 |
||
162 |
skip ifFalse:[ |
|
163 |
state == #initial ifTrue:[ |
|
164 |
list add:entry |
|
165 |
]. |
|
166 |
state == 1 ifTrue:[ |
|
167 |
e1 notNil ifTrue:[ |
|
168 |
list add:(Text string:entry emphasis:e1) |
|
169 |
] ifFalse:[ |
|
170 |
list add:entry |
|
171 |
] |
|
172 |
]. |
|
173 |
(state == 3 or:[state == 23]) ifTrue:[ |
|
174 |
e2 notNil ifTrue:[ |
|
175 |
list add:(Text string:entry emphasis:e2) |
|
176 |
] ifFalse:[ |
|
177 |
list add:entry |
|
178 |
] |
|
179 |
]. |
|
180 |
]. |
|
181 |
]. |
|
182 |
]. |
|
183 |
||
184 |
^ list |
|
185 |
||
186 |
"Created: 9.9.1996 / 19:54:00 / cg" |
|
187 |
"Modified: 9.9.1996 / 20:41:40 / cg" |
|
188 |
! ! |
|
189 |
||
271 | 190 |
!Diff3TextView methodsFor:'initialization'! |
191 |
||
192 |
initStyle |
|
193 |
super initStyle. |
|
194 |
||
195 |
showSeparators := false. |
|
196 |
||
197 |
useColors := ColoredListEntry notNil. |
|
198 |
useColors ifTrue:[ |
|
199 |
device hasColors ifTrue:[ |
|
200 |
addedColor := Color black. |
|
201 |
addedBgColor := Color green. |
|
202 |
||
203 |
removedColor := Color white. |
|
204 |
removedBgColor := Color red. |
|
205 |
||
206 |
changedColor := Color white. |
|
207 |
changedBgColor := Color blue. |
|
208 |
] ifFalse:[ |
|
209 |
addedBgColor := removedBgColor := changedBgColor := Color black. |
|
210 |
addedColor := removedColor := changedColor := Color white. |
|
211 |
] |
|
212 |
]. |
|
213 |
||
214 |
"Created: 16.11.1995 / 16:59:48 / cg" |
|
215 |
"Modified: 12.12.1995 / 12:25:55 / cg" |
|
216 |
! ! |
|
217 |
||
218 |
!Diff3TextView methodsFor:'private'! |
|
219 |
||
220 |
updateListsFromMergedText:mergedText |
|
221 |
"given the merge()/rcsmerge() merged output (as created by 'cvs update'), |
|
222 |
update my views contents" |
|
223 |
||
224 |
|idx1 idx2 idx3 dIdx dEnd state s nr1 nr2 nr3 entry c l1 l2 l3 |
|
225 |
textView1 textView2 textView3 skip max| |
|
226 |
||
227 |
textView1 := textViews at:1. |
|
228 |
textView2 := textViews at:2. |
|
229 |
textView3 := textViews at:3. |
|
230 |
||
231 |
l1 := OrderedCollection new. |
|
232 |
l2 := OrderedCollection new. |
|
233 |
l3 := OrderedCollection new. |
|
234 |
||
235 |
idx1 := 1. |
|
236 |
idx2 := 1. |
|
237 |
idx3 := 1. |
|
238 |
||
239 |
dIdx := 1. |
|
240 |
dEnd := mergedText size + 1. |
|
241 |
state := #initial. |
|
242 |
[dIdx < dEnd] whileTrue:[ |
|
243 |
dIdx == dEnd ifTrue:[ |
|
244 |
"dummy cleanup entry" |
|
245 |
entry := nil. |
|
246 |
state := #initial. |
|
247 |
] ifFalse:[ |
|
248 |
entry := mergedText at:dIdx. |
|
249 |
dIdx := dIdx + 1. |
|
250 |
]. |
|
251 |
||
252 |
state == #initial ifTrue:[ |
|
253 |
" |
|
254 |
fill up to size difference from previous change |
|
255 |
" |
|
256 |
max := (l1 size max:l2 size) max:l3 size. |
|
257 |
[l1 size < max] whileTrue:[ |
|
258 |
l1 add:nil |
|
259 |
]. |
|
260 |
[l2 size < max] whileTrue:[ |
|
261 |
l2 add:nil |
|
262 |
]. |
|
263 |
[l3 size < max] whileTrue:[ |
|
264 |
l3 add:nil |
|
265 |
]. |
|
266 |
||
267 |
" |
|
268 |
except for the first chunk, add a separating line |
|
269 |
" |
|
270 |
l1 size ~~ 0 ifTrue:[ |
|
271 |
showSeparators ifTrue:[ |
|
272 |
l1 add:'--------'. |
|
273 |
l2 add:'--------'. |
|
274 |
l3 add:'--------'. |
|
275 |
] |
|
276 |
]. |
|
277 |
]. |
|
278 |
||
279 |
skip := false. |
|
280 |
||
281 |
entry notNil ifTrue:[ |
|
282 |
(entry startsWith:'<<<<<<<') ifTrue:[ |
|
283 |
state := 1. skip := true. |
|
284 |
] ifFalse:[ |
|
285 |
(entry startsWith:'|||||||') ifTrue:[ |
|
286 |
state := 2. skip := true. |
|
287 |
] ifFalse:[ |
|
288 |
(entry startsWith:'=======') ifTrue:[ |
|
290
5b9361cfa7b8
oops - merge output is different than expected sometimes
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
289 |
state == 2 ifFalse:[ |
5b9361cfa7b8
oops - merge output is different than expected sometimes
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
290 |
state := 23 "/ on both 2 and 3 |
5b9361cfa7b8
oops - merge output is different than expected sometimes
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
291 |
] ifTrue:[ |
5b9361cfa7b8
oops - merge output is different than expected sometimes
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
292 |
state := 3 "/ only in 3 |
5b9361cfa7b8
oops - merge output is different than expected sometimes
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
293 |
]. |
5b9361cfa7b8
oops - merge output is different than expected sometimes
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
294 |
skip := true. |
271 | 295 |
] ifFalse:[ |
296 |
(entry startsWith:'>>>>>>>') ifTrue:[ |
|
297 |
state := #initial. |
|
298 |
skip := true. |
|
299 |
] |
|
300 |
] |
|
301 |
] |
|
302 |
]. |
|
303 |
||
304 |
skip ifFalse:[ |
|
305 |
(state == #initial or:[state == 1]) ifTrue:[ |
|
306 |
(useColors and:[state == 1]) ifTrue:[ |
|
307 |
l1 add:(ColoredListEntry string:entry foregroundColor:changedColor backgroundColor:changedBgColor). |
|
308 |
] ifFalse:[ |
|
309 |
l1 add:entry |
|
310 |
] |
|
311 |
]. |
|
290
5b9361cfa7b8
oops - merge output is different than expected sometimes
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
312 |
(state == #initial or:[state == 2 or:[state == 23]]) ifTrue:[ |
5b9361cfa7b8
oops - merge output is different than expected sometimes
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
313 |
(useColors and:[state == 2 or:[state == 23]]) ifTrue:[ |
271 | 314 |
l2 add:(ColoredListEntry string:entry foregroundColor:changedColor backgroundColor:changedBgColor). |
315 |
] ifFalse:[ |
|
316 |
l2 add:entry |
|
317 |
] |
|
318 |
]. |
|
290
5b9361cfa7b8
oops - merge output is different than expected sometimes
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
319 |
(state == #initial or:[state == 3 or:[state == 23]]) ifTrue:[ |
5b9361cfa7b8
oops - merge output is different than expected sometimes
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
320 |
(useColors and:[state == 3 or:[state == 23]]) ifTrue:[ |
271 | 321 |
l3 add:(ColoredListEntry string:entry foregroundColor:changedColor backgroundColor:changedBgColor). |
322 |
] ifFalse:[ |
|
323 |
l3 add:entry |
|
324 |
] |
|
325 |
]. |
|
326 |
]. |
|
327 |
]. |
|
328 |
]. |
|
329 |
||
330 |
textView1 list:l1. |
|
331 |
textView2 list:l2. |
|
332 |
textView3 list:l3. |
|
333 |
||
290
5b9361cfa7b8
oops - merge output is different than expected sometimes
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
334 |
"Modified: 13.12.1995 / 19:56:32 / cg" |
271 | 335 |
! ! |
336 |
||
2245 | 337 |
!Diff3TextView class methodsFor:'documentation'! |
271 | 338 |
|
339 |
version |
|
2245 | 340 |
^ '$Header: /cvs/stx/stx/libtool/Diff3TextView.st,v 1.5 1999-07-09 14:55:32 cg Exp $' |
271 | 341 |
! ! |