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 |
|
|
87 |
text1:t1 text2:t2
|
|
88 |
|data|
|
|
89 |
|
|
90 |
data := self computeDiffDataForText1:t1 text2:t2.
|
|
91 |
|
|
92 |
(textViews at:1)
|
|
93 |
contents:(data text1);
|
|
94 |
deletedLines:(data deleted);
|
|
95 |
changedLines:(data changed);
|
|
96 |
insertedLines:#();
|
|
97 |
originDiffText:t1;
|
|
98 |
emptyLines:(data inserted).
|
|
99 |
|
|
100 |
(textViews at:2)
|
|
101 |
contents:(data text2);
|
|
102 |
deletedLines:#();
|
|
103 |
changedLines:(data changed);
|
|
104 |
insertedLines:(data inserted);
|
|
105 |
originDiffText:t2;
|
|
106 |
emptyLines:(data deleted).
|
|
107 |
|
|
108 |
"Created: / 06-03-2010 / 10:45:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
109 |
"Modified: / 22-06-2010 / 21:36:35 / Jakub <zelenja7@fel.cvut.cz>"
|
|
110 |
"Modified: / 15-07-2010 / 23:08:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
111 |
! !
|
|
112 |
|
|
113 |
!DiffCodeView2 methodsFor:'initialization'!
|
|
114 |
|
|
115 |
initialize
|
|
116 |
|
|
117 |
super initialize.
|
|
118 |
textViews do:
|
|
119 |
[:thisView|
|
|
120 |
thisView diffMode: true.
|
|
121 |
thisView ~= textViews first ifTrue:
|
|
122 |
[thisView showGutterChannel value: false].
|
|
123 |
textViews do:
|
|
124 |
[:otherView|
|
|
125 |
thisView == otherView ifFalse:
|
|
126 |
[thisView synchronizeWith: otherView]]].
|
|
127 |
|
|
128 |
"Created: / 06-04-2010 / 14:15:03 / Jakub <zelenja7@fel.cvut.cz>"
|
|
129 |
"Modified: / 23-06-2010 / 19:36:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
130 |
! !
|
|
131 |
|
|
132 |
!DiffCodeView2 methodsFor:'private'!
|
|
133 |
|
|
134 |
computeDiffDataForText1:t1 text2:t2
|
|
135 |
"created diffText object from two string"
|
|
136 |
|
|
137 |
|array1 array2 diff change index1 index2 text1 text2 i diffHelper deleted inserted helperText addConstant1 addConstant2 changed helper ins del pom|
|
|
138 |
|
|
139 |
"cerate array from origin text(1 item=1 row)"
|
|
140 |
array1 := self createArray:t1.
|
|
141 |
array2 := self createArray:t2.
|
|
142 |
"inserted,deleted, cahnged lines"
|
|
143 |
inserted := OrderedCollection new.
|
|
144 |
deleted := OrderedCollection new.
|
|
145 |
changed := OrderedCollection new.
|
|
146 |
"indicates which row of origin text is added to ne text"
|
|
147 |
index1 := 1.
|
|
148 |
index2 := 1.
|
|
149 |
"indicate how much rows were deleted or inserted "
|
|
150 |
addConstant1 := 0.
|
|
151 |
addConstant2 := 0.
|
|
152 |
text1 := ''.
|
|
153 |
text2 := ''.
|
|
154 |
diff := Diff new.
|
|
155 |
diff a:array1 b:array2.
|
|
156 |
change := diff diff:false.
|
|
157 |
diffHelper := DiffData new.
|
|
158 |
[ change notNil ] whileTrue:[
|
|
159 |
"check first lines which are same"
|
|
160 |
(((change line0) > 0) and:[ ((change line1) > 0) ]) ifTrue:[
|
|
161 |
[
|
|
162 |
index1 <= (change line0)
|
|
163 |
] whileTrue:[
|
|
164 |
helperText := (array1 at:index1) asText.
|
|
165 |
text1 := text1 asString , helperText asString.
|
|
166 |
index1 := index1 + 1.
|
|
167 |
].
|
|
168 |
[
|
|
169 |
index2 <= (change line1)
|
|
170 |
] whileTrue:[
|
|
171 |
helperText := (array2 at:index2) asText.
|
|
172 |
text2 := text2 , helperText.
|
|
173 |
index2 := index2 + 1.
|
|
174 |
].
|
|
175 |
].
|
|
176 |
ins := change inserted.
|
|
177 |
del := change deleted.
|
|
178 |
index1 := (change line0) + 1.
|
|
179 |
index2 := (change line1) + 1.
|
|
180 |
"find replace files "
|
|
181 |
((del > 0) and:[ ins > 0 ]) ifTrue:[
|
|
182 |
helper := del - ins.
|
|
183 |
(helper <= 0) ifTrue:[
|
|
184 |
pom := change deleted.
|
|
185 |
].
|
|
186 |
(helper > 0) ifTrue:[
|
|
187 |
pom := change inserted.
|
|
188 |
].
|
|
189 |
"its same count row"
|
|
190 |
i := 1.
|
|
191 |
[ i <= pom ] whileTrue:[
|
|
192 |
changed add:index1 + addConstant1.
|
|
193 |
text1 := text1 , (array1 at:index1) asString.
|
|
194 |
text2 := text2 , (array2 at:index2) asString.
|
|
195 |
index1 := index1 + 1.
|
|
196 |
index2 := index2 + 1.
|
|
197 |
del := del - 1.
|
|
198 |
ins := ins - 1.
|
|
199 |
i := i + 1.
|
|
200 |
].
|
|
201 |
].
|
|
202 |
"find deleted files"
|
|
203 |
(del > 0) ifTrue:[
|
|
204 |
i := 1.
|
|
205 |
[ i <= del ] whileTrue:[
|
|
206 |
deleted add:index1 + addConstant1.
|
|
207 |
text2 := text2 , Character cr.
|
|
208 |
addConstant2 := addConstant2 + 1.
|
|
209 |
text1 := text1 , (array1 at:index1) asString.
|
|
210 |
index1 := index1 + 1.
|
|
211 |
i := i + 1.
|
|
212 |
].
|
|
213 |
].
|
|
214 |
"find inserted lines"
|
|
215 |
(ins > 0) ifTrue:[
|
|
216 |
i := 1.
|
|
217 |
[ i <= ins ] whileTrue:[
|
|
218 |
inserted add:index2 + addConstant2.
|
|
219 |
text1 := text1 , Character cr.
|
|
220 |
addConstant1 := addConstant1 + 1.
|
|
221 |
text2 := text2 , (array2 at:index2) asString.
|
|
222 |
index2 := index2 + 1.
|
|
223 |
i := i + 1.
|
|
224 |
].
|
|
225 |
].
|
|
226 |
change := change nextLink.
|
|
227 |
].
|
|
228 |
"kontrola zda nam nechybi posledni znaky"
|
|
229 |
(index1 <= (array1 size)) ifTrue:[
|
|
230 |
[
|
|
231 |
index1 <= (array1 size)
|
|
232 |
] whileTrue:[
|
|
233 |
helperText := (array1 at:index1) asText.
|
|
234 |
text1 := text1 , helperText.
|
|
235 |
index1 := index1 + 1.
|
|
236 |
].
|
|
237 |
].
|
|
238 |
(index2 <= (array2 size)) ifTrue:[
|
|
239 |
[
|
|
240 |
index2 <= (array2 size)
|
|
241 |
] whileTrue:[
|
|
242 |
helperText := (array2 at:index2) asText.
|
|
243 |
text2 := text2 , helperText.
|
|
244 |
index2 := index2 + 1.
|
|
245 |
].
|
|
246 |
].
|
|
247 |
diffHelper text1:text1.
|
|
248 |
diffHelper text2:text2.
|
|
249 |
diffHelper changed:changed.
|
|
250 |
diffHelper inserted:inserted.
|
|
251 |
diffHelper deleted:deleted.
|
|
252 |
^ diffHelper.
|
|
253 |
|
|
254 |
"Modified: / 22-06-2010 / 21:02:50 / Jakub <zelenja7@fel.cvut.cz>"
|
|
255 |
"Modified: / 24-06-2010 / 21:07:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
256 |
!
|
|
257 |
|
|
258 |
createArray:text1
|
|
259 |
"Creates array from string where every row is one item"
|
|
260 |
|
|
261 |
"^text1 asStringCollection"
|
|
262 |
|
|
263 |
|helperText i item char array|
|
|
264 |
|
|
265 |
item := ''.
|
|
266 |
helperText := text1.
|
|
267 |
array := OrderedCollection new.
|
|
268 |
i := 1.
|
|
269 |
[ i <= text1 size ] whileTrue:[
|
|
270 |
char := helperText at:i.
|
|
271 |
item := item , char.
|
|
272 |
(char == Character cr) ifTrue:[
|
|
273 |
array add:item.
|
|
274 |
item := ''.
|
|
275 |
].
|
|
276 |
i := i + 1.
|
|
277 |
].
|
|
278 |
|
|
279 |
^ array.
|
|
280 |
|
|
281 |
"Created: / 22-03-2010 / 14:48:27 / Jakub <zelenja7@fel.cvut.cz>"
|
|
282 |
"Modified: / 24-06-2010 / 13:40:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
283 |
! !
|
|
284 |
|
|
285 |
!DiffCodeView2::DiffData methodsFor:'accessing'!
|
|
286 |
|
|
287 |
changed
|
|
288 |
|
|
289 |
^changed copy
|
|
290 |
|
|
291 |
"Modified: / 02-05-2010 / 19:31:18 / Jakub <zelenja7@fel.cvut.cz>"
|
|
292 |
"Modified: / 16-07-2010 / 09:35:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
293 |
!
|
|
294 |
|
|
295 |
changed:something
|
|
296 |
changed := something.
|
|
297 |
!
|
|
298 |
|
|
299 |
deleted
|
|
300 |
^ deleted
|
|
301 |
!
|
|
302 |
|
|
303 |
deleted:something
|
|
304 |
deleted := something.
|
|
305 |
!
|
|
306 |
|
|
307 |
inserted
|
|
308 |
^ inserted
|
|
309 |
!
|
|
310 |
|
|
311 |
inserted:something
|
|
312 |
inserted := something.
|
|
313 |
!
|
|
314 |
|
|
315 |
text1
|
|
316 |
^ text1
|
|
317 |
!
|
|
318 |
|
|
319 |
text1:something
|
|
320 |
text1 := something.
|
|
321 |
!
|
|
322 |
|
|
323 |
text2
|
|
324 |
^ text2
|
|
325 |
!
|
|
326 |
|
|
327 |
text2:something
|
|
328 |
text2 := something.
|
|
329 |
! !
|
|
330 |
|
|
331 |
!DiffCodeView2 class methodsFor:'documentation'!
|
|
332 |
|
|
333 |
version_CVS
|
10074
|
334 |
^ '$Header: /cvs/stx/stx/libtool/Tools__DiffCodeView2.st,v 1.2 2011-07-03 17:50:11 cg Exp $'
|
9978
|
335 |
!
|
|
336 |
|
|
337 |
version_SVN
|
|
338 |
^ '§Id: Tools__DiffCodeView2.st 7594 2010-07-16 08:57:35Z vranyj1 §'
|
|
339 |
! !
|