author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 18 Jul 2012 18:00:57 +0100 | |
branch | jv |
changeset 12262 | d25ef6bb0ef3 |
parent 12198 | 414e7b69ecda |
child 12269 | 79f87eee62e5 |
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 |
||
12262 | 30 |
TwoColumnTextView subclass:#DiffCodeView2 |
9978 | 31 |
instanceVariableNames:'' |
32 |
classVariableNames:'' |
|
33 |
poolDictionaries:'' |
|
34 |
category:'Interface-CodeView' |
|
35 |
! |
|
36 |
||
12262 | 37 |
Object subclass:#DiffData |
38 |
instanceVariableNames:'text1 text2 inserted deleted changed' |
|
39 |
classVariableNames:'' |
|
40 |
poolDictionaries:'' |
|
41 |
privateIn:DiffCodeView2 |
|
42 |
! |
|
43 |
||
9978 | 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 |
||
94 |
languageHolder: aValueModel |
|
95 |
||
96 |
textViews do:[:each|each languageHolder: aValueModel]. |
|
97 |
||
98 |
"Created: / 19-07-2011 / 12:55:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
12198
414e7b69ecda
Text/ChangeSet diff improved
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12179
diff
changeset
|
99 |
! |
414e7b69ecda
Text/ChangeSet diff improved
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12179
diff
changeset
|
100 |
|
12262 | 101 |
text1:t1 text2:t2 |
102 |
|data| |
|
12198
414e7b69ecda
Text/ChangeSet diff improved
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12179
diff
changeset
|
103 |
|
12262 | 104 |
data := self computeDiffDataForText1:t1 text2:t2. |
12198
414e7b69ecda
Text/ChangeSet diff improved
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12179
diff
changeset
|
105 |
|
12262 | 106 |
(textViews at:1) |
107 |
contents:(data text1); |
|
108 |
deletedLines:(data deleted); |
|
109 |
changedLines:(data changed); |
|
110 |
insertedLines:#(); |
|
111 |
originDiffText:t1; |
|
112 |
emptyLines:(data inserted). |
|
12198
414e7b69ecda
Text/ChangeSet diff improved
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12179
diff
changeset
|
113 |
|
12262 | 114 |
(textViews at:2) |
115 |
contents:(data text2); |
|
116 |
deletedLines:#(); |
|
117 |
changedLines:(data changed); |
|
118 |
insertedLines:(data inserted); |
|
119 |
originDiffText:t2; |
|
120 |
emptyLines:(data deleted). |
|
12198
414e7b69ecda
Text/ChangeSet diff improved
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12179
diff
changeset
|
121 |
|
12262 | 122 |
"Created: / 06-03-2010 / 10:45:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
123 |
"Modified: / 22-06-2010 / 21:36:35 / Jakub <zelenja7@fel.cvut.cz>" |
|
124 |
"Modified: / 15-07-2010 / 23:08:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
9978 | 125 |
! ! |
126 |
||
127 |
!DiffCodeView2 methodsFor:'initialization'! |
|
128 |
||
129 |
initialize |
|
130 |
||
131 |
super initialize. |
|
132 |
textViews do: |
|
133 |
[:thisView| |
|
134 |
thisView diffMode: true. |
|
135 |
thisView ~= textViews first ifTrue: |
|
136 |
[thisView showGutterChannel value: false]. |
|
137 |
textViews do: |
|
138 |
[:otherView| |
|
139 |
thisView == otherView ifFalse: |
|
140 |
[thisView synchronizeWith: otherView]]]. |
|
141 |
||
142 |
"Created: / 06-04-2010 / 14:15:03 / Jakub <zelenja7@fel.cvut.cz>" |
|
143 |
"Modified: / 23-06-2010 / 19:36:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
144 |
! ! |
|
145 |
||
12262 | 146 |
!DiffCodeView2 methodsFor:'private'! |
147 |
||
148 |
computeDiffDataForText1:t1 text2:t2 |
|
149 |
"created diffText object from two strings |
|
150 |
This processes the DiffData as returned by the (now internal) Diff-tool" |
|
151 |
||
152 |
|array1 array2 diff change index1 index2 text1 text2 i diffData deleted inserted helperText addConstant1 addConstant2 changed helper ins del pom| |
|
153 |
||
154 |
"create line arrays from origin text(1 item/row)" |
|
155 |
array1 := self createArray:t1. |
|
156 |
array2 := self createArray:t2. |
|
157 |
"inserted,deleted, cahnged lines" |
|
158 |
inserted := OrderedCollection new. |
|
159 |
deleted := OrderedCollection new. |
|
160 |
changed := OrderedCollection new. |
|
161 |
"indicates which row of origin text is added to ne text" |
|
162 |
index1 := 1. |
|
163 |
index2 := 1. |
|
164 |
"indicate how much rows were deleted or inserted " |
|
165 |
addConstant1 := 0. |
|
166 |
addConstant2 := 0. |
|
167 |
text1 := ''. |
|
168 |
text2 := ''. |
|
169 |
diff := Diff new. |
|
170 |
diff a:array1 b:array2. |
|
171 |
change := diff diff:false. |
|
172 |
diffData := DiffData new. |
|
173 |
[ change notNil ] whileTrue:[ |
|
174 |
"check first lines which are same" |
|
175 |
(((change line0) > 0) and:[ ((change line1) > 0) ]) ifTrue:[ |
|
176 |
[ |
|
177 |
index1 <= (change line0) |
|
178 |
] whileTrue:[ |
|
179 |
helperText := (array1 at:index1) asText. |
|
180 |
text1 := text1 asString , helperText asString. |
|
181 |
index1 := index1 + 1. |
|
182 |
]. |
|
183 |
[ |
|
184 |
index2 <= (change line1) |
|
185 |
] whileTrue:[ |
|
186 |
helperText := (array2 at:index2) asText. |
|
187 |
text2 := text2 , helperText. |
|
188 |
index2 := index2 + 1. |
|
189 |
]. |
|
190 |
]. |
|
191 |
ins := change inserted. |
|
192 |
del := change deleted. |
|
193 |
index1 := (change line0) + 1. |
|
194 |
index2 := (change line1) + 1. |
|
195 |
"find replace files " |
|
196 |
((del > 0) and:[ ins > 0 ]) ifTrue:[ |
|
197 |
helper := del - ins. |
|
198 |
(helper <= 0) ifTrue:[ |
|
199 |
pom := change deleted. |
|
200 |
]. |
|
201 |
(helper > 0) ifTrue:[ |
|
202 |
pom := change inserted. |
|
203 |
]. |
|
204 |
"its same count row" |
|
205 |
i := 1. |
|
206 |
[ i <= pom ] whileTrue:[ |
|
207 |
changed add:index1 + addConstant1. |
|
208 |
text1 := text1 , (array1 at:index1) asString. |
|
209 |
text2 := text2 , (array2 at:index2) asString. |
|
210 |
index1 := index1 + 1. |
|
211 |
index2 := index2 + 1. |
|
212 |
del := del - 1. |
|
213 |
ins := ins - 1. |
|
214 |
i := i + 1. |
|
215 |
]. |
|
216 |
]. |
|
217 |
"find deleted files" |
|
218 |
(del > 0) ifTrue:[ |
|
219 |
i := 1. |
|
220 |
[ i <= del ] whileTrue:[ |
|
221 |
deleted add:index1 + addConstant1. |
|
222 |
text2 := text2 , Character cr. |
|
223 |
addConstant2 := addConstant2 + 1. |
|
224 |
text1 := text1 , (array1 at:index1) asString. |
|
225 |
index1 := index1 + 1. |
|
226 |
i := i + 1. |
|
227 |
]. |
|
228 |
]. |
|
229 |
"find inserted lines" |
|
230 |
(ins > 0) ifTrue:[ |
|
231 |
i := 1. |
|
232 |
[ i <= ins ] whileTrue:[ |
|
233 |
inserted add:index2 + addConstant2. |
|
234 |
text1 := text1 , Character cr. |
|
235 |
addConstant1 := addConstant1 + 1. |
|
236 |
text2 := text2 , (array2 at:index2) asString. |
|
237 |
index2 := index2 + 1. |
|
238 |
i := i + 1. |
|
239 |
]. |
|
240 |
]. |
|
241 |
change := change nextLink. |
|
242 |
]. |
|
243 |
"kontrola zda nam nechybi posledni znaky" |
|
244 |
(index1 <= (array1 size)) ifTrue:[ |
|
245 |
[ |
|
246 |
index1 <= (array1 size) |
|
247 |
] whileTrue:[ |
|
248 |
helperText := (array1 at:index1) asText. |
|
249 |
text1 := text1 , helperText. |
|
250 |
index1 := index1 + 1. |
|
251 |
]. |
|
252 |
]. |
|
253 |
(index2 <= (array2 size)) ifTrue:[ |
|
254 |
[ |
|
255 |
index2 <= (array2 size) |
|
256 |
] whileTrue:[ |
|
257 |
helperText := (array2 at:index2) asText. |
|
258 |
text2 := text2 , helperText. |
|
259 |
index2 := index2 + 1. |
|
260 |
]. |
|
261 |
]. |
|
262 |
diffData text1:text1. |
|
263 |
diffData text2:text2. |
|
264 |
diffData changed:changed. |
|
265 |
diffData inserted:inserted. |
|
266 |
diffData deleted:deleted. |
|
267 |
^ diffData. |
|
268 |
||
269 |
"Modified: / 22-06-2010 / 21:02:50 / Jakub <zelenja7@fel.cvut.cz>" |
|
270 |
"Modified: / 24-06-2010 / 21:07:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
271 |
"Modified: / 17-07-2012 / 18:55:01 / cg" |
|
272 |
! |
|
273 |
||
274 |
createArray:text1 |
|
275 |
"cg: isn't that an obfuscated variation of #asCollectionOfLines ?" |
|
276 |
||
277 |
^ text1 asStringCollection. "/ yes, it looks like !! |
|
278 |
"/ | array src line c | |
|
279 |
"/ |
|
280 |
"/ array := StringCollection new. |
|
281 |
"/ src := text1 readStream. |
|
282 |
"/ line := (String new: 80) writeStream. |
|
283 |
"/ [ src atEnd ] whileFalse:[ |
|
284 |
"/ c := src next. |
|
285 |
"/ line nextPut: c. |
|
286 |
"/ c == Character cr ifTrue:[ |
|
287 |
"/ array add: line contents. |
|
288 |
"/ line reset. |
|
289 |
"/ ] |
|
290 |
"/ ]. |
|
291 |
"/ line position ~~ 0 ifTrue:[ |
|
292 |
"/ array add: line contents |
|
293 |
"/ ]. |
|
294 |
"/ ^array |
|
295 |
||
296 |
"Created: / 22-03-2010 / 14:48:27 / Jakub <zelenja7@fel.cvut.cz>" |
|
297 |
"Modified (comment): / 19-07-2011 / 11:14:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
298 |
"Modified: / 17-07-2012 / 18:55:21 / cg" |
|
299 |
! ! |
|
300 |
||
301 |
!DiffCodeView2::DiffData methodsFor:'accessing'! |
|
302 |
||
303 |
changed |
|
304 |
||
305 |
^changed copy |
|
306 |
||
307 |
"Modified: / 02-05-2010 / 19:31:18 / Jakub <zelenja7@fel.cvut.cz>" |
|
308 |
"Modified: / 16-07-2010 / 09:35:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
309 |
! |
|
310 |
||
311 |
changed:something |
|
312 |
changed := something. |
|
313 |
! |
|
314 |
||
315 |
deleted |
|
316 |
^ deleted |
|
317 |
! |
|
318 |
||
319 |
deleted:something |
|
320 |
deleted := something. |
|
321 |
! |
|
322 |
||
323 |
inserted |
|
324 |
^ inserted |
|
325 |
! |
|
326 |
||
327 |
inserted:something |
|
328 |
inserted := something. |
|
329 |
! |
|
330 |
||
331 |
text1 |
|
332 |
^ text1 |
|
333 |
! |
|
334 |
||
335 |
text1:something |
|
336 |
text1 := something. |
|
337 |
! |
|
338 |
||
339 |
text2 |
|
340 |
^ text2 |
|
341 |
! |
|
342 |
||
343 |
text2:something |
|
344 |
text2 := something. |
|
345 |
! ! |
|
346 |
||
9978 | 347 |
!DiffCodeView2 class methodsFor:'documentation'! |
348 |
||
349 |
version_CVS |
|
12262 | 350 |
^ 'Header: /cvs/stx/stx/libtool/Tools__DiffCodeView2.st,v 1.4 2012/07/17 17:03:25 cg Exp ' |
9978 | 351 |
! |
352 |
||
353 |
version_SVN |
|
12262 | 354 |
^ '$Id: Tools__DiffCodeView2.st 8018 2012-07-18 17:00:57Z vranyj1 $' |
355 |
! ! |