39 inclusion of the above copyright notice. This software may not |
39 inclusion of the above copyright notice. This software may not |
40 be provided or otherwise made available to, or used by, any |
40 be provided or otherwise made available to, or used by, any |
41 other person. No title to or ownership of the software is |
41 other person. No title to or ownership of the software is |
42 hereby transferred. |
42 hereby transferred. |
43 " |
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" |
|
89 |
|
90 |array1 array2 diff change index1 index2 text1 text2 i data deleted inserted helperText addConstant1 addConstant2 changed helper ins del pom| |
|
91 |
|
92 "Convert text into an array of individual lines" |
|
93 array1 := self createArray:t1. |
|
94 array2 := self createArray:t2. |
|
95 "Initialize inserted/deleted/changed " |
|
96 inserted := OrderedCollection new. |
|
97 deleted := OrderedCollection new. |
|
98 changed := OrderedCollection new. |
|
99 |
|
100 "indicates which row of origin text is added to ne text" |
|
101 index1 := 1. |
|
102 index2 := 1. |
|
103 "indicate how much rows were deleted or inserted " |
|
104 addConstant1 := 0. |
|
105 addConstant2 := 0. |
|
106 text1 := ''. |
|
107 text2 := ''. |
|
108 diff := Diff new. |
|
109 diff a:array1 b:array2. |
|
110 change := diff diff:false. |
|
111 data := Diff2Data new. |
|
112 |
|
113 |
|
114 |
|
115 [ change notNil ] whileTrue:[ |
|
116 "check first lines which are same" |
|
117 (((change line0) > 0) and:[ ((change line1) > 0) ]) ifTrue:[ |
|
118 [ |
|
119 index1 <= (change line0) |
|
120 ] whileTrue:[ |
|
121 helperText := (array1 at:index1) asText. |
|
122 text1 := text1 asString , helperText asString. |
|
123 index1 := index1 + 1. |
|
124 ]. |
|
125 [ |
|
126 index2 <= (change line1) |
|
127 ] whileTrue:[ |
|
128 helperText := (array2 at:index2) asText. |
|
129 text2 := text2 , helperText. |
|
130 index2 := index2 + 1. |
|
131 ]. |
|
132 ]. |
|
133 ins := change inserted. |
|
134 del := change deleted. |
|
135 index1 := (change line0) + 1. |
|
136 index2 := (change line1) + 1. |
|
137 "find replace files " |
|
138 ((del > 0) and:[ ins > 0 ]) ifTrue:[ |
|
139 helper := del - ins. |
|
140 (helper <= 0) ifTrue:[ |
|
141 pom := change deleted. |
|
142 ]. |
|
143 (helper > 0) ifTrue:[ |
|
144 pom := change inserted. |
|
145 ]. |
|
146 "its same count row" |
|
147 i := 1. |
|
148 [ i <= pom ] whileTrue:[ |
|
149 changed add:index1 + addConstant1. |
|
150 text1 := text1 , (array1 at:index1) asString. |
|
151 text2 := text2 , (array2 at:index2) asString. |
|
152 index1 := index1 + 1. |
|
153 index2 := index2 + 1. |
|
154 del := del - 1. |
|
155 ins := ins - 1. |
|
156 i := i + 1. |
|
157 ]. |
|
158 ]. |
|
159 "find deleted files" |
|
160 (del > 0) ifTrue:[ |
|
161 i := 1. |
|
162 [ i <= del ] whileTrue:[ |
|
163 deleted add:index1 + addConstant1. |
|
164 text2 := text2 , Character cr. |
|
165 addConstant2 := addConstant2 + 1. |
|
166 text1 := text1 , (array1 at:index1) asString. |
|
167 index1 := index1 + 1. |
|
168 i := i + 1. |
|
169 ]. |
|
170 ]. |
|
171 "find inserted lines" |
|
172 (ins > 0) ifTrue:[ |
|
173 i := 1. |
|
174 [ i <= ins ] whileTrue:[ |
|
175 inserted add:index2 + addConstant2. |
|
176 text1 := text1 , Character cr. |
|
177 addConstant1 := addConstant1 + 1. |
|
178 text2 := text2 , (array2 at:index2) asString. |
|
179 index2 := index2 + 1. |
|
180 i := i + 1. |
|
181 ]. |
|
182 ]. |
|
183 change := change nextLink. |
|
184 ]. |
|
185 "kontrola zda nam nechybi posledni znaky" |
|
186 (index1 <= (array1 size)) ifTrue:[ |
|
187 [ |
|
188 index1 <= (array1 size) |
|
189 ] whileTrue:[ |
|
190 helperText := (array1 at:index1) asText. |
|
191 text1 := text1 , helperText. |
|
192 index1 := index1 + 1. |
|
193 ]. |
|
194 ]. |
|
195 (index2 <= (array2 size)) ifTrue:[ |
|
196 [ |
|
197 index2 <= (array2 size) |
|
198 ] whileTrue:[ |
|
199 helperText := (array2 at:index2) asText. |
|
200 text2 := text2 , helperText. |
|
201 index2 := index2 + 1. |
|
202 ]. |
|
203 ]. |
|
204 data text1:text1. |
|
205 data text2:text2. |
|
206 data changed:changed. |
|
207 data inserted:inserted. |
|
208 data deleted:deleted. |
|
209 ^ data. |
|
210 |
|
211 "Modified: / 22-06-2010 / 21:02:50 / Jakub <zelenja7@fel.cvut.cz>" |
|
212 "Modified: / 16-03-2012 / 12:53:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
213 "Modified (format): / 16-03-2012 / 16:10:54 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
214 ! |
|
215 |
|
216 createArray:text1 |
|
217 |
|
218 | array src line c | |
|
219 array := StringCollection new. |
|
220 src := text1 readStream. |
|
221 line := (String new: 80) writeStream. |
|
222 [ src atEnd ] whileFalse:[ |
|
223 c := src next. |
|
224 line nextPut: c. |
|
225 c == Character cr ifTrue:[ |
|
226 array add: line contents. |
|
227 line reset. |
|
228 ] |
|
229 ]. |
|
230 line position ~~ 0 ifTrue:[ |
|
231 array add: line contents |
|
232 ]. |
|
233 ^array |
|
234 |
|
235 "Created: / 22-03-2010 / 14:48:27 / Jakub <zelenja7@fel.cvut.cz>" |
|
236 "Modified (comment): / 19-07-2011 / 11:14:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
237 ! ! |
44 ! ! |
238 |
45 |
239 !Diff2CodeView2::Diff2Data methodsFor:'accessing'! |
46 !Diff2CodeView2::Diff2Data methodsFor:'accessing'! |
240 |
47 |
241 changed |
48 changed |