DiffTextView.st
changeset 6577 51b89422d7de
parent 6413 ee2f36cef562
child 6649 e957a17f5b00
--- a/DiffTextView.st	Fri Feb 17 13:06:09 2006 +0100
+++ b/DiffTextView.st	Fri Feb 17 13:14:51 2006 +0100
@@ -200,66 +200,14 @@
     "set the two texts which are to be diffed;
      execute DiffCommand and update the two textViews."
 
-    |tmpFile1 tmpFile2  stream line 
-     text1 text2 diffList  diffTemplate diffCmd|
+    |text1 text2 diffList|
 
     text1 := t1 asStringCollection.
     text2 := t2 asStringCollection.
 
-    diffTemplate := self class diffCommand.
-    diffTemplate isNil ifTrue:[
-        "/ self warn:'no diff command available'.
-    ] ifFalse:[
-        "
-         save them texts in two temporary files ...
-        "
-        tmpFile1 := Filename newTemporary.
-        stream := tmpFile1 writeStream.
-        text1 do:[:line |
-            line notNil ifTrue:[
-(line includes:Character return) ifTrue: [self halt:'oops - funny line'].
-                stream nextPutAll:line.
-            ].
-            stream cr
-        ].
-        stream close.
-
-        tmpFile2 := Filename newTemporary.
-        stream := tmpFile2 writeStream.
-        text2 do:[:line |
-            line notNil ifTrue:[
-(line includes:Character return) ifTrue: [self halt:'oops - funny line'].
-                stream nextPutAll:line utf8Encoded.
-            ].
-            stream cr
-        ].
-        stream close.
-
-        "
-         start diff on it ...
-        "
-        diffCmd := diffTemplate
-                    bindWith:tmpFile1 asString
-                    with:tmpFile2 asString.
-
-        stream := PipeStream readingFrom:diffCmd.
-        stream isNil ifTrue:[
-            stream := PipeStream readingFrom:('support' , Filename separator , diffCmd).
-        ].                                          
-        stream isNil ifTrue:[
-            self error:'cannot execute diff'.
-            text1 := text2 := nil.
-        ] ifFalse:[
-            diffList := OrderedCollection new.
-            [stream atEnd] whileFalse:[
-                line := stream nextLine.
-                line notNil ifTrue:[diffList add:line]
-            ].
-            stream close.
-        ].
-
-        tmpFile1 delete.
-        tmpFile2 delete.
+    Error handle:[:ex |
+    ] do:[
+        diffList := self diffListFor:text1 and:text2.
     ].
 
     self updateListsFrom:text1 and:text2 diffs:diffList
@@ -344,6 +292,72 @@
 
 !DiffTextView methodsFor:'private'!
 
+diffListFor:text1 and:text2
+    "set the two texts which are to be diffed;
+     execute DiffCommand and update the two textViews."
+
+    |tmpFile1 tmpFile2 stream line 
+     diffList diffTemplate diffCmd|
+
+    diffTemplate := self class diffCommand.
+    diffTemplate isNil ifTrue:[
+        "/ self warn:'no diff command available'.
+        ^ nil
+    ].
+
+    "
+     save them texts in two temporary files ...
+    "
+    self save:text1 as:(tmpFile1 := Filename newTemporary).
+    self save:text2 as:(tmpFile2 := Filename newTemporary).
+
+    "
+     start diff on it ...
+    "
+    diffCmd := diffTemplate
+                bindWith:tmpFile1 asString
+                with:tmpFile2 asString.
+
+    stream := PipeStream readingFrom:diffCmd.
+    stream isNil ifTrue:[
+        stream := PipeStream readingFrom:('support' , Filename separator , diffCmd).
+    ].                                          
+    stream isNil ifTrue:[
+        tmpFile1 delete.
+        tmpFile2 delete.
+        self error:'cannot execute diff' mayProceed:true.
+        ^ nil.
+    ].
+
+    diffList := OrderedCollection new.
+    [stream atEnd] whileFalse:[
+        line := stream nextLine.
+        line notNil ifTrue:[diffList add:line]
+    ].
+    stream close.
+
+    tmpFile1 delete.
+    tmpFile2 delete.
+
+    ^ diffList
+!
+
+save:text as:filename
+    |stream|
+
+    stream := filename writeStream.
+    text do:[:line |
+        line notNil ifTrue:[
+            (line includes:Character return) ifTrue: [
+                self error:'oops - funny line (includes returns) in text'.
+            ].
+            stream nextPutAll:line.
+        ].
+        stream cr
+    ].
+    stream close.
+!
+
 updateListsFrom:text1 and:text2 diffs:diffList
     "given the two texts in text1 and text2, and the diff-output in diffList,
      update my views contents"
@@ -642,5 +656,5 @@
 !DiffTextView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/DiffTextView.st,v 1.42 2005-11-18 14:55:31 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/DiffTextView.st,v 1.43 2006-02-17 12:14:51 cg Exp $'
 ! !