# HG changeset patch # User Claus Gittinger # Date 1403246368 -7200 # Node ID 935ad3a852624a0cdcf96ebea598e783d3f22bdb # Parent 9a90a9d52bc6edd0cf22f90a6b9677f98dbb8ff7 class: UIPainter comment/format in: #doStepDown #doStepUp diff -r 9a90a9d52bc6 -r 935ad3a85262 UIPainter.st --- a/UIPainter.st Wed Jun 18 18:26:32 2014 +0200 +++ b/UIPainter.st Fri Jun 20 08:39:28 2014 +0200 @@ -6206,7 +6206,7 @@ ! doStepDown - "moves the selected widget one step down in the hierarchy" + "moves the selected widget(s) one step down in the hierarchy" treeView doStepOver:1 ! @@ -6224,7 +6224,7 @@ ! doStepUp - "moves the selected widget one step up in the hierarchy" + "moves the selected widget(s) one step up in the hierarchy" treeView doStepOver:-1 ! @@ -6995,11 +6995,19 @@ "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: - [self selectedNode parent children size > 1]] - - +"/ old code (only allow if a single item is selected): +"/ +"/ ^(selection size == 1) and: +"/ [(selection at: 1) ~~ 1 and: +"/ [self selectedNode parent children size > 1]] + + ^ self selectedNodes + conform:[:eachSelectedNode | + |parent| + + (parent := eachSelectedNode parent) notNil + and:[parent children size > 1] + ]. ! canExchangeSelectionLayouts @@ -7189,6 +7197,58 @@ self selectNodes:itemList asOrderedCollection. ! +doStep:item over:anIndex + "moves a single child 'anIndex' forward or backward in list of children. + positive index: move down; negative index: move up" + + |idx size parentItem parentItemsView itemsView canvas prevSelection| + + self askForSelectionChangeAllowed ifFalse:[^ self]. + + ( item 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]]. + + prevSelection := self selectedNodes. + self setSelection:nil. + + 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 ]. + ]. + self selectNodes:prevSelection. + canvas showSelection. +! + doStepIn "move the currently selected widget into the next available container below" @@ -7223,6 +7283,19 @@ self askForSelectionChangeAllowed ifFalse:[^ self]. + anIndex < 0 ifTrue:[ + "/ moving up + self selectedNodes do:[:eachNode | + self doStep:eachNode over:anIndex. + ]. + ] ifFalse:[ + "/ moving down + self selectedNodes reverseDo:[:eachNode | + self doStep:eachNode over:anIndex. + ]. + ]. + ^ self. + ( (item := self selectedNode) isNil or:[(parentItem := item parent) isNil or:[(size := parentItem children size) < 2