*** empty log message ***
authorClaus Gittinger <cg@exept.de>
Thu, 05 Sep 2013 00:10:44 +0200
changeset 3053 db8d30e7a621
parent 3052 8734833de8fe
child 3054 22d13f07a426
*** empty log message ***
UIPainter.st
--- a/UIPainter.st	Wed Sep 04 21:52:50 2013 +0200
+++ b/UIPainter.st	Thu Sep 05 00:10:44 2013 +0200
@@ -5009,52 +5009,6 @@
     UserPreferences current systemBrowserClass openInClass:cls selector:aspect
 !
 
-doBrowseAspectClass:aspectSelector
-    "browse the class as entered in the field (can be called by buttons in a subspec)"
-
-    self doBrowseAspectClassAndSelector:{ aspectSelector . nil }
-!
-
-doBrowseAspectClassAndSelector:classAndSelectorPair
-    "browse the class as entered in the field (can be called by buttons in a subspec)"
-
-    |spec classAspect selectorAspect className selector class |
-
-    classAspect := classAndSelectorPair first.
-    selectorAspect := classAndSelectorPair second.
-
-    "/ wrong: the code below uses the spec's aspect values;
-    "/ but the spec is only valid after accepting.
-
-    "/    spec := painter specForSelection.
-    "/    spec isNil ifTrue:[^ self].
-    "/    className := spec perform:classAspect.
-    "/    
-    "/    selectorAspect notNil ifTrue:[
-    "/        selector := spec perform:selectorAspect.
-    "/    ].
-
-    "/ we have to take the current value from the widget's value,
-    "/ which is in the listOfAspects!!
-    className := (specTool aspectFor:classAspect) value.
-    selector := (specTool aspectFor:selectorAspect) value.
-
-    (className isEmptyOrNil or:[(selectorAspect notNil and:[selector isEmptyOrNil])]) ifTrue:[
-        Dialog information:(resources 
-                                string:'Class and/or selector missing (for "%1 / %2")'
-                                with:classAspect with:selectorAspect).
-        ^ self
-    ].
-    class := Smalltalk classNamed:className.
-    class isBehavior ifFalse:[
-        Dialog information:(resources 
-                                string:'"%1" does not refer to a valid class (in "%2")'
-                                with:className with:classAspect).
-        ^ self
-    ].
-    UserPreferences current systemBrowserClass openInClass:class selector:selector
-!
-
 doBrowseAspectMethod:aspectSelector
     "browse or create the aspect method as entered in the field (button beside input fieled pressed)"
 
@@ -5952,63 +5906,14 @@
 
 !UIPainter::TreeView class methodsFor:'documentation'!
 
-erarchy"
-
-    treeView doStepOver:-1
-! !
-
-!UIPainter::TreeView methodsFor:'accessing'!
-
-ditToolbar
-    self editToolBarVisibleHolder value:false
-!
-
-BarVisibleHolder value:false
-!
-
-Spec newSpec|
-
-    (aSpecOrWidgetClass isSubclassOf:UISpecification) ifTrue:[
-        newSpecClass := aSpecOrWidgetClass.
-    ] ifFalse:[
-        (aSpecOrWidgetClass isSubclassOf:View) ifTrue:[
-            newSpecClass := aSpecOrWidgetClass basicNew specClass.
-        ] ifFalse:[
-            newSpecClass := nil
-        ].
-    ].
-    newSpecClass isNil ifTrue:[
-        Dialog warn:'Invalid Spec- or View-Class: ' , aSpecOrWidgetClass name.
-        ^ self.
-    ].
-
-    treeView isCanvasSelected ifTrue:[
-        ^ self
-    ].
-    oldSpec := self selectedSpec.
-    newSpec := newSpecClass cloneFrom:oldSpec.
-
-    self painter replaceSelectionBy:newSpec.
-
-    "Modified: / 05-09-2012 / 19:24:40 / cg"
-!
-
-og warn:'Invalid Spec- or View-Class: ' , aSpecOrWidgetClass name.
-        ^ self.
-    ].
-
-    treeView isCanvasSelected ifTrue:[
-        ^ self
-    ].
-    oldSpec := self selectedSpec.
-    newSpec := newSpecClass cloneFrom:oldSpec.
-
-    self painter replaceSelectionBy:newSpec.
-
-    "Modified: / 05-09-2012 / 19:24:40 / cg"
-!
-
-TreeItem
+documentation
+"
+    selection in tree view; only used by the UIPainter
+
+    [see also:]
+        SelectionInTreeView
+        SelectionInTree
+        TreeItem
         UIPainter
 
     [author:]
@@ -6016,14 +5921,30 @@
 "
 
 
-!
-
-ew)"
+! !
+
+!UIPainter::TreeView methodsFor:'accessing'!
+
+canvas
+    "returns the canvas (UIPainterView)"
+
+    ^ model root contents view
+
+
+!
+
+canvas:aCanvas
+    "install canvas (UIPainterView)"
 
     self canvas:aCanvas specName:nil
 !
 
-props := UIPainterView::ViewProperty new.
+canvas:aCanvas specName:nameOfSpec
+    "install canvas (UIPainterView)"
+
+    |props|
+
+    props := UIPainterView::ViewProperty new.
     props view:aCanvas.
 
     model root:(TreeItem 
@@ -6034,11 +5955,7 @@
     self enableChannel:(aCanvas enableChannel).
 !
 
-model root expand.
-    self enableChannel:(aCanvas enableChannel).
-!
-
-pec
+canvasSpec
     "returns spec assigned to canvas"
 
     |spec list cls canvas|
@@ -6079,193 +5996,31 @@
   ^ spec
 !
 
-igned to canvas"
-
-    |spec list cls canvas|
-
-    spec := self windowSpecClass new.
-    canvas := self canvas.
-
-    spec fromView:(canvas topView) callBack:nil.
-
-    windowSpec notNil ifTrue:[
-        spec copyValuesFromSpec:windowSpec.
-    ].
-
-    spec exportedAspects isNil ifTrue:[
-        (     (cls  := canvas className) notNil
-         and:[(cls  := canvas resolveName:cls) notNil]
-        ) ifTrue:[
-            list := cls perform:#aspectSelectors ifNotUnderstood:nil.
-        ].
-        spec setExportedAspectsFrom:list.
-        windowSpec notNil ifTrue:[
-            windowSpec exportedAspects:(spec exportedAspects).
-        ]
-    ].
-
-    self propertiesDo:[:aProp| 
-        |propsSpec|
-
-        spec exportedAspectsAddKey:(aProp model) type:nil.
-        propsSpec := aProp spec.
-        propsSpec aspectSelectors 
-                select:[:a | a isString or:[a isSymbol]] 
-                thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:nil].
-        propsSpec actionSelectors 
-                select:[:a | a isString or:[a isSymbol]] 
-                thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:#action].
-    ].
-  ^ spec
-!
-
-spec := self windowSpecClass new.
-    canvas := self canvas.
-
-    spec fromView:(canvas topView) callBack:nil.
-
-    windowSpec notNil ifTrue:[
-        spec copyValuesFromSpec:windowSpec.
-    ].
-
-    spec exportedAspects isNil ifTrue:[
-        (     (cls  := canvas className) notNil
-         and:[(cls  := canvas resolveName:cls) notNil]
-        ) ifTrue:[
-            list := cls perform:#aspectSelectors ifNotUnderstood:nil.
-        ].
-        spec setExportedAspectsFrom:list.
-        windowSpec notNil ifTrue:[
-            windowSpec exportedAspects:(spec exportedAspects).
-        ]
-    ].
-
-    self propertiesDo:[:aProp| 
-        |propsSpec|
-
-        spec exportedAspectsAddKey:(aProp model) type:nil.
-        propsSpec := aProp spec.
-        propsSpec aspectSelectors 
-                select:[:a | a isString or:[a isSymbol]] 
-                thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:nil].
-        propsSpec actionSelectors 
-                select:[:a | a isString or:[a isSymbol]] 
-                thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:#action].
-    ].
-  ^ spec
-!
-
-l.
-
-    windowSpec notNil ifTrue:[
-        spec copyValuesFromSpec:windowSpec.
-    ].
-
-    spec exportedAspects isNil ifTrue:[
-        (     (cls  := canvas className) notNil
-         and:[(cls  := canvas resolveName:cls) notNil]
-        ) ifTrue:[
-            list := cls perform:#aspectSelectors ifNotUnderstood:nil.
-        ].
-        spec setExportedAspectsFrom:list.
-        windowSpec notNil ifTrue:[
-            windowSpec exportedAspects:(spec exportedAspects).
-        ]
-    ].
-
-    self propertiesDo:[:aProp| 
-        |propsSpec|
-
-        spec exportedAspectsAddKey:(aProp model) type:nil.
-        propsSpec := aProp spec.
-        propsSpec aspectSelectors 
-                select:[:a | a isString or:[a isSymbol]] 
-                thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:nil].
-        propsSpec actionSelectors 
-                select:[:a | a isString or:[a isSymbol]] 
-                thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:#action].
-    ].
-  ^ spec
-! !
-
-!UIPainter::TreeView methodsFor:'accessing-property'!
-
-as className) notNil
-         and:[(cls  := canvas resolveName:cls) notNil]
-        ) ifTrue:[
-            list := cls perform:#aspectSelectors ifNotUnderstood:nil.
-        ].
-        spec setExportedAspectsFrom:list.
-        windowSpec notNil ifTrue:[
-            windowSpec exportedAspects:(spec exportedAspects).
-        ]
-    ].
-
-    self propertiesDo:[:aProp| 
-        |propsSpec|
-
-        spec exportedAspectsAddKey:(aProp model) type:nil.
-        propsSpec := aProp spec.
-        propsSpec aspectSelectors 
-                select:[:a | a isString or:[a isSymbol]] 
-                thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:nil].
-        propsSpec actionSelectors 
-                select:[:a | a isString or:[a isSymbol]] 
-                thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:#action].
-    ].
-  ^ spec
-!
-
-stood:nil.
-        ].
-        spec setExportedAspectsFrom:list.
-        windowSpec notNil ifTrue:[
-            windowSpec exportedAspects:(spec exportedAspects).
-        ]
-    ].
-
-    self propertiesDo:[:aProp| 
-        |propsSpec|
-
-        spec exportedAspectsAddKey:(aProp model) type:nil.
-        propsSpec := aProp spec.
-        propsSpec aspectSelectors 
-                select:[:a | a isString or:[a isSymbol]] 
-                thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:nil].
-        propsSpec actionSelectors 
-                select:[:a | a isString or:[a isSymbol]] 
-                thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:#action].
-    ].
-  ^ spec
-!
-
-esDo:[:aProp| 
-        |propsSpec|
-
-        spec exportedAspectsAddKey:(aProp model) type:nil.
-        propsSpec := aProp spec.
-        propsSpec aspectSelectors 
-                select:[:a | a isString or:[a isSymbol]] 
-                thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:nil].
-        propsSpec actionSelectors 
-                select:[:a | a isString or:[a isSymbol]] 
-                thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:#action].
-    ].
-  ^ spec
-! !
-
-!UIPainter::TreeView methodsFor:'adding & removing'!
-
-sSymbol]] 
-                thenDo:[:aKey|spec exportedAspectsAddKey:aKey type:#action].
-    ].
-  ^ spec
-!
-
-spec
-!
-
-aView notNil ifTrue:[
+canvasSpec:aSpec
+    "update canvas from spec"
+
+    |spec|
+
+    self setAttributesFromWindowSpec:aSpec.
+    spec := aSpec copy.
+    spec  menu:nil.
+    spec flags:nil.
+
+    spec setAttributesIn:(self canvas "topView") with:(UIBuilder new isEditing:true).
+!
+
+exportedAspects
+    "returns spec assigned to canvas"
+
+    windowSpec isNil ifTrue:[^ #()].
+    ^ windowSpec exportedAspects ? #()
+
+!
+
+itemOfView:aView
+    "returns item assigned to view or nil"
+
+    aView notNil ifTrue:[
         self allItemsDo:[:anItem|
             (anItem contents view == aView) ifTrue:[^ anItem]
         ]
@@ -6275,15 +6030,45 @@
 
 !
 
-ass
+lastDrawnMaster
+    "returns the lastDrawnMaster"
+
+    ^ lastDrawnMaster
+
+
+!
+
+painter
+    ^ painter
+!
+
+painter:something
+    painter := something.
+!
+
+windowSpecClass
+    "returns the default  windowSpecClass (WindowSpec)"
+
+    ^ windowSpecClass ? WindowSpec
+!
+
+windowSpecClass:aClass
     "set the default windowSpecClass"
 
     ^ windowSpecClass := aClass
 ! !
 
-!UIPainter::TreeView methodsFor:'building'!
-
-yDetect:aOneArgBlock
+!UIPainter::TreeView methodsFor:'accessing-property'!
+
+propertiesDo:aOneArgBlock
+    "evaluates the argument a block on each property"
+
+    self allItemsDo:[:anItem| aOneArgBlock value:(anItem contents)]
+
+
+!
+
+propertyDetect:aOneArgBlock
     "evaluates the block on each property"
 
     self allItemsDo:[:anItem|
@@ -6293,7 +6078,30 @@
 
 !
 
-y beforeIndex:anIndex
+propertySelected
+    "returns current selected property or nil in case of multi selection
+     or empty selection "
+
+    |idx|
+
+    selection size == 1 ifTrue:[
+        (idx := selection first) ~~ 1 ifTrue:[          "canvas: not yet supported"
+            ^ (listOfNodes at:idx) contents
+        ]
+    ].
+    ^ nil
+
+! !
+
+!UIPainter::TreeView methodsFor:'adding & removing'!
+
+addProperty:aProperty
+    "adds a new item"
+
+    ^ self addProperty:aProperty beforeIndex:nil.
+!
+
+addProperty:aProperty beforeIndex:anIndex
     "adds a new item"
 
     |parent treeItem index| 
@@ -6309,11 +6117,15 @@
     ].
     model add:treeItem beforeIndex:index below:parent.
     ^ treeItem
-! !
-
-!UIPainter::TreeView methodsFor:'canvas selection'!
-
-copy do:[:aView|
+!
+
+removeAll
+    "removes all items other than canvas"
+
+    lastDrawnMaster := nil.
+    windowSpec := nil.
+
+    self canvas components copy do:[:aView|
         aView destroy
     ].
     self canvas subViews copy do:[:aView|
@@ -6324,7 +6136,23 @@
     model removeAllOtherThanRoot.
 !
 
-orComponents:aSpecArray named:specNameSymbol
+removeView:aView
+    "removes a view"
+
+    |item prnt|
+
+    ((item := self itemOfView:aView) notNil and:[(prnt := item parent) notNil]) ifTrue:[
+        aView destroy.
+        prnt contents view sizeChanged:nil.
+        model remove:item
+    ]
+
+
+! !
+
+!UIPainter::TreeView methodsFor:'building'!
+
+generateFullSpecForComponents:aSpecArray named:specNameSymbol
     "generates a full spec from aSpecArray"
 
     |fullSpec winSpec|
@@ -6348,18 +6176,11 @@
     ^ fullSpec.
 !
 
-wSpec (which should not)
-        self canvas gridShown ifTrue:[
-            fullSpec window backgroundColor:nil.    
-        ].
-    ] ifFalse:[
-        winSpec copyValuesFromSpec:windowSpec.
-    ].    
-    winSpec name: winSpec label.
-    ^ fullSpec.
-!
-
-|name canvasView builder|
+setAttributesFromWindowSpec:aWindowSpec
+    "sets a window spec from aWindowSpec and applies some attributes
+     to the canvas."
+
+    |name canvasView builder|
 
     windowSpec := (self windowSpecClass) new copyValuesFromSpec:aWindowSpec.
     canvasView := self canvas.
@@ -6373,15 +6194,18 @@
     self application treeSelectionChanged.
 ! !
 
-!UIPainter::TreeView methodsFor:'change & update'!
-
-:= aWindowSpec label.
-    canvasView topView name:name.
-    self canvasNameChanged:name.
-    self application treeSelectionChanged.
-!
-
-True:[
+!UIPainter::TreeView methodsFor:'canvas selection'!
+
+canvasSelection:aSelection
+    "canvas changed its selection
+    "
+    |sel list size|
+
+    ((sel := aSelection) isNil or:[sel isCollection]) ifFalse:[
+        sel := Array with:sel
+    ].
+
+    (size := sel size) ~~ 0 ifTrue:[
         list := OrderedCollection new:size.
 
         sel do:[:aView|
@@ -6397,16 +6221,41 @@
     self canvasEventsDisabledDo:[ self selection:sel ].            
 !
 
-]
-        ].
-        sel := list collect:[:anItem| self indexOfNode:anItem ].
-    ].
-    self canvasEventsDisabledDo:[ self selection:sel ].            
-! !
-
-!UIPainter::TreeView methodsFor:'drag & drop'!
-
-election 
+canvasSelectionAdd:aView
+    "canvas adds a view to current selection
+    "
+    |item index oldSel|
+
+    item := self itemOfView:aView.
+
+    item notNil ifTrue:[
+        model doMakeVisible:item.
+
+        (index := self indexOfNode:item) ~~ 0 ifTrue:[
+            oldSel := selection copy.
+            self addToSelection:index.
+            self selectionChangedFrom:oldSel
+        ]        
+    ]            
+!
+
+canvasSelectionRemove:aView
+    "canvas removes a view from current selection
+    "
+    |item index oldSel|
+
+    (     (item := self itemOfView:aView) notNil
+     and:[(index := self indexOfNode:item) ~~ 0
+     and:[self isInSelection:index]]
+    ) ifTrue:[
+        oldSel := selection copy.
+        self removeFromSelection:index.
+        self selectionChangedFrom:oldSel.
+    ].
+!
+
+selectedViews
+    ^ self selection 
         collect:[:index |
             |node view|
 
@@ -6414,13 +6263,16 @@
             view := node contents view.
             view
         ]
-!
-
-view
-        ]
-!
-
-fNodes at:1.
+! !
+
+!UIPainter::TreeView methodsFor:'change & update'!
+
+canvasNameChanged:aName
+    "called if identification name assigned to window (canvas) changed
+    "
+    |name node|
+
+    node := listOfNodes at:1.
 
     (    aName size ~~ 0
      and:[(name := aName string withoutSeparators) size ~~ 0
@@ -6432,14 +6284,9 @@
     ].
 !
 
-]]
-    ) ifTrue:[
-        node name: name asBoldText.
-        node changed.   
-    ].
-!
-
-d to update its layout
+layoutChanged
+    "layout of any component changed; in case of single selection, the
+     application will be informed to update its layout
     "
     selection size == 1 ifTrue:[
         self application layoutChanged
@@ -6448,7 +6295,8 @@
 
 !
 
-perty changed
+propertyChanged:aProperty
+    "property of view derived from argument a property changed
     "
     |item idx end|
 
@@ -6481,83 +6329,19 @@
     ].
 
 
-!
-
-ame = aProperty name ifFalse:[
-            idx := self firstLineShown.
-
-            (end := self lastLineShown) > listOfNodes size ifTrue:[
-                end := listOfNodes size
-            ].                          
-            item changed.   
-
-            [idx <= end] whileTrue:[
-                (listOfNodes at:idx) == item ifTrue:[
-                    self redrawLine:idx.                "/ is visible; redraw line
-                    end := 0
-                ] ifFalse:[
-                    idx := idx + 1
-                ]
-            ]
-        ].
-
-        self selectedNode == item ifTrue:[              "/ inform application
-            self application propertyChanged
-        ]
-    ].
-
-
-!
-
-].                          
-            item changed.   
-
-            [idx <= end] whileTrue:[
-                (listOfNodes at:idx) == item ifTrue:[
-                    self redrawLine:idx.                "/ is visible; redraw line
-                    end := 0
-                ] ifFalse:[
-                    idx := idx + 1
-                ]
-            ]
-        ].
-
-        self selectedNode == item ifTrue:[              "/ inform application
-            self application propertyChanged
-        ]
-    ].
-
-
 ! !
 
-!UIPainter::TreeView methodsFor:'enumerating'!
-
-end := 0
-                ] ifFalse:[
-                    idx := idx + 1
-                ]
-            ]
-        ].
-
-        self selectedNode == item ifTrue:[              "/ inform application
-            self application propertyChanged
-        ]
-    ].
-
-
-! !
-
-!UIPainter::TreeView methodsFor:'event handling'!
-
-rm application
-            self application propertyChanged
-        ]
-    ].
-
-
-!
-
-ntext at:aPoint
+!UIPainter::TreeView methodsFor:'drag & drop'!
+
+canDrop:aDropContext
+    "can drop ? -> delegate to canvas"
+
+    ^ self canvas canDrop:aDropContext
+
+    "Modified: / 13-10-2006 / 16:08:43 / cg"
+!
+
+canDrop:aDropContext at:aPoint
     "can drop ? -> delegate to canvas"
 
     ^ self canvas canDrop:aDropContext at:aPoint
@@ -6566,43 +6350,155 @@
     "Modified: / 13-10-2006 / 16:08:46 / cg"
 !
 
-/ cg"
-    "Modified: / 13-10-2006 / 16:08:46 / cg"
+canDropObjects:aCollectionOfDropObjects
+    "can drop ? -> delegate to canvas"
+
+    ^ self canvas canDropObjects:aCollectionOfDropObjects
+
+    "Created: / 13-10-2006 / 16:08:31 / cg"
+!
+
+canDropObjects:aCollectionOfDropObjects at:aPoint
+    "can drop ? -> delegate to canvas"
+
+    ^ self canvas canDropObjects:aCollectionOfDropObjects at:aPoint
+
+    "Created: / 13-10-2006 / 16:08:35 / cg"
+!
+
+drop:aDropContext
+    "drop objects -> delegate to canvas"
+
+    self canvas drop:aDropContext
+
+    "Created: / 13-10-2006 / 12:35:59 / cg"
+    "Modified: / 13-10-2006 / 16:09:04 / cg"
+!
+
+drop:aDropContext at:aPoint
+    "drop objects -> delegate to canvas"
+
+    self canvas drop:aDropContext at:nil
+
+    "Modified: / 13-10-2006 / 16:09:07 / cg"
+!
+
+dropObjects:aCollectionOfDropObjects
+    "drop objects -> delegate to canvas"
+
+    self canvas dropObjects:aCollectionOfDropObjects
+
+    "Created: / 13-10-2006 / 16:08:51 / cg"
+!
+
+dropObjects:aCollectionOfDropObjects at:aPoint
+    "drop objects -> delegate to canvas"
+
+    self canvas dropObjects:aCollectionOfDropObjects at:nil
+
+    "Created: / 13-10-2006 / 16:08:56 / cg"
+! !
+
+!UIPainter::TreeView methodsFor:'enumerating'!
+
+allItemsDo:aOneArgBlock
+    "evaluates the argument a block on each item other than the canvas"
+
+    model root allChildrenDo:aOneArgBlock
+
+
+! !
+
+!UIPainter::TreeView methodsFor:'event handling'!
+
+canvasEventsDisabledDo:aBlock
+    "evaluates the block without raising selection changed notifications to canvas"
+
+    |restoreCanvasEvents|
+
+    restoreCanvasEvents  := canvasEventsDisabled.
+    canvasEventsDisabled := true.
+    aBlock value.
+    canvasEventsDisabled := restoreCanvasEvents.
+!
+
+doubleClicked
+    "disables collapsing of the root item"
+
+    self selectedNode == model root ifFalse:[
+        super doubleClicked
+    ]
+
+
+!
+
+redrawLabelAt:x y:yTop index:anIndex
+    "draws a tiny rectangle for indicating the master node (first selected node)"
+
+    |dX|
+
+    super redrawLabelAt:x y:yTop index:anIndex.
+
+    ((selection size > 1) and: [selection first == anIndex]) ifTrue:[
+        dX := textInset - 1.
+        self paint:(Color red). "/ self application painter handleMasterColor.
+        self fillRectangleX:(x - dX - 2)
+                          y:yTop + ((fontHeight - dX) // 2)
+                      width:dX
+                     height:dX
+    ]
 ! !
 
 !UIPainter::TreeView methodsFor:'initialization'!
 
-cg"
-    "Modified: / 13-10-2006 / 16:09:04 / cg"
-!
-
-"Modified: / 13-10-2006 / 16:09:07 / cg"
-!
-
-: / 13-10-2006 / 16:08:56 / cg"
+iconForNode:aNode
+    |spec|       
+
+    spec := aNode contents spec.
+    spec isNil ifTrue: [
+        ^ WindowSpec icon
+    ] ifFalse:[
+        ^ spec icon
+    ]
+!
+
+initialize
+    "initialize the tree view; multiple select and tree item actions"
+
+    super initialize.
+
+    self multipleSelectOk:true.
+    canvasEventsDisabled := false.
+    self showDirectoryIndicator: true.
+    self showDirectoryIndicatorForRoot: false.
+
+    self model 
+        iconAction:[:aNode| self iconForNode:aNode];
+        labelAction: [:aNode | self labelForNode:aNode].
+!
+
+labelForNode:aNode
+    |spec|
+
+    spec := aNode contents spec.
+    spec notNil ifTrue: [
+        ^ self nameForSpecInList:spec
+    ] ifFalse:[
+        ^ aNode name
+    ]
 ! !
 
 !UIPainter::TreeView methodsFor:'private'!
 
-ock
-
-
-!
-
-Clicked
-    ]
-
-
-! !
-
-!UIPainter::TreeView methodsFor:'queries'!
-
-[
-        ^ aNode name
-    ]
-!
-
-aspect := aSpec nameOfMainAspect.
+nameForSpecInList:aSpec
+    "returns the tree item label for aSpec"
+
+    |aspect aspectPrefix nameString viewClassString|
+
+    nameString := aSpec name ? ''.
+    viewClassString := '[',aSpec viewClass name,']' .
+
+    aspect := aSpec nameOfMainAspect.
     aspect notNil ifTrue:[
         aspectPrefix := '(',aspect allBold ,') '
     ] ifFalse:[
@@ -6614,7 +6510,7 @@
     "Modified: / 17-08-2011 / 09:10:31 / cg"
 !
 
-m:oldSelection
+selectionChangedFrom:oldSelection
     "selection has changed. update master selection and raise notification
      to canvas in case of enabled cvs events
     "
@@ -6651,38 +6547,13 @@
     ifFalse: [
         lastDrawnMaster := nil
     ] 
-!
-
-].             
-    size = 1 ifTrue:[
-        oldSelection size > 1 ifTrue: [
-            (listOfNodes at:lastDrawnMaster) retrieveLabel.
-            self redrawLine: lastDrawnMaster. 
-            lastDrawnMaster := selection first
-        ]
-    ].
-    size > 1 ifTrue:[
-        selection first ~~ lastDrawnMaster ifTrue: [
-            (listOfNodes at:selection first) retrieveLabel.
-            lastDrawnMaster notNil ifTrue: [(listOfNodes at:lastDrawnMaster) retrieveLabel].
-            self redrawLine: lastDrawnMaster. 
-            self redrawLine: (lastDrawnMaster := selection first)
-        ]
-    ]         
-    ifFalse: [
-        lastDrawnMaster := nil
-    ] 
-!
-
-er := selection first)
-        ]
-    ]         
-    ifFalse: [
-        lastDrawnMaster := nil
-    ] 
-!
-
-on"
+! !
+
+!UIPainter::TreeView methodsFor:'queries'!
+
+canChangeOrderInContainer
+    "returns true if any selection exists and all widgets in the selection
+     can change their layout through to a move or align operation"
 
     ^(selection size == 1)  and: 
     [(selection at: 1) ~~ 1 and:   
@@ -6691,7 +6562,18 @@
 
 !
 
-AlignSelection
+canExchangeSelectionLayouts 
+    "returns true if the selections size is exactly 2
+     and all widgets in the selection
+     can change their layout through to a move or align operation"
+
+    selection size == 2 ifFalse:[
+        ^ false
+    ].
+    ^ self canMoveOrAlignSelection
+!
+
+canMoveOrAlignSelection
     "returns true if any selection exists and all widgets in the selection
      can change their layout through to a move or align operation"
 
@@ -6715,40 +6597,7 @@
     ^ true
 !
 
-tyOrNil ifTrue:[
-        ^ false
-    ].
-
-    selection do:[:i|
-        |node view|
-
-        i == 1 ifTrue:[
-            "/ the tree node for the canvas itself.
-            ^ false
-        ].
-        node := listOfNodes at:i.
-        view := node contents view.
-        (self canvas canChangeLayoutOfView:view) ifFalse:[
-            ^ false
-        ]
-    ].
-    ^ true
-!
-
-^ false
-        ].
-        node := listOfNodes at:i.
-        view := node contents view.
-        (self canvas canChangeLayoutOfView:view) ifFalse:[
-            ^ false
-        ]
-    ].
-    ^ true
-! !
-
-!UIPainter::TreeView methodsFor:'searching'!
-
-ectionIntoContainer
+canMoveSelectionIntoContainer
     "returns true in case that one widget is selected and can change its container
      widget to an element below"
 
@@ -6764,18 +6613,10 @@
     ].
 
     ^ false
-! !
-
-!UIPainter::TreeView methodsFor:'user interaction'!
-
-] startingAt:idx ifNone:nil.
-        ^ newParentItem notNil.
-    ].
-
-    ^ false
-!
-
-rue in case that one widget is selected which is contained within
+!
+
+canMoveSelectionOutOfContainer
+    "returns true in case that one widget is selected which is contained within
      another widget"
 
     |item prnt|
@@ -6789,7 +6630,9 @@
     ^ true
 !
 
-within a widget which allows to resize sub components"
+canResizeSelectedWidget
+    "returns true in case of one widget selected and is contained
+     within a widget which allows to resize sub components"
 
     |selectedNode|
 
@@ -6801,14 +6644,74 @@
     ^ false
 !
 
-ctionChangeAllowed 
+canResizeSelection
+    "returns true if all selected widgets can be resized"
+
+    selection isEmptyOrNil ifTrue:[ ^ false ].
+    ^ self canvas canResize:(self selectedViews)
+!
+
+hasOneSelectionOtherThanCanvas
+    "returns true in case that one selection exists other than the canvas"
+
+    ^ selection size == 1 and:[selection first ~~ 1]
+!
+
+isCanvasSelected
+    "returns true in case of a single selection and the
+     selection is the canvas (index 1)"
+
+    ^ selection size == 1 and:[self isInSelection:1]
+! !
+
+!UIPainter::TreeView methodsFor:'searching'!
+
+detectItemCorespondingToView:aView
+    "detects the item coresponding to the view. The item of the view or the first
+     subview providing the item is returned. If no property is detected nil is
+     returned"
+
+    |view item|
+
+    (view := aView) isNil ifTrue:[ ^ nil ].
+
+    [(item := self itemOfView:view) isNil] whileTrue:[
+        (view := view superView) isNil ifTrue:[^ listOfNodes at:1]
+    ].
+    ^ item
+! !
+
+!UIPainter::TreeView methodsFor:'user interaction'!
+
+askForSelectionChangeAllowed 
     selectConditionBlock notNil ifTrue:[
         ^ selectConditionBlock value:nil 
     ].
     ^ true
 !
 
-kForSelectionChangeAllowed ifFalse:[^ self].
+doChangeParentOfSelectedItemTo:newParentItem
+
+    |canvas|
+
+    newParentItem isNil ifTrue:[
+        ^ self
+    ].
+    self askForSelectionChangeAllowed ifFalse:[^ self].    
+    self setSelection:nil.
+
+    canvas := self canvas.
+    canvas deleteSelection.
+    canvas setSelection:(newParentItem contents view) withRedraw:false.
+    canvas pasteWithLayout.
+!
+
+doSortItems
+    "sort items by their top-left position"
+
+    |selectedItems parent sortedItems newChildren itemList parentView|
+
+    self askForSelectionChangeAllowed ifFalse:[^ self].
 
     selectedItems := self selectedNodes.
     selectedItems size <= 1 ifTrue:[^ self].
@@ -6846,37 +6749,80 @@
     self selectNodes:itemList asOrderedCollection.
 !
 
-sNil or:[(selectedItems conform:[:e| e parent == parent]) not]) ifTrue:[^ self].
-
-    sortedItems := selectedItems sort:[:a :b| 
-                            a contents view origin isLeftOrAbove:(b contents view origin)].
-    itemList := selectedItems asIdentitySet.
-
-    newChildren := parent children collect:[:eachChild|
-        (itemList includes:eachChild) ifTrue:[
-            sortedItems removeFirst.
-        ] ifFalse:[
-            eachChild.
+doStepIn
+    "move the currently selected widget into the next available container below"
+    
+    |item oldParentItem newParentItem idx|
+
+    item := self selectedNode.
+    (item notNil and:[(oldParentItem := item parent) notNil]) ifTrue:[
+        idx := (oldParentItem indexOfChild:item) + 1.
+        newParentItem := oldParentItem children 
+                    detect:[:eachChild | eachChild contents spec class supportsSubComponents]
+                    startingAt:idx
+                    ifNone:nil.
+        newParentItem notNil ifTrue:[
+            self doChangeParentOfSelectedItemTo:newParentItem
         ].
-    ].
+    ]
+!
+
+doStepOut
+    |item|
+
+    item := self selectedNode.    
+    (item notNil and:[(item := item parent) notNil]) ifTrue:[
+        self doChangeParentOfSelectedItemTo:(item parent)
+    ].
+!
+
+doStepOver:anIndex
+    "moves child 'anIndex' forward or backward in list of children"
+
+    |item idx size parentItem parentItemsView itemsView canvas|
+
+    self askForSelectionChangeAllowed ifFalse:[^ self].
+
+    (    (item := self selectedNode) isNil
+     or:[(parentItem := item parent) isNil
+     or:[(size := parentItem children size) < 2
+     or:[(idx  := parentItem indexOfChild:item) == 0]]]
+    ) ifTrue:[
+        ^ self
+    ].
+
+    idx := idx + anIndex.
+
+    idx < 1 ifTrue:[idx := size]
+           ifFalse:[idx > size ifTrue:[idx := 1]].
 
     self setSelection:nil.
-    model remove:parent children.
-    model add:newChildren beforeIndex:1 below:parent.
-
-    parentView := parent contents view.
-
-    self canvas hideSelection.
-    newChildren keysAndValuesDo:[:idx :eachItem|
-        parentView changeSequenceOrderFor:eachItem contents view to:idx.
-    ].
-    parentView specClass isLayoutContainer ifFalse:[
-        parentView components notEmptyOrNil ifTrue:[ self halt ].
-        parentView subViews do:[:v| v raise ].
-    ].
-    self canvas showSelection.
-
-    self selectNodes:itemList asOrderedCollection.
+    model remove:item.
+    model add:item beforeIndex:idx below:parentItem.
+
+    idx := parentItem indexOfChild:item.
+    itemsView := item contents view.
+    parentItemsView := parentItem contents view.
+
+    canvas := self canvas.
+    canvas hideSelection.
+
+    itemsView isView ifFalse:[
+        "/ a component - has its own collection (and therefore indexing) - sigh
+        idx := idx - ((1 to:idx-1) count:[:i | (parentItem children at:i) contents view isView]).
+        parentItemsView changeSequenceOrderFor:itemsView to:idx.
+    ] ifTrue:[
+        "/ a view - has its own collection (and therefore indexing) - sigh
+        idx := idx - ((1 to:idx-1) count:[:i | (parentItem children at:i) contents view isView not]).
+        parentItemsView changeSequenceOrderFor:itemsView to:idx.
+    ].
+
+    parentItemsView specClass isLayoutContainer ifFalse:[
+        "/ spVw components notEmptyOrNil ifTrue:[ self halt ].
+        parentItemsView subViews do:[:v| v raise ].
+    ].
+    canvas showSelection.
+    self selectNode:item.
 ! !
 
 !UIPainter class methodsFor:'documentation'!