# HG changeset patch # User ca # Date 870353916 -7200 # Node ID 99de6af43afa514173efb99b22a5aa867d09f4ee # Parent ca85216907a452c3a2c8d90550c2d99e403822a1 confirm/cancel changes before switching a section or widget diff -r ca85216907a4 -r 99de6af43afa UIPainter.st --- a/UIPainter.st Thu Jul 31 14:31:07 1997 +0200 +++ b/UIPainter.st Thu Jul 31 14:58:36 1997 +0200 @@ -1222,7 +1222,7 @@ cancel "cancel all changes and read back attributes from current view " - self modifiedChannel value ifTrue:[ + self isModified ifTrue:[ specTool specification:(self painter specForSelection). layoutTool layoutView:(layoutTool layoutView). self modifiedChannel value:false. @@ -1463,73 +1463,33 @@ !UIPainter methodsFor:'change & update'! layoutChanged - self modifiedChannel value ifFalse:[ + self isModified ifFalse:[ layoutTool update. self modifiedChannel value:false ] ! -treeViewChanged - "property or selection in the treeView changed +propertyChanged + "property changed " - |oldSelection view slices list spec props size nameOfSpec| - - props := treeView propertySelected. - oldSelection := tabSelection. - tabSelection := nil. - - self hasValidSelection value:(treeView hasValidSelection). - self canStepIn value:(treeView canStepIn). - self canStepOut value:(treeView canStepOut). - - props isNil ifFalse:[ - self hasSingleSelection value:true. - view := props view. - spec := props spec copy. - - layoutTool layoutView == view ifFalse:[ - slices := spec class slices. - size := slices size + 1. - list := Array new:size. - slices keysAndValuesDo:[:i :s|list at:i put:(s first asString)]. - list at:size put:(layoutTool class label). - (self tabList) value:list. - ] ifTrue:[ - list := self tabList value - ]. - (list findFirst:[:n| n = oldSelection ]) ~~ 0 ifTrue:[ - tabSelection := oldSelection - ] ifFalse:[ - tabSelection := list first - ]. - nameOfSpec := spec class name. - ] ifTrue:[ - self hasSingleSelection value:false. - nameOfSpec := '' - ]. - - self showHelp:nameOfSpec for:nil. - - layoutTool layoutView:view. - specTool specification:spec. - - tabSelection notNil ifTrue:[ - self isLayoutToolSelected ifTrue:[ - (self noteBookView subViews at:1) raise - ] ifFalse:[ - specTool selection:tabSelection. - (self noteBookView subViews at:2) raise + |p| + + (p := treeView propertySelected) notNil ifTrue:[ + specTool specification:(p spec copy). + layoutTool layoutView:(p view). + self modifiedChannel value:false + ] ifFalse:[ + layoutTool layoutView notNil ifTrue:[ + self modifiedChannel value:false. + self treeSelection ] - ]. - - (builder componentAt:#noteBook) setSelection:tabSelection. - self modifiedChannel value:false. + ] ! update:something with:aParameter from:someObject someObject == treeView model ifTrue:[ - something == #selection ifTrue:[self treeViewChanged]. + something == #selection ifTrue:[self treeSelection]. ^ self ]. @@ -1631,6 +1591,12 @@ ^ tabSelection = layoutTool class label ! +isModified + "returns true if current spec. is modified + " + ^ self modifiedChannel value +! + isPainterEnabled ^ self painter enabled ! ! @@ -1638,23 +1604,100 @@ !UIPainter methodsFor:'selection'! tabSelection + "returns current name of section + " ^ tabSelection ! tabSelection:something + "section changed + " |raiseViewIdx| - something notNil ifTrue:[ - raiseViewIdx := 1. - tabSelection := something. - - self isLayoutToolSelected ifFalse:[ + (something isNil or:[tabSelection = something]) ifTrue:[ + ^ self + ]. + + self isModified ifTrue:[ + (self confirm:'accept change made in ' , tabSelection printString , ' section ?') ifFalse:[ + ^ self + ]. + self accept + ]. + + raiseViewIdx := 1. + tabSelection := something. + + self isLayoutToolSelected ifFalse:[ + specTool selection:tabSelection. + raiseViewIdx := 2 + ]. + (self noteBookView subViews at:raiseViewIdx) raise. + self cancel. +! + +treeSelection + "called whenever tree-selection changed + " + |oldSelection view slices list spec props size nameOfSpec| + + self isModified ifTrue:[ + (self confirm:'accept change made in ' , tabSelection printString , ' section ?') ifTrue:[ + self accept + ] + ]. + + props := treeView propertySelected. + oldSelection := tabSelection. + tabSelection := nil. + + self hasValidSelection value:(treeView hasValidSelection). + self canStepIn value:(treeView canStepIn). + self canStepOut value:(treeView canStepOut). + + props isNil ifFalse:[ + self hasSingleSelection value:true. + view := props view. + spec := props spec copy. + + layoutTool layoutView == view ifFalse:[ + slices := spec class slices. + size := slices size + 1. + list := Array new:size. + slices keysAndValuesDo:[:i :s|list at:i put:(s first asString)]. + list at:size put:(layoutTool class label). + (self tabList) value:list. + ] ifTrue:[ + list := self tabList value + ]. + (list findFirst:[:n| n = oldSelection ]) ~~ 0 ifTrue:[ + tabSelection := oldSelection + ] ifFalse:[ + tabSelection := list first + ]. + nameOfSpec := spec class name. + ] ifTrue:[ + self hasSingleSelection value:false. + nameOfSpec := '' + ]. + + self showHelp:nameOfSpec for:nil. + + layoutTool layoutView:view. + specTool specification:spec. + + tabSelection notNil ifTrue:[ + self isLayoutToolSelected ifTrue:[ + (self noteBookView subViews at:1) raise + ] ifFalse:[ specTool selection:tabSelection. - raiseViewIdx := 2 - ]. - (self noteBookView subViews at:raiseViewIdx) raise. - self cancel. - ] + (self noteBookView subViews at:2) raise + ] + ]. + + (builder componentAt:#noteBook) setSelection:tabSelection. + self modifiedChannel value:false. + ! ! !UIPainter methodsFor:'startup / release'! @@ -2473,7 +2516,7 @@ ]. self selectedNode == item ifTrue:[ "/ inform application - self application treeViewChanged + self application propertyChanged ] ].