Tools__DiffCodeView2.st
branchjv
changeset 15566 184cea584be5
parent 12431 9f0c59c742d5
parent 15474 9d8648afebd3
child 15724 c2b9162d087d
--- a/Tools__DiffCodeView2.st	Sun Jan 12 23:30:25 2014 +0000
+++ b/Tools__DiffCodeView2.st	Wed Apr 01 10:38:01 2015 +0100
@@ -92,7 +92,11 @@
 !
 
 codeAspect:aSymbol
-    textViews do:[:each|each codeAspect:aSymbol].
+    "tell the textViews what is shown, so they can adjust their
+     syntaxhighlighters.
+     See SyntaxHighlighter codeAspectXXX for possible aspects."
+
+     textViews do:[:each|each codeAspect:aSymbol].
 
     "Created: / 27-07-2012 / 23:24:46 / cg"
 !
@@ -140,17 +144,18 @@
 !DiffCodeView2 methodsFor:'initialization'!
 
 initialize
-
     super initialize.
-    textViews do:
-        [:thisView|
-        thisView diffMode: true.
-        thisView ~= textViews first ifTrue:
-            [thisView showGutterChannel value: false].
-        textViews do:
-            [:otherView|
-            thisView == otherView ifFalse:
-                [thisView synchronizeWith: otherView]]].
+    textViews do:[:thisView | 
+        thisView diffMode:true.
+        thisView ~= textViews first ifTrue:[
+            thisView showGutterChannel value:false
+        ].
+        textViews do:[:otherView | 
+            thisView == otherView ifFalse:[
+                thisView synchronizeWith:otherView
+            ]
+        ]
+    ].
 
     "Created: / 06-04-2010 / 14:15:03 / Jakub <zelenja7@fel.cvut.cz>"
     "Modified: / 23-06-2010 / 19:36:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -162,7 +167,196 @@
     "created diffText object from two strings
      This processes the DiffData as returned by the (now internal) Diff-tool"
     
-    |array1 array2 diff change index1 index2 text1 text2 i diffData deleted inserted helperText addConstant1 addConstant2 changed helper ins del pom|
+    "/ cg: same code as in Diff2CodeView2!!!!!!
+    "/ please refactor and make this a utility method on the class side
+
+    |array1 array2 diff change index1 index2 text1 text2 i 
+     diffData deleted inserted helperText addConstant1 addConstant2 changed helper ins del pom
+     array1Size array2Size cr|
+
+    cr := Character cr asString.
+
+    "create line arrays from origin text(1 item/row)"
+    array1 := self createArray:t1.
+    array2 := self createArray:t2.
+     "inserted,deleted, cahnged lines"
+    inserted := OrderedCollection new.
+    deleted := OrderedCollection new.
+    changed := OrderedCollection new.
+     "indicates which row of origin text is added to ne text"
+    index1 := 1.
+    index2 := 1.
+     "indicate how much rows were deleted or inserted "
+    addConstant1 := 0.
+    addConstant2 := 0.
+    text1 := OrderedCollection new.
+    text2 := OrderedCollection new.
+    diff := Diff new.
+    diff a:array1 b:array2.
+    change := diff diff:false.
+    diffData := DiffData new.
+    [ change notNil ] whileTrue:[
+        "check first lines which are same"
+        (((change line0) > 0) and:[ ((change line1) > 0) ]) ifTrue:[
+            [
+                index1 <= (change line0)
+            ] whileTrue:[
+                helperText := (array1 at:index1) asText.
+                text1 add: helperText asString.
+                index1 := index1 + 1.
+            ].
+            [
+                index2 <= (change line1)
+            ] whileTrue:[
+                helperText := (array2 at:index2) asText.
+                text2 add: helperText.
+                index2 := index2 + 1.
+            ].
+        ].
+        ins := change inserted.
+        del := change deleted.
+        index1 := (change line0) + 1.
+        index2 := (change line1) + 1.
+         "find replaced lines "
+        ((del > 0) and:[ ins > 0 ]) ifTrue:[
+            helper := del - ins.
+            (helper <= 0) ifTrue:[
+                pom := change deleted.
+            ].
+            (helper > 0) ifTrue:[
+                pom := change inserted.
+            ].
+             "its same count row"
+            i := 1.
+            [ i <= pom ] whileTrue:[
+                changed add:index1 + addConstant1.
+                text1 add: (array1 at:index1) asString.
+                text2 add: (array2 at:index2) asString.
+                index1 := index1 + 1.
+                index2 := index2 + 1.
+                del := del - 1.
+                ins := ins - 1.
+                i := i + 1.
+            ].
+        ].
+         "find deleted lines"
+        (del > 0) ifTrue:[
+            i := 1.
+            [ i <= del ] whileTrue:[
+                deleted add:index1 + addConstant1.
+                text2 add: cr.
+                addConstant2 := addConstant2 + 1.
+                text1 add: (array1 at:index1) asString.
+                index1 := index1 + 1.
+                i := i + 1.
+            ].
+        ].
+         "find inserted lines"
+        (ins > 0) ifTrue:[
+            i := 1.
+            [ i <= ins ] whileTrue:[
+                inserted add:index2 + addConstant2.
+                text1 add: cr.
+                addConstant1 := addConstant1 + 1.
+                text2 add: (array2 at:index2) asString.
+                index2 := index2 + 1.
+                i := i + 1.
+            ].
+        ].
+        change := change nextLink.
+    ].
+     "kontrola zda nam nechybi posledni znaky"
+    array1Size := array1 size.
+    (index1 <= array1Size) ifTrue:[
+        [ index1 <= array1Size ] whileTrue:[
+            helperText := (array1 at:index1) asText.
+            text1 add: helperText.
+            index1 := index1 + 1.
+        ].
+    ].
+    array2Size := array2 size.
+    (index2 <= array2Size) ifTrue:[
+        [ index2 <= array2Size ] whileTrue:[
+            helperText := (array2 at:index2) asText.
+            text2 add: helperText.
+            index2 := index2 + 1.
+        ].
+    ].
+
+    1 to:(text1 size min:text2 size) do:[:idx |
+        |l1 l2|
+
+        l1 := text1 at:idx.
+        l2 := text2 at:idx.
+        l1 = l2 ifTrue:[
+            text1 at:idx put:l1 string.   "/ remove color
+            text2 at:idx put:l2 string.
+            changed remove:idx ifAbsent:[].
+        ] ifFalse:[
+            l1 withoutSeparators = l2 withoutSeparators ifTrue:[
+                text1 at:idx put:l1 string.     "/ remove color  
+                text2 at:idx put:l2 string.
+                changed remove:idx ifAbsent:[].
+            ] ifFalse:[
+                "/ self halt.
+            ]
+        ]
+    ].
+
+    diffData text1:(text1 asStringWith:'').
+    diffData text2:(text2 asStringWith:'').
+    diffData changed:changed.
+    diffData inserted:inserted.
+    diffData deleted:deleted.
+    ^ diffData.
+
+    "Modified: / 22-06-2010 / 21:02:50 / Jakub <zelenja7@fel.cvut.cz>"
+    "Modified: / 24-06-2010 / 21:07:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 17-07-2012 / 18:55:01 / cg"
+!
+
+createArray:text1
+    "cg: isn't that an obfuscated variation of #asCollectionOfLines ?"
+
+    "/ ^ text1 asStringCollection. "/ yes, it looks like !! 
+
+    "/ JV@2012-07-26: Yes, looks like but it is not!! This version
+    "/ keeps CRs in lines. Do not change it back - if you do, DoffCodeView2 
+    "/ will show whole source in a single line.
+
+    | array src line c |
+
+    array := StringCollection new.
+    src := text1 readStream.
+    line := (String new: 80) writeStream.
+    [ src atEnd ] whileFalse:[
+        c := src next.
+        line nextPut: c.
+        c == Character cr ifTrue:[
+            array add: line contents.
+            line reset.
+        ]        
+    ].
+    line position ~~ 0 ifTrue:[
+        array add: line contents
+    ].
+    ^array
+
+    "Created: / 22-03-2010 / 14:48:27 / Jakub <zelenja7@fel.cvut.cz>"
+    "Modified: / 17-07-2012 / 18:55:21 / cg"
+    "Modified (comment): / 26-07-2012 / 21:45:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+old_computeDiffDataForText1:t1 text2:t2 
+    "created diffText object from two strings
+     This processes the DiffData as returned by the (now internal) Diff-tool"
+    
+    "/ cg: same code as in Diff2CodeView2!!!!!!
+    "/ please refactor and make this a utility method on the class side
+
+    |array1 array2 diff change index1 index2 text1 text2 i 
+     diffData deleted inserted helperText addConstant1 addConstant2 changed helper ins del pom
+     array1Size array2Size|
 
     "create line arrays from origin text(1 item/row)"
     array1 := self createArray:t1.
@@ -205,7 +399,7 @@
         del := change deleted.
         index1 := (change line0) + 1.
         index2 := (change line1) + 1.
-         "find replace files "
+         "find replaced lines "
         ((del > 0) and:[ ins > 0 ]) ifTrue:[
             helper := del - ins.
             (helper <= 0) ifTrue:[
@@ -227,7 +421,7 @@
                 i := i + 1.
             ].
         ].
-         "find deleted files"
+         "find deleted lines"
         (del > 0) ifTrue:[
             i := 1.
             [ i <= del ] whileTrue:[
@@ -254,19 +448,17 @@
         change := change nextLink.
     ].
      "kontrola zda nam nechybi posledni znaky"
-    (index1 <= (array1 size)) ifTrue:[
-        [
-            index1 <= (array1 size)
-        ] whileTrue:[
+    array1Size := array1 size.
+    (index1 <= array1Size) ifTrue:[
+        [ index1 <= array1Size ] whileTrue:[
             helperText := (array1 at:index1) asText.
             text1 := text1 , helperText.
             index1 := index1 + 1.
         ].
     ].
-    (index2 <= (array2 size)) ifTrue:[
-        [
-            index2 <= (array2 size)
-        ] whileTrue:[
+    array2Size := array2 size.
+    (index2 <= array2Size) ifTrue:[
+        [ index2 <= array2Size ] whileTrue:[
             helperText := (array2 at:index2) asText.
             text2 := text2 , helperText.
             index2 := index2 + 1.
@@ -282,38 +474,6 @@
     "Modified: / 22-06-2010 / 21:02:50 / Jakub <zelenja7@fel.cvut.cz>"
     "Modified: / 24-06-2010 / 21:07:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 17-07-2012 / 18:55:01 / cg"
-!
-
-createArray:text1
-    "cg: isn't that an obfuscated variation of #asCollectionOfLines ?"
-
-    "/ ^ text1 asStringCollection. "/ yes, it looks like !! 
-
-    "/ JV@2012-07-26: Yes, looks like but it is not!! This version
-    "/ keeps CRs in lines. Do not change it back - if you do, DoffCodeView2 
-    "/ will show whole source in a single line.
-
-    | array src line c |
-
-    array := StringCollection new.
-    src := text1 readStream.
-    line := (String new: 80) writeStream.
-    [ src atEnd ] whileFalse:[
-        c := src next.
-        line nextPut: c.
-        c == Character cr ifTrue:[
-            array add: line contents.
-            line reset.
-        ]        
-    ].
-    line position ~~ 0 ifTrue:[
-        array add: line contents
-    ].
-    ^array
-
-    "Created: / 22-03-2010 / 14:48:27 / Jakub <zelenja7@fel.cvut.cz>"
-    "Modified: / 17-07-2012 / 18:55:21 / cg"
-    "Modified (comment): / 26-07-2012 / 21:45:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !DiffCodeView2::DiffData methodsFor:'accessing'!
@@ -365,15 +525,10 @@
 !DiffCodeView2 class methodsFor:'documentation'!
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libtool/Tools__DiffCodeView2.st,v 1.6 2012-07-27 22:05:42 cg Exp $'
-!
-
-version_HG
-
-    ^ '$Changeset: <not expanded> $'
+    ^ '$Header: /cvs/stx/stx/libtool/Tools__DiffCodeView2.st,v 1.11 2015-02-28 03:15:32 cg Exp $'
 !
 
 version_SVN
-    ^ '§Id: Tools__DiffCodeView2.st 7594 2010-07-16 08:57:35Z vranyj1 §'
+    ^ '$Id: Tools__DiffCodeView2.st,v 1.11 2015-02-28 03:15:32 cg Exp $'
 ! !