cg: check if selection change is allowed BEFORE changing the
actual selection (to avoid writing into a wrong spec).
allow to paste into a non-container (search for a container)
--- a/UIPainter.st Tue Oct 08 17:28:30 2002 +0200
+++ b/UIPainter.st Tue Oct 08 18:00:46 2002 +0200
@@ -2428,10 +2428,10 @@
clipboard isCollection ifTrue:[clipboard notEmpty ifTrue:[sel := clipboard first]]
ifFalse:[sel := clipboard].
- canPaste := (sel isKindOf:UISpecification) and:
- [treeSelection size = 1
- and:[treeSelection first == 1
- or: [self canPasteInto: treeView selectedNode contents view]]]
+ canPaste := (sel isKindOf:UISpecification)
+"/ and:[treeSelection size = 1
+"/ and:[treeSelection first == 1
+"/ or: [self canPasteInto: treeView selectedNode contents view]]]
].
self valueOfCanCut value: canCutOrCopy.
@@ -2819,6 +2819,35 @@
!UIPainter methodsFor:'selection'!
+askForUnsavedModifications
+ |whatToDo|
+
+ self isModified ifFalse:[^ true].
+
+ whatToDo := DialogBox
+ confirmWithCancel:'Accept modifications in section ' , tabSelection printString asBoldText, ' ?'
+ labels:#('Cancel' 'Ignore' 'Accept')
+ default:3.
+ whatToDo isNil ifTrue:[^ false].
+ whatToDo == true ifTrue:[
+ self accept
+ ] ifFalse:[
+ self cancel
+ ].
+
+ ^ true
+!
+
+copySelection
+ self painter copySelection.
+ self updateChannels.
+!
+
+selectionChangeAllowed:newSelection
+ self askForUnsavedModifications ifFalse:[^ false].
+ ^ true
+!
+
tabSelection
"returns the label of the current section in the notebook"
@@ -2828,41 +2857,28 @@
tabSelection:something
"called whenever the section of the notebook has changed"
- |whatToDo|
-
(something isNil or:[tabSelection = something]) ifTrue:[
- ^ self
+ ^ self
].
- self isModified ifTrue:[
- whatToDo := DialogBox
- confirmWithCancel:'Accept modifications in section ' , tabSelection printString asBoldText, '?'
- labels:#('Cancel' 'Ignore' 'Accept')
- default:3.
- whatToDo isNil ifTrue:[^self].
- whatToDo == true ifTrue:[
- self accept
- ] ifFalse:[
- self cancel
- ]
- ].
+ self askForUnsavedModifications ifFalse:[^ self].
tabSelection := something.
self raiseTabView.
self cancel.
-
!
treeSelection
"called whenever the selection of the treeview has changed"
- |view list spec slices size property tabComponent|
-
- self isModified ifTrue:[
- (self confirm:'Accept modifications in section ' , tabSelection printString asBoldText, '?') ifTrue:[
- self accept
- ]
- ].
+ |view spec property|
+
+ self askForUnsavedModifications ifFalse:[^ self].
+"/ self isModified ifTrue:[
+"/ (self confirm:'Accept modifications in section ' , tabSelection printString asBoldText, '?') ifTrue:[
+"/ self accept
+"/ ]
+"/ ].
treeView isCanvasSelected ifTrue:[
spec := treeView canvasSpec.
@@ -2875,10 +2891,20 @@
spec := property spec copy.
]
].
- tabComponent := self componentAt:#noteBook.
+
self setViewInLayoutTool:view spec:spec.
self specTool specification:spec.
+ self updateSlicesForSpec:spec andView:view.
+ self clearModifiedFlag.
+ self updateChannels.
+!
+
+updateSlicesForSpec:spec andView:view
+ |slices size list tabComponent|
+
+ tabComponent := self componentAt:#noteBook.
+
spec notNil ifTrue:[
self helpTool helpKey:(spec activeHelpKey).
slices := spec class slices.
@@ -2916,9 +2942,6 @@
tabComponent enabled:false.
self defaultInfoLabel.
].
- self clearModifiedFlag.
-
- self updateChannels
! !
!UIPainter methodsFor:'settings'!
@@ -3064,6 +3087,8 @@
treeView := TreeView new.
treeView windowSpecClass:(self defaultWindowSpecClass).
+ treeView selectConditionBlock:[:newSelection | self selectionChangeAllowed:newSelection].
+
painterView := StandardSystemView new.
name := name ? UIPainter defaultNameOfCanvas.
@@ -4374,14 +4399,14 @@
"returns true in case that one widget is selected and can change its container
widget to the next element in the list which will have the same container"
- |item prnt|
+ |item prnt container|
( (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]]]
+ or:[(container := prnt childAt:((prnt indexOfChild:item) + 1)) isNil
+ or:[container contents spec class supportsSubComponents not]]]
) ifTrue:[
- ^ false
+ ^ false
].
^ true
!
@@ -4448,13 +4473,21 @@
!UIPainter::TreeView methodsFor:'user interaction'!
+askForSelectionChangeAllowed
+ selectConditionBlock notNil ifTrue:[
+ ^ selectConditionBlock value:nil
+ ].
+ ^ true
+!
+
doChangeHierarchyOf:anItem
|canvas|
anItem isNil ifTrue:[
- ^ self
+ ^ self
].
+ self askForSelectionChangeAllowed ifFalse:[^ self].
self setSelection:nil.
canvas := self canvas.
@@ -4488,17 +4521,19 @@
|item idx size prnt spVw view canvas|
+ self askForSelectionChangeAllowed ifFalse:[^ self].
+
( (item := self selectedNode) isNil
or:[(prnt := item parent) isNil
or:[(size := prnt children size) < 2
or:[(idx := prnt indexOfChild:item) == 0]]]
) ifTrue:[
- ^ self
+ ^ self
].
idx := idx + anIndex.
idx < 1 ifTrue:[idx := size]
- ifFalse:[idx > size ifTrue:[idx := 1]].
+ ifFalse:[idx > size ifTrue:[idx := 1]].
self setSelection:nil.
model remove:item.
@@ -4513,13 +4548,13 @@
"/ input view might by contained in sequence
((size := canvas findInputViewIn:spVw) ~~ 0 and:[idx >= size]) ifTrue:[
- idx := idx + 1
+ idx := idx + 1
].
spVw changeSequenceOrderFor:view to:idx.
spVw specClass isLayoutContainer ifFalse:[
- spVw subViews do:[:v| v raise ].
- canvas inputView raise
+ spVw subViews do:[:v| v raise ].
+ canvas inputView raise
].
canvas showSelection.
self selectNode:item.
--- a/UIPainterView.st Tue Oct 08 17:28:30 2002 +0200
+++ b/UIPainterView.st Tue Oct 08 18:00:46 2002 +0200
@@ -252,6 +252,8 @@
"
|specs coll index oldSelection newSelection treeModel children size nd|
+ treeView askForSelectionChangeAllowed ifFalse:[^ self].
+
coll := self minSetOfSuperViews:(self selection).
coll notNil ifTrue:[
@@ -364,7 +366,19 @@
pasteSpecifications:aSpecificationOrList keepLayout:keepLayout keepPosition:keepPosition at:aPointOrNil
"add the specs to the object view; returns list of pasted components
"
- |paste frame pasteOrigin pasteOffset builder newSel bounds|
+ |paste frame pasteOrigin pasteOffset builder newSel bounds container|
+
+ treeView askForSelectionChangeAllowed ifFalse:[^ nil].
+
+ (self canPasteInto:(self singleSelection)) ifFalse:[
+ (container := self singleSelection) notNil ifTrue:[
+ "/ search up parent list for something we can paste into
+ [container notNil and:[(self canPasteInto:container) not]] whileTrue:[
+ container := container container.
+ ].
+ self selection:container.
+ ].
+ ].
(self canPaste:aSpecificationOrList) ifFalse:[
^ nil
@@ -378,7 +392,7 @@
(frame := self singleSelection) isNil ifTrue:[
frame := self
].
- self selection:nil.
+ self setSelection:nil.
newSel := OrderedCollection new.
builder := UIBuilder new isEditing:true.
@@ -2293,4 +2307,5 @@
version
^ '$Header$'
! !
+
UIPainterView initialize!