ListView.st
changeset 1099 eccab3759ddb
parent 1081 0d3f4ad6e7e5
child 1101 a38f49637175
--- a/ListView.st	Wed Mar 05 17:09:02 1997 +0100
+++ b/ListView.st	Wed Mar 05 17:31:43 1997 +0100
@@ -789,12 +789,20 @@
      This can be used to update a self-changing list 
      (for example: a file list being shown, without disturbing the user too much)"
 
-    |oldFirst nonStringsBefore|
+    |oldFirst nonStringsBefore linesShownBefore|
 
     (aCollection isNil and:[list isNil]) ifTrue:[
         "no change"
         ^ self
     ].
+
+    list isNil ifTrue:[
+        linesShownBefore := (1 to:nLinesShown) collect:[:i | ''].
+    ] ifFalse:[
+        linesShownBefore := (firstLineShown to:(firstLineShown+nLinesShown-1))
+                            collect:[:i | (self at:i) ? ''].
+    ].
+
     list := aCollection.
 
     nonStringsBefore := includesNonStrings.
@@ -822,17 +830,36 @@
         firstLineShown := self size - nFullLinesShown + 1.
         firstLineShown < 1 ifTrue:[firstLineShown := 1].
         self originChanged:0 @ ((oldFirst - 1) negated * fontHeight).
+        linesShownBefore := nil.
         shown ifTrue:[
             self clear.
         ]
     ].
 "/ end new
     shown ifTrue:[
-        self redrawFromVisibleLine:1 to:nLinesShown
+        linesShownBefore isNil ifTrue:[
+            self redrawFromVisibleLine:1 to:nLinesShown
+        ] ifFalse:[
+            1 to:nLinesShown do:[:l |
+                |oldLine newLine|
+
+                newLine := self visibleAt:l.
+                newLine size == 0 ifTrue:[
+                    newLine := ''
+                ].
+                oldLine := linesShownBefore at:l ifAbsent:nil.
+                oldLine size == 0 ifTrue:[
+                    oldLine := ''
+                ].
+                oldLine ~= newLine ifTrue:[
+                    self redrawVisibleLine:l
+                ]
+            ]
+        ]
     ]
 
     "Modified: 18.12.1995 / 23:27:54 / stefan"
-    "Modified: 4.11.1996 / 23:28:55 / cg"
+    "Modified: 5.3.1997 / 17:20:48 / cg"
 !
 
 size
@@ -985,12 +1012,18 @@
 
 update:something with:aParameter from:changedObject
     changedObject == model ifTrue:[
-	(aspectMsg notNil
-	and:[something == aspectMsg]) ifTrue:[
-	    ^ self getListFromModel.
-	].
+        (aspectMsg notNil
+        and:[something == aspectMsg]) ifTrue:[
+            ^ self getListFromModel.
+        ].
+
+        something == #size ifTrue:[
+            ^ self getListFromModelScroll:false.
+        ]
     ].
     ^ super update:something with:aParameter from:changedObject
+
+    "Modified: 5.3.1997 / 16:14:01 / cg"
 ! !
 
 !ListView methodsFor:'drawing'!
@@ -1229,6 +1262,7 @@
     shown ifTrue:[
         list notNil ifTrue:[
             listSize := self numberOfLines.
+
             listSize == 0 ifTrue:[
                 widthOfWidestLine := 0.
             ].
@@ -1249,7 +1283,7 @@
     ^ super contentsChanged
 
     "Modified: 18.11.1996 / 19:50:07 / stefan"
-    "Modified: 8.2.1997 / 12:41:51 / cg"
+    "Modified: 5.3.1997 / 15:50:46 / cg"
 !
 
 keyPress:key x:x y:y
@@ -1744,6 +1778,40 @@
     "Modified: 19.2.1997 / 12:08:50 / stefan"
 !
 
+getListFromModelScroll:aBoolean
+    "ask my model (if any) for the text via the listMsg.
+     If there is no listMessage, try aspect for backward compatibility."
+
+    |text msg|
+
+    model notNil ifTrue:[
+        msg := listMsg.
+        msg isNil ifTrue:[
+            msg := aspectMsg
+        ].
+
+        msg notNil ifTrue:[
+            text := model perform:msg.
+            text notNil ifTrue:[
+                text := text asStringCollection.
+            ].
+"/ SV: this does not work, if model uses (i.e. updates) the same stringCollection
+"/ as the view!!
+"/            text ~= list ifTrue:[
+                aBoolean ifTrue:[
+                    self list:text
+                ] ifFalse:[
+                    self setList:text
+                ]
+"/            ].
+        ].
+    ].
+
+    "Modified: 19.2.1997 / 12:08:50 / stefan"
+    "Created: 5.3.1997 / 16:10:22 / cg"
+    "Modified: 5.3.1997 / 16:14:44 / cg"
+!
+
 lineOfCharacterPosition:charPos
     "given a character index within the contents-string,
      return the lineNumber where the character is
@@ -3516,5 +3584,5 @@
 !ListView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/ListView.st,v 1.125 1997-02-28 18:48:48 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/ListView.st,v 1.126 1997-03-05 16:31:43 cg Exp $'
 ! !