reuse methods provided by the model
authorca
Tue, 14 Apr 1998 13:32:46 +0200
changeset 774 5ca0853de0bc
parent 773 de5c99bd3078
child 775 0ead717f3e35
reuse methods provided by the model
UIPainter.st
--- a/UIPainter.st	Fri Apr 10 19:21:21 1998 +0200
+++ b/UIPainter.st	Tue Apr 14 13:32:46 1998 +0200
@@ -3323,8 +3323,7 @@
         (aView isKindOf:InputView) ifFalse:[aView destroy]
     ].
     model root name: UIPainter defaultNameOfCanvas asBoldText.
-    model root children:(OrderedCollection new).
-    model recomputeList.                
+    model removeAllOtherThanRoot.
 
 !
 
@@ -3376,38 +3375,31 @@
 cvsSelection:aSelection
     "canvas changed its selection
     "
-    |sel list rcLt|
-
+    |sel list|
+
+    (     aSelection isNil
+     or:[(aSelection isCollection and:[aSelection isEmpty])]
+    ) ifTrue:[
+        ^ self cvsEventsDisabledDo:[ self selection:sel ]
+    ].
     list := OrderedCollection new.
 
-    aSelection isNil ifFalse:[
-        aSelection isCollection ifTrue:[
-            aSelection notNil ifTrue:[sel := aSelection]
-        ] ifFalse:[
-            sel := Array with:aSelection
+    aSelection isCollection ifTrue:[
+        aSelection notNil ifTrue:[sel := aSelection]
+    ] ifFalse:[
+        sel := Array with:aSelection
+    ].
+
+    list := OrderedCollection new:(sel size).
+    self setSelection:nil.
+
+    sel do:[:aView||item|
+        (item := self itemOfView:aView) notNil ifTrue:[
+            list add:item.
+            model doMakeVisible:item.
         ]
     ].
-
-    sel notNil ifTrue:[
-        rcLt := false.
-
-        sel do:[:aView||item|
-            (item := self itemOfView:aView) notNil ifTrue:[
-                list add:item.
-
-                [(item := item parent) notNil] whileTrue:[
-                    item hidden ifTrue:[
-                        rcLt := true.
-                        item expand.
-                    ]
-                ]
-            ]
-        ].
-        rcLt ifTrue:[model recomputeList].
-        sel := list collect:[:anItem| listOfNodes findFirst:[:el| el == anItem]]
-    ] ifFalse:[
-        sel := list
-    ].
+    sel := list collect:[:anItem| self indexOfNode:anItem ].
     self cvsEventsDisabledDo:[ self selection:sel ].            
 
 
@@ -3418,25 +3410,19 @@
 cvsSelectionAdd:aView
     "canvas adds a view to current selection
     "
-    |parent item rcLt oldSel|
+    |item index oldSel|
 
     item := self itemOfView:aView.
 
     item notNil ifTrue:[
-        parent := item.
-
-        [ (parent := parent parent) notNil ] whileTrue:[
-            parent hidden ifTrue:[
-                rcLt := true.
-                parent expand.
-            ]
-        ].
-        rcLt == true ifTrue:[model recomputeList].
-
-        oldSel := selection copy.
-        self addToSelection:(listOfNodes findFirst:[:el| el == item]).
-        self selectionChangedFrom:oldSel
-    ].            
+        model doMakeVisible:item.
+
+        (index := self indexOfNode:item) ~~ 0 ifTrue:[
+            oldSel := selection copy.
+            self addToSelection:index.
+            self selectionChangedFrom:oldSel
+        ]        
+    ]            
 
 
 
@@ -3445,26 +3431,16 @@
 cvsSelectionRemove:aView
     "canvas removes a view from current selection
     "
-    |parent item rcLt oldSel|
-
-    item := self itemOfView:aView.
-
-    item notNil ifTrue:[
-        parent := item.
-
-        [ (parent := parent parent) notNil ] whileTrue:[
-            parent hidden ifTrue:[
-                rcLt := true.
-                parent expand.
-            ]
-        ].
-        rcLt == true ifTrue:[model recomputeList].
-
+    |item index oldSel|
+
+    (     (item := self itemOfView:aView) notNil
+     and:[(index := self indexOfNode:item) ~~ 0
+     and:[self isInSelection:index]]
+    ) ifTrue:[
         oldSel := selection copy.
-        self removeFromSelection:(listOfNodes findFirst:[:el| el == item]).
-        self selectionChangedFrom:oldSel
-    ].            
-
+        self removeFromSelection:index.
+        self selectionChangedFrom:oldSel.
+    ].
 
 
 ! !
@@ -3575,21 +3551,6 @@
 
 !
 
-cvsSetupListDo:aBlock
-    "evaluates block without handling notifications from model; after evaluation
-     the new list will be recomputed"
-
-    model removeDependent:self.
-
-    self cvsEventsDisabledDo:[
-        self selection:nil.
-        aBlock value
-    ].
-    model addDependent:self.
-    model recomputeList.
-
-!
-
 doubleClicked
     "disables collapsing of the root item"
 
@@ -3791,37 +3752,39 @@
 
 !UIPainter::TreeView methodsFor:'user interactions'!
 
+doChangeHierarchyOf:anItem
+
+    |canvas|
+
+    anItem isNil ifTrue:[
+        ^ self
+    ].
+    self setSelection:nil.
+
+    canvas := self canvas.
+    canvas deleteSelection.
+    canvas setSelection:(anItem contents view) withRedraw:false.
+    canvas pasteWithLayout.
+!
+
 doStepIn
-    |item prnt canvas|
+    |item prnt|
 
     (     (item := self selectedNode) isNil
       or:[(prnt := item parent) isNil
       or:[(prnt := prnt childAt:((prnt indexOfChild:item) + 1)) isNil
       or:[prnt contents spec class supportsSubComponents not]]]
     ) ifFalse:[
-        canvas := self canvas.
-        canvas deleteSelection.
-        canvas setSelection:(prnt contents view) withRedraw:false.
-        canvas pasteWithLayout.
+        self doChangeHierarchyOf:prnt
     ]
 !
 
 doStepOut
-    |item next prnt canvas|
-
-    (     (item := self selectedNode) isNil
-      or:[(prnt := item parent) isNil
-      or:[(next := prnt parent) isNil]]
-    ) ifTrue:[
-        ^ self
+    |item|
+
+    ((item := self selectedNode) notNil and:[(item := item parent) notNil]) ifTrue:[
+        self doChangeHierarchyOf:(item parent)
     ].
-    model removeDependent:self.
-
-    canvas := self canvas.
-    canvas deleteSelection.
-    canvas setSelection:(next contents view) withRedraw:false.
-    canvas pasteWithLayout.
-
 !
 
 doStepOver:anIndex
@@ -3836,16 +3799,15 @@
     ) ifTrue:[
         ^ self
     ].
-    model removeDependent:self.
-    model removeSelection.
-    selection := nil.
-    model addDependent:self.
     idx := idx + anIndex.
 
     idx < 1 ifTrue:[idx := size]
            ifFalse:[idx > size ifTrue:[idx := 1]].
 
+    self setSelection:nil.
+    model remove:item.
     model add:item beforeIndex:idx below:prnt.
+
     idx    := prnt indexOfChild:item.
     view   := item contents view.
     spVw   := prnt contents view.