author | Claus Gittinger <cg@exept.de> |
Mon, 12 May 2014 19:58:40 +0200 | |
changeset 14355 | bb39d11673d7 |
parent 13808 | 4f97b7921d6e |
child 14370 | bb3f3eec9f1b |
permissions | -rw-r--r-- |
9978 | 1 |
" |
10074 | 2 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague |
3 |
All Rights Reserved |
|
9978 | 4 |
|
10074 | 5 |
Permission is hereby granted, free of charge, to any person |
6 |
obtaining a copy of this software and associated documentation |
|
7 |
files (the 'Software'), to deal in the Software without |
|
8 |
restriction, including without limitation the rights to use, |
|
9 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
10 |
copies of the Software, and to permit persons to whom the |
|
11 |
Software is furnished to do so, subject to the following |
|
12 |
conditions: |
|
13 |
||
14 |
The above copyright notice and this permission notice shall be |
|
15 |
included in all copies or substantial portions of the Software. |
|
16 |
||
17 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
18 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
19 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
20 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
21 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
22 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
23 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
24 |
OTHER DEALINGS IN THE SOFTWARE. |
|
9978 | 25 |
" |
26 |
"{ Package: 'stx:libtool' }" |
|
27 |
||
28 |
"{ NameSpace: Tools }" |
|
29 |
||
30 |
TwoColumnTextView subclass:#DiffCodeView2 |
|
31 |
instanceVariableNames:'' |
|
32 |
classVariableNames:'' |
|
33 |
poolDictionaries:'' |
|
34 |
category:'Interface-CodeView' |
|
35 |
! |
|
36 |
||
37 |
Object subclass:#DiffData |
|
38 |
instanceVariableNames:'text1 text2 inserted deleted changed' |
|
39 |
classVariableNames:'' |
|
40 |
poolDictionaries:'' |
|
41 |
privateIn:DiffCodeView2 |
|
42 |
! |
|
43 |
||
44 |
!DiffCodeView2 class methodsFor:'documentation'! |
|
45 |
||
46 |
copyright |
|
47 |
" |
|
10074 | 48 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague |
49 |
All Rights Reserved |
|
50 |
||
51 |
Permission is hereby granted, free of charge, to any person |
|
52 |
obtaining a copy of this software and associated documentation |
|
53 |
files (the 'Software'), to deal in the Software without |
|
54 |
restriction, including without limitation the rights to use, |
|
55 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
56 |
copies of the Software, and to permit persons to whom the |
|
57 |
Software is furnished to do so, subject to the following |
|
58 |
conditions: |
|
9978 | 59 |
|
10074 | 60 |
The above copyright notice and this permission notice shall be |
61 |
included in all copies or substantial portions of the Software. |
|
62 |
||
63 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
64 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
65 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
66 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
67 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
68 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
69 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
70 |
OTHER DEALINGS IN THE SOFTWARE. |
|
9978 | 71 |
" |
72 |
! ! |
|
73 |
||
74 |
!DiffCodeView2 class methodsFor:'defaults'! |
|
75 |
||
76 |
textViewClass |
|
77 |
"return the type of the synced subViews. |
|
78 |
Can be redefined in subclasses" |
|
79 |
||
80 |
^ Tools::CodeView2 |
|
81 |
||
82 |
"Created: / 06-03-2010 / 10:40:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
83 |
! ! |
|
84 |
||
85 |
!DiffCodeView2 methodsFor:'accessing'! |
|
86 |
||
10331 | 87 |
classHolder: aValueModel |
88 |
||
89 |
textViews do:[:each|each classHolder: aValueModel]. |
|
90 |
||
91 |
"Created: / 19-07-2011 / 12:55:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
92 |
! |
|
93 |
||
11707 | 94 |
codeAspect:aSymbol |
95 |
textViews do:[:each|each codeAspect:aSymbol]. |
|
96 |
||
97 |
"Created: / 27-07-2012 / 23:24:46 / cg" |
|
98 |
! |
|
99 |
||
10331 | 100 |
languageHolder: aValueModel |
101 |
||
102 |
textViews do:[:each|each languageHolder: aValueModel]. |
|
103 |
||
104 |
"Created: / 19-07-2011 / 12:55:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
105 |
! |
|
106 |
||
13808 | 107 |
modeHolder: aValueModel |
108 |
||
109 |
textViews do:[:each|each modeHolder: aValueModel]. |
|
110 |
||
111 |
"Created: / 26-07-2012 / 19:19:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
112 |
! |
|
113 |
||
9978 | 114 |
text1:t1 text2:t2 |
115 |
|data| |
|
116 |
||
117 |
data := self computeDiffDataForText1:t1 text2:t2. |
|
118 |
||
119 |
(textViews at:1) |
|
120 |
contents:(data text1); |
|
121 |
deletedLines:(data deleted); |
|
122 |
changedLines:(data changed); |
|
123 |
insertedLines:#(); |
|
124 |
originDiffText:t1; |
|
125 |
emptyLines:(data inserted). |
|
126 |
||
127 |
(textViews at:2) |
|
128 |
contents:(data text2); |
|
129 |
deletedLines:#(); |
|
130 |
changedLines:(data changed); |
|
131 |
insertedLines:(data inserted); |
|
132 |
originDiffText:t2; |
|
133 |
emptyLines:(data deleted). |
|
134 |
||
135 |
"Created: / 06-03-2010 / 10:45:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
136 |
"Modified: / 22-06-2010 / 21:36:35 / Jakub <zelenja7@fel.cvut.cz>" |
|
137 |
"Modified: / 15-07-2010 / 23:08:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
138 |
! ! |
|
139 |
||
140 |
!DiffCodeView2 methodsFor:'initialization'! |
|
141 |
||
142 |
initialize |
|
143 |
||
144 |
super initialize. |
|
145 |
textViews do: |
|
146 |
[:thisView| |
|
147 |
thisView diffMode: true. |
|
148 |
thisView ~= textViews first ifTrue: |
|
149 |
[thisView showGutterChannel value: false]. |
|
150 |
textViews do: |
|
151 |
[:otherView| |
|
152 |
thisView == otherView ifFalse: |
|
153 |
[thisView synchronizeWith: otherView]]]. |
|
154 |
||
155 |
"Created: / 06-04-2010 / 14:15:03 / Jakub <zelenja7@fel.cvut.cz>" |
|
156 |
"Modified: / 23-06-2010 / 19:36:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
157 |
! ! |
|
158 |
||
159 |
!DiffCodeView2 methodsFor:'private'! |
|
160 |
||
161 |
computeDiffDataForText1:t1 text2:t2 |
|
11598
0350a5f84be7
comment/format in: #computeDiffDataForText1:text2:
Claus Gittinger <cg@exept.de>
parents:
10331
diff
changeset
|
162 |
"created diffText object from two strings |
0350a5f84be7
comment/format in: #computeDiffDataForText1:text2:
Claus Gittinger <cg@exept.de>
parents:
10331
diff
changeset
|
163 |
This processes the DiffData as returned by the (now internal) Diff-tool" |
9978 | 164 |
|
11598
0350a5f84be7
comment/format in: #computeDiffDataForText1:text2:
Claus Gittinger <cg@exept.de>
parents:
10331
diff
changeset
|
165 |
|array1 array2 diff change index1 index2 text1 text2 i diffData deleted inserted helperText addConstant1 addConstant2 changed helper ins del pom| |
9978 | 166 |
|
11598
0350a5f84be7
comment/format in: #computeDiffDataForText1:text2:
Claus Gittinger <cg@exept.de>
parents:
10331
diff
changeset
|
167 |
"create line arrays from origin text(1 item/row)" |
9978 | 168 |
array1 := self createArray:t1. |
169 |
array2 := self createArray:t2. |
|
170 |
"inserted,deleted, cahnged lines" |
|
171 |
inserted := OrderedCollection new. |
|
172 |
deleted := OrderedCollection new. |
|
173 |
changed := OrderedCollection new. |
|
174 |
"indicates which row of origin text is added to ne text" |
|
175 |
index1 := 1. |
|
176 |
index2 := 1. |
|
177 |
"indicate how much rows were deleted or inserted " |
|
178 |
addConstant1 := 0. |
|
179 |
addConstant2 := 0. |
|
180 |
text1 := ''. |
|
181 |
text2 := ''. |
|
182 |
diff := Diff new. |
|
183 |
diff a:array1 b:array2. |
|
184 |
change := diff diff:false. |
|
11598
0350a5f84be7
comment/format in: #computeDiffDataForText1:text2:
Claus Gittinger <cg@exept.de>
parents:
10331
diff
changeset
|
185 |
diffData := DiffData new. |
9978 | 186 |
[ change notNil ] whileTrue:[ |
187 |
"check first lines which are same" |
|
188 |
(((change line0) > 0) and:[ ((change line1) > 0) ]) ifTrue:[ |
|
189 |
[ |
|
190 |
index1 <= (change line0) |
|
191 |
] whileTrue:[ |
|
192 |
helperText := (array1 at:index1) asText. |
|
193 |
text1 := text1 asString , helperText asString. |
|
194 |
index1 := index1 + 1. |
|
195 |
]. |
|
196 |
[ |
|
197 |
index2 <= (change line1) |
|
198 |
] whileTrue:[ |
|
199 |
helperText := (array2 at:index2) asText. |
|
200 |
text2 := text2 , helperText. |
|
201 |
index2 := index2 + 1. |
|
202 |
]. |
|
203 |
]. |
|
204 |
ins := change inserted. |
|
205 |
del := change deleted. |
|
206 |
index1 := (change line0) + 1. |
|
207 |
index2 := (change line1) + 1. |
|
208 |
"find replace files " |
|
209 |
((del > 0) and:[ ins > 0 ]) ifTrue:[ |
|
210 |
helper := del - ins. |
|
211 |
(helper <= 0) ifTrue:[ |
|
212 |
pom := change deleted. |
|
213 |
]. |
|
214 |
(helper > 0) ifTrue:[ |
|
215 |
pom := change inserted. |
|
216 |
]. |
|
217 |
"its same count row" |
|
218 |
i := 1. |
|
219 |
[ i <= pom ] whileTrue:[ |
|
220 |
changed add:index1 + addConstant1. |
|
221 |
text1 := text1 , (array1 at:index1) asString. |
|
222 |
text2 := text2 , (array2 at:index2) asString. |
|
223 |
index1 := index1 + 1. |
|
224 |
index2 := index2 + 1. |
|
225 |
del := del - 1. |
|
226 |
ins := ins - 1. |
|
227 |
i := i + 1. |
|
228 |
]. |
|
229 |
]. |
|
230 |
"find deleted files" |
|
231 |
(del > 0) ifTrue:[ |
|
232 |
i := 1. |
|
233 |
[ i <= del ] whileTrue:[ |
|
234 |
deleted add:index1 + addConstant1. |
|
235 |
text2 := text2 , Character cr. |
|
236 |
addConstant2 := addConstant2 + 1. |
|
237 |
text1 := text1 , (array1 at:index1) asString. |
|
238 |
index1 := index1 + 1. |
|
239 |
i := i + 1. |
|
240 |
]. |
|
241 |
]. |
|
242 |
"find inserted lines" |
|
243 |
(ins > 0) ifTrue:[ |
|
244 |
i := 1. |
|
245 |
[ i <= ins ] whileTrue:[ |
|
246 |
inserted add:index2 + addConstant2. |
|
247 |
text1 := text1 , Character cr. |
|
248 |
addConstant1 := addConstant1 + 1. |
|
249 |
text2 := text2 , (array2 at:index2) asString. |
|
250 |
index2 := index2 + 1. |
|
251 |
i := i + 1. |
|
252 |
]. |
|
253 |
]. |
|
254 |
change := change nextLink. |
|
255 |
]. |
|
256 |
"kontrola zda nam nechybi posledni znaky" |
|
257 |
(index1 <= (array1 size)) ifTrue:[ |
|
258 |
[ |
|
259 |
index1 <= (array1 size) |
|
260 |
] whileTrue:[ |
|
261 |
helperText := (array1 at:index1) asText. |
|
262 |
text1 := text1 , helperText. |
|
263 |
index1 := index1 + 1. |
|
264 |
]. |
|
265 |
]. |
|
266 |
(index2 <= (array2 size)) ifTrue:[ |
|
267 |
[ |
|
268 |
index2 <= (array2 size) |
|
269 |
] whileTrue:[ |
|
270 |
helperText := (array2 at:index2) asText. |
|
271 |
text2 := text2 , helperText. |
|
272 |
index2 := index2 + 1. |
|
273 |
]. |
|
274 |
]. |
|
11598
0350a5f84be7
comment/format in: #computeDiffDataForText1:text2:
Claus Gittinger <cg@exept.de>
parents:
10331
diff
changeset
|
275 |
diffData text1:text1. |
0350a5f84be7
comment/format in: #computeDiffDataForText1:text2:
Claus Gittinger <cg@exept.de>
parents:
10331
diff
changeset
|
276 |
diffData text2:text2. |
0350a5f84be7
comment/format in: #computeDiffDataForText1:text2:
Claus Gittinger <cg@exept.de>
parents:
10331
diff
changeset
|
277 |
diffData changed:changed. |
0350a5f84be7
comment/format in: #computeDiffDataForText1:text2:
Claus Gittinger <cg@exept.de>
parents:
10331
diff
changeset
|
278 |
diffData inserted:inserted. |
0350a5f84be7
comment/format in: #computeDiffDataForText1:text2:
Claus Gittinger <cg@exept.de>
parents:
10331
diff
changeset
|
279 |
diffData deleted:deleted. |
0350a5f84be7
comment/format in: #computeDiffDataForText1:text2:
Claus Gittinger <cg@exept.de>
parents:
10331
diff
changeset
|
280 |
^ diffData. |
9978 | 281 |
|
282 |
"Modified: / 22-06-2010 / 21:02:50 / Jakub <zelenja7@fel.cvut.cz>" |
|
283 |
"Modified: / 24-06-2010 / 21:07:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
11598
0350a5f84be7
comment/format in: #computeDiffDataForText1:text2:
Claus Gittinger <cg@exept.de>
parents:
10331
diff
changeset
|
284 |
"Modified: / 17-07-2012 / 18:55:01 / cg" |
9978 | 285 |
! |
286 |
||
11598
0350a5f84be7
comment/format in: #computeDiffDataForText1:text2:
Claus Gittinger <cg@exept.de>
parents:
10331
diff
changeset
|
287 |
createArray:text1 |
0350a5f84be7
comment/format in: #computeDiffDataForText1:text2:
Claus Gittinger <cg@exept.de>
parents:
10331
diff
changeset
|
288 |
"cg: isn't that an obfuscated variation of #asCollectionOfLines ?" |
9978 | 289 |
|
11679 | 290 |
"/ ^ text1 asStringCollection. "/ yes, it looks like !! |
291 |
||
292 |
"/ JV@2012-07-26: Yes, looks like but it is not!! This version |
|
293 |
"/ keeps CRs in lines. Do not change it back - if you do, DoffCodeView2 |
|
294 |
"/ will show whole source in a single line. |
|
295 |
||
296 |
| array src line c | |
|
297 |
||
298 |
array := StringCollection new. |
|
299 |
src := text1 readStream. |
|
300 |
line := (String new: 80) writeStream. |
|
301 |
[ src atEnd ] whileFalse:[ |
|
302 |
c := src next. |
|
303 |
line nextPut: c. |
|
304 |
c == Character cr ifTrue:[ |
|
305 |
array add: line contents. |
|
306 |
line reset. |
|
307 |
] |
|
308 |
]. |
|
309 |
line position ~~ 0 ifTrue:[ |
|
310 |
array add: line contents |
|
311 |
]. |
|
312 |
^array |
|
9978 | 313 |
|
314 |
"Created: / 22-03-2010 / 14:48:27 / Jakub <zelenja7@fel.cvut.cz>" |
|
11598
0350a5f84be7
comment/format in: #computeDiffDataForText1:text2:
Claus Gittinger <cg@exept.de>
parents:
10331
diff
changeset
|
315 |
"Modified: / 17-07-2012 / 18:55:21 / cg" |
11679 | 316 |
"Modified (comment): / 26-07-2012 / 21:45:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
9978 | 317 |
! ! |
318 |
||
319 |
!DiffCodeView2::DiffData methodsFor:'accessing'! |
|
320 |
||
321 |
changed |
|
322 |
||
323 |
^changed copy |
|
324 |
||
325 |
"Modified: / 02-05-2010 / 19:31:18 / Jakub <zelenja7@fel.cvut.cz>" |
|
326 |
"Modified: / 16-07-2010 / 09:35:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
327 |
! |
|
328 |
||
329 |
changed:something |
|
330 |
changed := something. |
|
331 |
! |
|
332 |
||
333 |
deleted |
|
334 |
^ deleted |
|
335 |
! |
|
336 |
||
337 |
deleted:something |
|
338 |
deleted := something. |
|
339 |
! |
|
340 |
||
341 |
inserted |
|
342 |
^ inserted |
|
343 |
! |
|
344 |
||
345 |
inserted:something |
|
346 |
inserted := something. |
|
347 |
! |
|
348 |
||
349 |
text1 |
|
350 |
^ text1 |
|
351 |
! |
|
352 |
||
353 |
text1:something |
|
354 |
text1 := something. |
|
355 |
! |
|
356 |
||
357 |
text2 |
|
358 |
^ text2 |
|
359 |
! |
|
360 |
||
361 |
text2:something |
|
362 |
text2 := something. |
|
363 |
! ! |
|
364 |
||
365 |
!DiffCodeView2 class methodsFor:'documentation'! |
|
366 |
||
367 |
version_CVS |
|
13808 | 368 |
^ '$Header: /cvs/stx/stx/libtool/Tools__DiffCodeView2.st,v 1.7 2014-02-05 18:56:22 cg Exp $' |
9978 | 369 |
! |
370 |
||
371 |
version_SVN |
|
13808 | 372 |
^ '$Id: Tools__DiffCodeView2.st,v 1.7 2014-02-05 18:56:22 cg Exp $' |
9978 | 373 |
! ! |
13808 | 374 |