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