CRLF management
authorfm
Wed, 05 Jul 2006 11:56:40 +0200
changeset 3314 c486911eea21
parent 3313 6c2fd7c5a02f
child 3315 1b42d2f8dcbc
CRLF management
ListView.st
--- a/ListView.st	Wed Jul 05 09:41:40 2006 +0200
+++ b/ListView.st	Wed Jul 05 11:56:40 2006 +0200
@@ -19,7 +19,7 @@
 		fontIsFixedWidth fontWidth autoScroll autoScrollBlock
 		autoScrollDeltaT wordCheck includesNonStrings widthOfWidestLine
 		listMsg viewOrigin listChannel backgroundAlreadyClearedColor
-		scrollWhenUpdating scrollLocked'
+		scrollWhenUpdating scrollLocked lineEndCRLF'
 	classVariableNames:'DefaultForegroundColor DefaultBackgroundColor DefaultTabPositions
 		UserDefaultTabPositions DefaultLeftMargin DefaultTopMargin'
 	poolDictionaries:''
@@ -455,6 +455,12 @@
 
 !ListView methodsFor:'accessing-behavior'!
 
+lineEndCRLF
+    ^ lineEndCRLF ? false
+
+    "Created: / 04-07-2006 / 19:05:01 / fm"
+!
+
 scrollWhenUpdating
     "return the scroll behavior, when I get a new text 
      (via the model or the #contents/#list)
@@ -687,7 +693,12 @@
     "return the contents as a string"
 
     list isNil ifTrue:[^ ''].
+    self lineEndCRLF ifTrue:[      
+        ^ list asStringCollection asStringWith:(String crlf)
+    ].
     ^ list asStringCollection asString
+
+    "Modified: / 04-07-2006 / 19:18:47 / fm"
 !
 
 contents:something
@@ -823,7 +834,17 @@
         self scrollToLeft.
         ^ self
     ].
-    list := aCollection.
+
+    lineEndCRLF := (aCollection size > 0 and:[aCollection first string endsWith:Character return]).
+    lineEndCRLF ifTrue:[
+        list := aCollection 
+                    collect:[:eachLineWithCROrNil | 
+                        eachLineWithCROrNil isNil 
+                            ifTrue:nil
+                            ifFalse:[eachLineWithCROrNil copyButLast:1]].
+    ] ifFalse:[
+        list := aCollection.
+    ].
 
     nonStringsBefore := includesNonStrings.
     fontHeightBefore := fontHeight.
@@ -895,9 +916,10 @@
         ]
     ]
 
-    "Modified: / 30.8.1995 / 19:07:13 / claus"
-    "Created: / 5.6.1997 / 12:40:06 / cg"
-    "Modified: / 26.7.1998 / 13:47:35 / cg"
+    "Modified: / 30-08-1995 / 19:07:13 / claus"
+    "Created: / 05-06-1997 / 12:40:06 / cg"
+    "Modified: / 26-07-1998 / 13:47:35 / cg"
+    "Modified: / 04-07-2006 / 19:12:39 / fm"
 !
 
 listAt:lineNr
@@ -2809,7 +2831,9 @@
      - used with Compilers error-positioning, which is based on character positions
      of the contents-string."
 
-    |lineString pos|
+    |lineString pos lineEndCharSize|
+
+    lineEndCharSize := self lineEndCRLF ifTrue:2 ifFalse:1.
 
     self checkForExistingLine:lineNr.
     pos := 1.
@@ -2818,9 +2842,11 @@
         lineString notNil ifTrue:[
             pos := pos + lineString size
         ].
-        pos := pos + 1   "the return-character"
+        pos := pos + lineEndCharSize   "the return-character"
     ].
     ^ pos + col - 1
+
+    "Modified: / 04-07-2006 / 19:14:25 / fm"
 !
 
 colOfCharacterPosition:charPos
@@ -2981,22 +3007,25 @@
      return the lineNumber where the character is
      - used to find line to hilight from Compilers error-position"
 
-    |lineNr sum lastLine|
+    |lineNr sum lastLine lineEndCharSize|
+
+    lineEndCharSize := self lineEndCRLF ifTrue:2 ifFalse:1.
 
     lineNr := 1.
     sum := 0.
     lastLine := self size.
     [(sum < charPos) and:[lineNr <= lastLine]] whileTrue:[
-	sum := sum + (self at:lineNr) size + 1.
-	lineNr := lineNr + 1
+        sum := sum + (self at:lineNr) size + lineEndCharSize.
+        lineNr := lineNr + 1
     ].
     sum == charPos ifTrue:[
-	^ lineNr
+        ^ lineNr
     ].
 
     ^ lineNr - 1
 
-    "Modified: / 5.4.1998 / 17:19:28 / cg"
+    "Modified: / 05-04-1998 / 17:19:28 / cg"
+    "Modified: / 04-07-2006 / 19:13:32 / fm"
 !
 
 numberOfLines
@@ -4450,5 +4479,5 @@
 !ListView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/ListView.st,v 1.308 2006-07-03 15:14:40 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/ListView.st,v 1.309 2006-07-05 09:56:40 fm Exp $'
 ! !