author | Claus Gittinger <cg@exept.de> |
Fri, 04 Jul 2014 12:28:31 +0200 | |
changeset 14586 | 15f0df501dd2 |
parent 14371 | 491ec9ff2c09 |
child 15278 | 1d449ea6c8e0 |
permissions | -rw-r--r-- |
13839 | 1 |
" |
2 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
3 |
All Rights Reserved |
|
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 |
"{ Package: 'stx:libtool' }" |
|
13 |
||
14 |
"{ NameSpace: Tools }" |
|
15 |
||
16 |
DiffCodeView2 subclass:#Diff2CodeView2 |
|
17 |
instanceVariableNames:'' |
|
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'Interface-CodeView' |
|
21 |
! |
|
22 |
||
23 |
Object subclass:#Diff2Data |
|
24 |
instanceVariableNames:'text1 text2 inserted deleted changed' |
|
25 |
classVariableNames:'' |
|
26 |
poolDictionaries:'' |
|
27 |
privateIn:Diff2CodeView2 |
|
28 |
! |
|
29 |
||
30 |
!Diff2CodeView2 class methodsFor:'documentation'! |
|
31 |
||
32 |
copyright |
|
33 |
" |
|
34 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
35 |
All Rights Reserved |
|
36 |
||
37 |
This software is furnished under a license and may be used |
|
38 |
only in accordance with the terms of that license and with the |
|
39 |
inclusion of the above copyright notice. This software may not |
|
40 |
be provided or otherwise made available to, or used by, any |
|
41 |
other person. No title to or ownership of the software is |
|
42 |
hereby transferred. |
|
43 |
" |
|
44 |
! ! |
|
45 |
||
46 |
!Diff2CodeView2 class methodsFor:'defaults'! |
|
47 |
||
48 |
numberOfViews |
|
49 |
"return the number of the synced subViews. |
|
50 |
Usually redefined in subclasses" |
|
51 |
||
52 |
^ 2 |
|
53 |
||
54 |
"Created: / 16-03-2012 / 12:54:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
55 |
! ! |
|
56 |
||
57 |
!Diff2CodeView2 methodsFor:'accessing'! |
|
58 |
||
59 |
text1:t1 text2:t2 |
|
60 |
|data| |
|
61 |
||
62 |
data := self computeDiffDataForText1:t1 text2:t2. |
|
63 |
||
64 |
(textViews at:1) |
|
65 |
contents:(data text1); |
|
66 |
deletedLines:(data deleted); |
|
67 |
changedLines:(data changed); |
|
68 |
insertedLines:#(); |
|
69 |
originDiffText:t1; |
|
70 |
emptyLines:(data inserted). |
|
71 |
||
72 |
(textViews at:2) |
|
73 |
contents:(data text2); |
|
74 |
deletedLines:#(); |
|
75 |
changedLines:(data changed); |
|
76 |
insertedLines:(data inserted); |
|
77 |
originDiffText:t2; |
|
78 |
emptyLines:(data deleted). |
|
79 |
||
80 |
"Created: / 06-03-2010 / 10:45:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
81 |
"Modified: / 22-06-2010 / 21:36:35 / Jakub <zelenja7@fel.cvut.cz>" |
|
82 |
"Modified: / 15-07-2010 / 23:08:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
83 |
! ! |
|
84 |
||
85 |
!Diff2CodeView2 methodsFor:'private'! |
|
86 |
||
87 |
computeDiffDataForText1:t1 text2:t2 |
|
88 |
"created diffText object from two string" |
|
14371
491ec9ff2c09
class: Tools::Diff2CodeView2
Claus Gittinger <cg@exept.de>
parents:
13839
diff
changeset
|
89 |
|
491ec9ff2c09
class: Tools::Diff2CodeView2
Claus Gittinger <cg@exept.de>
parents:
13839
diff
changeset
|
90 |
"/ cg: same code as in DiffCodeView2!!!!!! |
491ec9ff2c09
class: Tools::Diff2CodeView2
Claus Gittinger <cg@exept.de>
parents:
13839
diff
changeset
|
91 |
"/ please refactor and make this a utility method on the class side |
491ec9ff2c09
class: Tools::Diff2CodeView2
Claus Gittinger <cg@exept.de>
parents:
13839
diff
changeset
|
92 |
|
491ec9ff2c09
class: Tools::Diff2CodeView2
Claus Gittinger <cg@exept.de>
parents:
13839
diff
changeset
|
93 |
|array1 array2 diff change index1 index2 text1 text2 i |
491ec9ff2c09
class: Tools::Diff2CodeView2
Claus Gittinger <cg@exept.de>
parents:
13839
diff
changeset
|
94 |
data deleted inserted helperText addConstant1 addConstant2 changed helper ins del pom |
491ec9ff2c09
class: Tools::Diff2CodeView2
Claus Gittinger <cg@exept.de>
parents:
13839
diff
changeset
|
95 |
array1Size array2Size| |
13839 | 96 |
|
97 |
"Convert text into an array of individual lines" |
|
98 |
array1 := self createArray:t1. |
|
99 |
array2 := self createArray:t2. |
|
100 |
"Initialize inserted/deleted/changed " |
|
101 |
inserted := OrderedCollection new. |
|
102 |
deleted := OrderedCollection new. |
|
103 |
changed := OrderedCollection new. |
|
104 |
||
105 |
"indicates which row of origin text is added to ne text" |
|
106 |
index1 := 1. |
|
107 |
index2 := 1. |
|
108 |
"indicate how much rows were deleted or inserted " |
|
109 |
addConstant1 := 0. |
|
110 |
addConstant2 := 0. |
|
111 |
text1 := ''. |
|
112 |
text2 := ''. |
|
113 |
diff := Diff new. |
|
114 |
diff a:array1 b:array2. |
|
115 |
change := diff diff:false. |
|
116 |
data := Diff2Data new. |
|
117 |
||
118 |
||
119 |
||
120 |
[ change notNil ] whileTrue:[ |
|
121 |
"check first lines which are same" |
|
122 |
(((change line0) > 0) and:[ ((change line1) > 0) ]) ifTrue:[ |
|
123 |
[ |
|
124 |
index1 <= (change line0) |
|
125 |
] whileTrue:[ |
|
126 |
helperText := (array1 at:index1) asText. |
|
127 |
text1 := text1 asString , helperText asString. |
|
128 |
index1 := index1 + 1. |
|
129 |
]. |
|
130 |
[ |
|
131 |
index2 <= (change line1) |
|
132 |
] whileTrue:[ |
|
133 |
helperText := (array2 at:index2) asText. |
|
134 |
text2 := text2 , helperText. |
|
135 |
index2 := index2 + 1. |
|
136 |
]. |
|
137 |
]. |
|
138 |
ins := change inserted. |
|
139 |
del := change deleted. |
|
140 |
index1 := (change line0) + 1. |
|
141 |
index2 := (change line1) + 1. |
|
142 |
"find replace files " |
|
143 |
((del > 0) and:[ ins > 0 ]) ifTrue:[ |
|
144 |
helper := del - ins. |
|
145 |
(helper <= 0) ifTrue:[ |
|
146 |
pom := change deleted. |
|
147 |
]. |
|
148 |
(helper > 0) ifTrue:[ |
|
149 |
pom := change inserted. |
|
150 |
]. |
|
151 |
"its same count row" |
|
152 |
i := 1. |
|
153 |
[ i <= pom ] whileTrue:[ |
|
154 |
changed add:index1 + addConstant1. |
|
155 |
text1 := text1 , (array1 at:index1) asString. |
|
156 |
text2 := text2 , (array2 at:index2) asString. |
|
157 |
index1 := index1 + 1. |
|
158 |
index2 := index2 + 1. |
|
159 |
del := del - 1. |
|
160 |
ins := ins - 1. |
|
161 |
i := i + 1. |
|
162 |
]. |
|
163 |
]. |
|
164 |
"find deleted files" |
|
165 |
(del > 0) ifTrue:[ |
|
166 |
i := 1. |
|
167 |
[ i <= del ] whileTrue:[ |
|
168 |
deleted add:index1 + addConstant1. |
|
169 |
text2 := text2 , Character cr. |
|
170 |
addConstant2 := addConstant2 + 1. |
|
171 |
text1 := text1 , (array1 at:index1) asString. |
|
172 |
index1 := index1 + 1. |
|
173 |
i := i + 1. |
|
174 |
]. |
|
175 |
]. |
|
176 |
"find inserted lines" |
|
177 |
(ins > 0) ifTrue:[ |
|
178 |
i := 1. |
|
179 |
[ i <= ins ] whileTrue:[ |
|
180 |
inserted add:index2 + addConstant2. |
|
181 |
text1 := text1 , Character cr. |
|
182 |
addConstant1 := addConstant1 + 1. |
|
183 |
text2 := text2 , (array2 at:index2) asString. |
|
184 |
index2 := index2 + 1. |
|
185 |
i := i + 1. |
|
186 |
]. |
|
187 |
]. |
|
188 |
change := change nextLink. |
|
189 |
]. |
|
190 |
"kontrola zda nam nechybi posledni znaky" |
|
14371
491ec9ff2c09
class: Tools::Diff2CodeView2
Claus Gittinger <cg@exept.de>
parents:
13839
diff
changeset
|
191 |
array1Size := array1 size. |
491ec9ff2c09
class: Tools::Diff2CodeView2
Claus Gittinger <cg@exept.de>
parents:
13839
diff
changeset
|
192 |
(index1 <= array1Size) ifTrue:[ |
491ec9ff2c09
class: Tools::Diff2CodeView2
Claus Gittinger <cg@exept.de>
parents:
13839
diff
changeset
|
193 |
[ index1 <= array1Size ] whileTrue:[ |
13839 | 194 |
helperText := (array1 at:index1) asText. |
195 |
text1 := text1 , helperText. |
|
196 |
index1 := index1 + 1. |
|
197 |
]. |
|
198 |
]. |
|
14371
491ec9ff2c09
class: Tools::Diff2CodeView2
Claus Gittinger <cg@exept.de>
parents:
13839
diff
changeset
|
199 |
array2Size := array2 size. |
491ec9ff2c09
class: Tools::Diff2CodeView2
Claus Gittinger <cg@exept.de>
parents:
13839
diff
changeset
|
200 |
(index2 <= array2Size) ifTrue:[ |
491ec9ff2c09
class: Tools::Diff2CodeView2
Claus Gittinger <cg@exept.de>
parents:
13839
diff
changeset
|
201 |
[ index2 <= (array2 size) ] whileTrue:[ |
13839 | 202 |
helperText := (array2 at:index2) asText. |
203 |
text2 := text2 , helperText. |
|
204 |
index2 := index2 + 1. |
|
205 |
]. |
|
206 |
]. |
|
207 |
data text1:text1. |
|
208 |
data text2:text2. |
|
209 |
data changed:changed. |
|
210 |
data inserted:inserted. |
|
211 |
data deleted:deleted. |
|
212 |
^ data. |
|
213 |
||
214 |
"Modified: / 22-06-2010 / 21:02:50 / Jakub <zelenja7@fel.cvut.cz>" |
|
215 |
"Modified: / 16-03-2012 / 12:53:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
216 |
"Modified (format): / 16-03-2012 / 16:10:54 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
217 |
! |
|
218 |
||
219 |
createArray:text1 |
|
220 |
||
221 |
| array src line c | |
|
222 |
array := StringCollection new. |
|
223 |
src := text1 readStream. |
|
224 |
line := (String new: 80) writeStream. |
|
225 |
[ src atEnd ] whileFalse:[ |
|
226 |
c := src next. |
|
227 |
line nextPut: c. |
|
228 |
c == Character cr ifTrue:[ |
|
229 |
array add: line contents. |
|
230 |
line reset. |
|
231 |
] |
|
232 |
]. |
|
233 |
line position ~~ 0 ifTrue:[ |
|
234 |
array add: line contents |
|
235 |
]. |
|
236 |
^array |
|
237 |
||
238 |
"Created: / 22-03-2010 / 14:48:27 / Jakub <zelenja7@fel.cvut.cz>" |
|
239 |
"Modified (comment): / 19-07-2011 / 11:14:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
240 |
! ! |
|
241 |
||
242 |
!Diff2CodeView2::Diff2Data methodsFor:'accessing'! |
|
243 |
||
244 |
changed |
|
245 |
||
246 |
^changed copy |
|
247 |
||
248 |
"Modified: / 02-05-2010 / 19:31:18 / Jakub <zelenja7@fel.cvut.cz>" |
|
249 |
"Modified: / 16-07-2010 / 09:35:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
250 |
! |
|
251 |
||
252 |
changed:something |
|
253 |
changed := something. |
|
254 |
! |
|
255 |
||
256 |
deleted |
|
257 |
^ deleted |
|
258 |
! |
|
259 |
||
260 |
deleted:something |
|
261 |
deleted := something. |
|
262 |
! |
|
263 |
||
264 |
inserted |
|
265 |
^ inserted |
|
266 |
! |
|
267 |
||
268 |
inserted:something |
|
269 |
inserted := something. |
|
270 |
! |
|
271 |
||
272 |
text1 |
|
273 |
^ text1 |
|
274 |
! |
|
275 |
||
276 |
text1:something |
|
277 |
text1 := something. |
|
278 |
! |
|
279 |
||
280 |
text2 |
|
281 |
^ text2 |
|
282 |
! |
|
283 |
||
284 |
text2:something |
|
285 |
text2 := something. |
|
286 |
! ! |
|
287 |
||
288 |
!Diff2CodeView2 class methodsFor:'documentation'! |
|
289 |
||
290 |
version |
|
14371
491ec9ff2c09
class: Tools::Diff2CodeView2
Claus Gittinger <cg@exept.de>
parents:
13839
diff
changeset
|
291 |
^ '$Header: /cvs/stx/stx/libtool/Tools__Diff2CodeView2.st,v 1.2 2014-05-15 17:21:25 cg Exp $' |
13839 | 292 |
! |
293 |
||
294 |
version_CVS |
|
14371
491ec9ff2c09
class: Tools::Diff2CodeView2
Claus Gittinger <cg@exept.de>
parents:
13839
diff
changeset
|
295 |
^ '$Header: /cvs/stx/stx/libtool/Tools__Diff2CodeView2.st,v 1.2 2014-05-15 17:21:25 cg Exp $' |
13839 | 296 |
! ! |
297 |