diff -r 0d3cc25662d6 -r a0a00603a8b6 UIPainterView.st --- a/UIPainterView.st Mon Mar 03 11:08:15 1997 +0100 +++ b/UIPainterView.st Tue Mar 04 11:21:16 1997 +0100 @@ -19,16 +19,14 @@ ! Object subclass:#ViewProperty - instanceVariableNames:'aspectSelector changeSelector nameIndex view elementClass - labelSelector identifier tabable defaultable menuSelector - initiallyInvisible' + instanceVariableNames:'view spec identifier' classVariableNames:'Identifier' poolDictionaries:'' privateIn:UIPainterView ! UIPainterView::ViewProperty subclass:#GroupProperties - instanceVariableNames:'controlledObjects group groupName' + instanceVariableNames:'controlledObjects group name' classVariableNames:'' poolDictionaries:'' privateIn:UIPainterView @@ -75,35 +73,35 @@ "Modified: 6.9.1995 / 00:46:44 / claus" ! +applicationName + ^ self className +! + +applicationName:aName + self className:aName +! + className ^ className - - "Modified: 5.9.1995 / 18:41:30 / claus" ! -className:aString - className := aString - - "Modified: 5.9.1995 / 18:47:17 / claus" +className:aName + className := aName ! className:aClassName superclassName:aSuperclassName selector:aSelector - className := aClassName. + className := aClassName. superclassName := aSuperclassName. - methodName := aSelector. + methodName := aSelector. ! methodName ^ methodName - - "Modified: 5.9.1995 / 18:41:34 / claus" ! -methodName:aString - methodName := aString - - "Modified: 5.9.1995 / 18:47:27 / claus" +methodName:aName + methodName := aName ! selectNames:aStringOrCollection @@ -137,63 +135,6 @@ ! ! -!UIPainterView ignoredMethodsFor:'code manipulation'! - -changeClass - |box classNameHolder superclassNameHolder| - - classNameHolder := (className ? 'MyClass') asValue. - superclassNameHolder := (superclassName ? 'ApplicationModel') asValue. - - box := DialogBox new. - box addTextLabel:'class:'. - box addInputFieldOn:classNameHolder. - box addTextLabel:'super class:'. - box addInputFieldOn:superclassNameHolder. - box addAbortButton; addOkButton. - - box open. - - box accepted ifTrue:[ - className := classNameHolder value. - superclassName := superclassNameHolder value. - ]. - - - - - - -! - -changeVariables - | box names propList p n newName| - - names := VariableArray new. - propList := VariableArray new. - viewProperties do:[:props | - n := props name. - n notNil ifTrue:[ - names add:n. - propList add:props - ] - ]. - box := BuilderVariablesBox new. - box list:names. - box selectAction:[:selection | - p := propList at:selection - ]. - box okAction:[ - newName := box enterValue. -Transcript showCR:('renamed ' , (p name) , 'to:' , newName). - p name:newName - ]. - box showAtPointer - - - -! ! - !UIPainterView methodsFor:'copy & cut & paste'! copySelection @@ -205,33 +146,44 @@ coll notNil ifTrue:[ self unselect. - specs := self generateSpecFor:coll. + specs := coll collect:[:aView| self fullSpecFor:aView ]. self setSelection:specs ]. + + ! deleteSelection "delete the selection; copy the selection into the cut&paste-buffer and open a transaction " - |text specs newSel| + |text specs coll| - newSel := self minSetOfSuperViews:selection. + coll := self minSetOfSuperViews:selection. - newSel notNil ifTrue:[ + coll notNil ifTrue:[ self unselect. - specs := self generateSpecFor:newSel. - text := self transactionTextFor:newSel. + specs := coll collect:[:aView| self fullSpecFor:aView ]. + text := self transactionTextFor:coll. - undoHistory transaction:#cut text:text do:[self remove:newSel]. - self setSelection:specs + undoHistory transaction:#cut text:text do:[ + coll reverseDo:[:o||p| + (p := self propertyOfView:o) notNil ifTrue:[ + self undoRemove:(p identifier) + ]. + self remove:o + ] + ]. + + self setSelection:specs. + self changed:#tree. ] ! pasteBuffer "add the objects in the paste-buffer to the object view " - |paste builder frame pasteOrigin pasteOffset| + |paste frame pasteOrigin pasteOffset builder| paste := self getSelection. @@ -245,20 +197,16 @@ ]. self unselect. - builder := UIBuilder new. selection := OrderedCollection new. pasteOffset := 0@0. pasteOrigin := self sensor mousePoint. pasteOrigin := device translatePoint:pasteOrigin from:device rootView id to:frame id. + builder := UIBuilder new. paste do:[:aSpec| - |view org| + |view| - builder componentCreationHook:[:aView :aSpecification :aBuilder | - self createdComponent:aView forSpec:aSpecification builder:aBuilder. - ]. - builder applicationClass:(Smalltalk classNamed:className). - view := aSpec buildViewWithLayoutFor:builder in:frame. + view := self addSpec:aSpec builder:builder in:frame. (frame bounds containsPoint:pasteOrigin) ifFalse:[ self moveObject:view to:pasteOffset. @@ -285,57 +233,6 @@ ! ! -!UIPainterView methodsFor:'creating subviews'! - -addProperties:properties for:aView - "set properties to a view and add properties to viewProperties. - In case that properties are nil properties are created - " - |name props| - - (props := properties) isNil ifTrue:[ - props := self propertiesForNewView:aView. - ]. - - viewProperties add:props. - name := props name. - - aView specClass supportsLabel ifTrue:[ - aView label:name - ]. - aView name:name. - ^ props -! - -propertiesForNewView:aView - "generate property for a view and return properties - " - |cls props index| - - cls := aView class. - - props := ViewProperty new. - props view:aView. - props elementClass:cls. - index := self variableIndexForClass:cls. - props nameIndex:index. - props name:(self variableNameForClass:cls index:index). - - ^ props -! - -setupCreatedObject:anObject - "set default properties for a created object - " - |props| - - props := self addProperties:nil for:anObject. - - undoHistory transaction:#create text:(props name) do:[ - self undoCreate:(props identifier). - ]. -! ! - !UIPainterView methodsFor:'drag & drop'! canDrop:anObjectOrCollection @@ -351,30 +248,53 @@ ! ! -!UIPainterView methodsFor:'event handling'! +!UIPainterView methodsFor:'generating output'! + +XXgenerateWindowSpecMethodSource + |spec specArray str code| -keyPress:key x:x y:y - "any key pressed - " - + subViews remove:inputView. + [ + spec := FullSpec fromView:self + ] valueNowOrOnUnwindDo:[ + subViews addFirst:inputView. + ]. + specArray := spec literalArrayEncoding. - key == #Copy ifTrue:[ - ^ self copySelection - ]. + str := WriteStream on:String new. + self prettyPrintSpecArray:specArray on:str indent:5. + + code := Character excla asString + , className , ' class methodsFor:''interface specs''' + , Character excla asString , '\\' - key == #Paste ifTrue:[ - ^ self pasteBuffer - ]. - - super keyPress:key x:x y:y - + , methodName , '\' + , ' "this window spec was automatically generated by the ST/X UIPainter"\\' + , ' "do not manually edit this - the painter/builder may not be able to\' + , ' handle the specification if its corrupted."\\' + , ' "\' + , ' UIPainter new openOnClass:' , className , ' andSelector:#' , methodName , '\' + , ' ' , className , ' new openInterface:#' , methodName , '\' + , ' "\'. - - + methodName = 'windowSpec' ifTrue:[ + code := code , ' "' , className , ' open"\' + ]. + code := code + , '\' + , ' \\' + , ' ^\' + , ' ', str contents + , '\' + , Character excla asString + , ' ' + , Character excla asString + , '\\'. -! ! + ^ code withCRs -!UIPainterView methodsFor:'generating output'! + "Modified: 5.9.1995 / 21:01:35 / claus" +! generateActionMethodFor:aspect spec:protoSpec inClass:targetClass ^ ('!!' , targetClass name , ' methodsFor:''actions''!!\\' , @@ -403,21 +323,17 @@ generateAspectMethods |cls code| + code := ''. + className isNil ifTrue:[ self warn:'set the class first'. - ^ '' + ^ code ]. -"/ (cls := Smalltalk at:className asSymbol) isNil ifTrue:[ -"/ self warn:'create the class first'. -"/ ^ '' -"/ ]. - - code := ''. viewProperties do:[:aProp | |modelSelector menuSelector protoSpec thisCode| - (modelSelector := aProp aspectSelector) notNil ifTrue:[ + (modelSelector := aProp model) notNil ifTrue:[ (cls implements:modelSelector asSymbol) ifFalse:[ protoSpec := aProp view specClass basicNew. "/ kludge .. @@ -430,7 +346,7 @@ ]. ]. - (menuSelector := aProp menuSelector) notNil ifTrue:[ + (menuSelector := aProp menu) notNil ifTrue:[ (cls implements:menuSelector asSymbol) ifFalse:[ protoSpec := aProp view specClass basicNew. "/ kludge .. @@ -505,7 +421,7 @@ objects := p at:#controlledObjects ifAbsent:[nil]. objects notNil ifTrue:[ objects do:[:controlledObject | - c := c , name , ' add:' , (self variableNameOf:controlledObject) , '.\' + c := c , name , ' add:' , (self uniqueNameOf:controlledObject) , '.\' ] ]. @@ -545,7 +461,7 @@ p := self propertyOfView:aView. name := p at:#variableName. c := ' ' , name , ' := ' , - (aView class name) , ' in:' , (self variableNameOf:(aView superView)) , '.\'. + (aView class name) , ' in:' , (self uniqueNameOf:(aView superView)) , '.\'. " origin:(...) extent:(...)" @@ -647,44 +563,18 @@ !UIPainterView methodsFor:'generating output'! -generateSpecFor:something - "generate a spec for a view or collection of views - " - |spec views| - - something notNil ifTrue:[ - something isCollection ifTrue:[views := something] - ifFalse:[views := Array with:something]. +generateWindowSpecMethodSource + |t s spec specArray str code| - spec := views collect:[:aView||topSpec| - aView specClass isNil ifTrue:[ - ^ nil - ]. + specArray := OrderedCollection new. - topSpec := aView specClass - fromView:aView - callBack:[:newSpec :view | self stuffPropertiesFrom:view intoSpec:newSpec]. - topSpec + self subViews do:[:aView| + aView ~~ inputView ifTrue:[ + specArray add:(self fullSpecFor:aView) ] ]. - ^ spec - - - - - - -! - -generateWindowSpecMethodSource - |spec specArray str code| - - subViews remove:inputView. - [ - spec := FullSpec fromView:self callBack:[:newSpec :view | self stuffPropertiesFrom:view intoSpec:newSpec]. - ] valueNowOrOnUnwindDo:[ - subViews addFirst:inputView. - ]. + spec := FullSpec new. + spec fromBuilder:self components:(SpecCollection new collection:specArray). specArray := spec literalArrayEncoding. str := WriteStream on:String new. @@ -830,55 +720,6 @@ viewProperties do:[:p| p storeOn:aStream] ! -stuffPropertiesFrom:view intoSpec:newSpec - "stuff any additional information (held in the properties) into the spec - which was just created from view" - - |props aspectSelector changeSelector labelSelector name tabable defaultable - menuSelector initiallyInvisible| - - props := self propertyOfView:view. - props isNil ifTrue:[^ self]. - - (aspectSelector := props aspectSelector) notNil ifTrue:[ - newSpec model:aspectSelector - ]. - (changeSelector := props changeSelector) notNil ifTrue:[ - newSpec change:changeSelector - ]. - (menuSelector := props menuSelector) notNil ifTrue:[ - newSpec menu:menuSelector - ]. - (labelSelector := props labelSelector) notNil ifTrue:[ - newSpec label:labelSelector - ]. - (tabable := props tabable) == true ifTrue:[ - newSpec tabable:tabable - ]. - (defaultable := props defaultable) notNil ifTrue:[ - newSpec defaultable:defaultable - ]. - (initiallyInvisible := props initiallyInvisible) notNil ifTrue:[ - newSpec initiallyInvisible:initiallyInvisible - ]. - (name := props name) notNil ifTrue:[ - newSpec name:name - ]. - -! ! - -!UIPainterView ignoredMethodsFor:'generating output'! - -subviewVariableNames - |names| - - names := ''. - viewProperties do:[:p| names := names , ' ' , (p name)]. - ^ names -! ! - -!UIPainterView methodsFor:'generating output'! - subviewsOf:aView do:aBlock |subs v| @@ -899,7 +740,7 @@ !UIPainterView methodsFor:'group manipulations'! groupEnterFields - |props name index group objects| + |props group objects| selection isNil ifTrue:[^ self]. self selectionDo:[:aView | @@ -910,14 +751,11 @@ ]. self withSelectionHiddenDo:[ group := EnterFieldGroup new. - props := GroupProperties new. - props elementClass:EnterFieldGroup. + name := self uniqueNameFor:EnterFieldGroup. props group:group. - index := self variableIndexForClass:EnterFieldGroup. - props nameIndex:index. - name := self variableNameForClass:EnterFieldGroup index:index. props name:name. + group groupID:name asSymbol. objects := OrderedCollection new. props controlledObjects:objects. viewProperties add:props. @@ -932,7 +770,7 @@ ! groupRadioButtons - |props name index group objects| + |props name group objects| selection isNil ifTrue:[^ self]. self selectionDo:[:aView | @@ -943,13 +781,9 @@ ]. self withSelectionHiddenDo:[ group := RadioButtonGroup new. - props := GroupProperties new. - props elementClass:RadioButtonGroup. + name := self uniqueNameFor:RadioButtonGroup. props group:group. - index := self variableIndexForClass:RadioButtonGroup. - props nameIndex:index. - name := self variableNameForClass:RadioButtonGroup index:index. props name:name. group groupID:name asSymbol. objects := OrderedCollection new. @@ -981,154 +815,42 @@ HandCursor := Cursor leftHand. "Modified: 5.9.1995 / 19:58:06 / claus" -! ! - -!UIPainterView methodsFor:'interface to Builder'! - -addOutletDefinitionFor:outletSymbol type:type value:outletValue for:aView - |outletProps selectorProps viewProps| - - viewProps := self propertyOfView:aView. -"/ outletProps := viewProps at:#outlets ifAbsent:[nil]. -"/ outletProps isNil ifTrue:[ -"/ outletProps := Dictionary new. -"/ viewProps at:#outlets put:outletProps -"/ ]. -"/ selectorProps := outletProps at:outletSymbol ifAbsent:[nil]. -"/ selectorProps isNil ifTrue:[ -"/ selectorProps := Dictionary new. -"/ outletProps at:outletSymbol put:selectorProps -"/ ]. -"/ -"/ selectorProps at:#selector put:outletSymbol. -"/ selectorProps at:#type put:type. -"/ selectorProps at:#value put:outletValue - -! - -addSpec:specOrSpecArray - |spec builder| - - spec := UISpecification from:specOrSpecArray. - - builder := UIBuilder new. - builder componentCreationHook:[:view :spec :aBuilder | - self createdComponent:view forSpec:spec builder:aBuilder - ]. - builder applicationClass:(Smalltalk classNamed:className). - spec setupView:self for:builder. - - self realizeAllSubViews. - inputView raise. - -"/ viewProperties := OrderedCollection new. -"/ self generatePropertiesFor:(self subViews select:[:v | v ~~ inputView]). - - self changed:#tree. - - - "Modified: 5.9.1995 / 23:36:55 / claus" -! - -applicationName - ^ className -! - -aspectAt:aSymbol - self halt. - ^ nil - - "Modified: 6.9.1995 / 00:45:35 / claus" ! -createdComponent:newView forSpec:aSpec builder:aBuilder - "callBack from UISpec view building" - - |props| +initializeCreatedObject:anObject + "set default properties for a created object + " + |props spec cls| - props := self propertiesForNewView:newView. + cls := anObject class. + spec := anObject specClass fromView:anObject. + props := ViewProperty new. + props view:anObject. + props spec:spec. + props name:(self uniqueNameFor:cls). + viewProperties add:props. - aSpec name notNil ifTrue:[ - (self propertyOfName:(aSpec name)) isNil ifTrue:[ - props name:aSpec name - ] + ((anObject respondsTo:#label:) and:[(spec respondsTo:#label:)]) ifTrue:[ + anObject label:(props name). + spec label:(props name) ]. - props labelSelector:(aSpec labelSelector). - props aspectSelector:(aSpec modelSelector). - props menuSelector:(aSpec menuSelector). - props tabable:(aSpec tabable). - props defaultable:(aSpec defaultable). - props initiallyInvisible:(aSpec initiallyInvisible). - - viewProperties add:props. -! - -generatePropertiesFor:aCollectionOfViews - - "/ done as two loops, to get bread-first naming - - aCollectionOfViews do:[:aView| - |props| - - props := self propertiesForNewView:aView. - viewProperties add:props. - aView name:(props name). - - aView geometryLayout isNil ifTrue:[ - aView geometryLayout:(aView bounds asLayout). - ] + undoHistory transaction:#create text:(props name) do:[ + self undoCreate:(props identifier). ]. - - aCollectionOfViews do:[:aView | - |subs| - - subs := aView subViews. - subs notNil ifTrue:[ - self generatePropertiesFor:subs - ] - ]. - -! - -inspectAttributes - |p| - - self singleSelectionDo:[:aView | - p := self propertyOfView:aView. - p inspect - ] -! - -inspectSpec - |s| - - self singleSelectionDo:[:aView | - s := self generateSpecFor:aView. - s first inspect - ] ! setupFromSpec:specOrSpecArray - self removeAll. - self addSpec:specOrSpecArray -! - -showFontPanel - |action| + |spec builder| - fontPanel isNil ifTrue:[ - fontPanel := FontPanel new - ]. - - selection notNil ifTrue:[ - action := [:family :face :style :size | - self changeFontFamily:family face:face - style:style size:size - ]. - fontPanel action:action. - fontPanel showAtPointer - ] + self removeAll. + spec := UISpecification from:specOrSpecArray. + builder := UIBuilder new. + spec window setupView:self topView for:builder. + self addSpec:(spec component) builder:builder in:self. + self realizeAllSubViews. + inputView raise. + self changed:#tree. ! ! !UIPainterView methodsFor:'menus'! @@ -1205,6 +927,23 @@ ! +showFontPanel + |action| + + fontPanel isNil ifTrue:[ + fontPanel := FontPanel new + ]. + + selection notNil ifTrue:[ + action := [:family :face :style :size | + self changeFontFamily:family face:face + style:style size:size + ]. + fontPanel action:action. + fontPanel showAtPointer + ] +! + subMenuAlign "returns submenu alignment " @@ -1354,79 +1093,26 @@ ] "Modified: 5.9.1995 / 12:13:27 / claus" -! - -changeVariableNameOf:aView to:newName - |prop| - - prop := self propertyOf:aView. - - prop isNil ifTrue:[ - ^ self error:'no such view' - ]. - - ((aView respondsTo:#label:) and:[aView label = prop name]) ifTrue:[ - self withSelectionHiddenDo:[ - |layout| - layout := aView geometryLayout copy. - aView label:newName. - aView geometryLayout:layout. - ] - ]. - - prop name:newName. - aView name:newName. - self changed:#widgetName - - - -! - -variableIndexForClass:aClass - |max| - - max := 0. - - viewProperties do:[:p| - p elementClass == aClass ifTrue:[ - max := max max:(p nameIndex) - ] - ]. - ^ max + 1 - -! - -variableNameForClass:aClass index:index - |n| - - n := (aClass name) , index printString. - n at:1 put:(n at:1) asLowercase. - ^ n - -! - -variableNameOf:aView - |prop| - - aView notNil ifTrue:[ - prop := self propertyOf:aView - ]. - - prop notNil ifTrue:[^ prop name] - ifFalse:[^ 'self'] - ! ! !UIPainterView methodsFor:'removing components'! -remove:something - "remove something, anObject or a collection of objects from the contents do redraw +remove:anObject + "remove anObject from the contents do redraw " - self forEach:something do:[:anObject | - self removeObject:anObject + |props| + + anObject notNil ifTrue:[ + (anObject subViews notNil) ifTrue:[ + anObject subViews copy do:[:sub | + self remove:sub + ] + ]. + (props := self propertyOfView:anObject) notNil ifTrue:[ + viewProperties remove:props ifAbsent:nil + ]. + anObject destroy ] - - ! removeAll @@ -1438,46 +1124,12 @@ subViews notNil ifTrue:[ subViews copy do:[:sub | sub ~~ inputView ifTrue:[ - self removeTreeFrom:sub + self remove:sub ] ] ]. undoHistory reinitialize. self changed:#tree -! - -removeObject:anObject - "remove the argument, anObject - " - |spec prop| - - undoHistory isTransactionOpen ifTrue:[ - (prop := self propertyOfView:anObject) notNil ifTrue:[ - self undoRemove:(prop identifier) - ] - ]. - self removeTreeFrom:anObject. - self changed:#tree -! - -removeTreeFrom:anObject - "remove the argument, anObject and all of its subviews - " - |props| - - anObject notNil ifTrue:[ - (anObject subViews notNil) ifTrue:[ - anObject subViews copy do:[:sub | - self removeTreeFrom:sub - ] - ]. - props := self propertyOf:anObject. - - props notNil ifTrue:[ - viewProperties remove:props ifAbsent:nil - ]. - anObject destroy - ] ! ! !UIPainterView methodsFor:'searching'! @@ -1508,6 +1160,76 @@ prop notNil ifTrue:[^ prop view] ifFalse:[^ nil] +! + +propertyOfGroup:aGroup + "returns property assigned to group + " + ^ viewProperties detect:[:p| p group == aGroup] ifNone:nil +! + +propertyOfIdentifier:anId + "returns property assigned to unique identifier + " + anId notNil ifTrue:[ + ^ viewProperties detect:[:p| p identifier == anId] ifNone:nil. + ]. + ^ nil +! + +propertyOfName:aString + "returns property assigned to name + " + aString = 'self' ifFalse:[ + ^ viewProperties detect:[:p| p name = aString] ifNone:nil + ]. + ^ nil +! + +propertyOfView:aView + "returns property assigned to view + " + (aView isNil or:[aView == self]) ifFalse:[ + ^ viewProperties detect:[:p| p view == aView] ifNone:nil + ]. + ^ nil +! + +uniqueNameFor:aClass + "generate and return an unique name for a class + " + |next name size| + + next := 0. + name := aClass name asString copy. + size := name size + 1. + + name at:1 put:(name at:1) asLowercase. + + viewProperties do:[:p||n| + n := p name. + + (n size >= size and:[n startsWith:name]) ifTrue:[ + next := next max:(p extractNumberStartingAt:size) + ] + ]. + next := next + 1. + name := name, next printString. + ^ name + + + +! + +uniqueNameOf:aView + |prop| + + aView notNil ifTrue:[ + prop := self propertyOfView:aView + ]. + + prop notNil ifTrue:[^ prop name] + ifFalse:[^ 'self'] ! ! !UIPainterView methodsFor:'selection'! @@ -1515,7 +1237,7 @@ addTreeFrom:aView to:aCollection "add aView and contained subcomponents to collection " - (self propertyOf:aView) notNil ifTrue:[ + (self propertyOfView:aView) notNil ifTrue:[ aCollection add:aView. (aView subViews notNil) ifTrue:[ @@ -1555,13 +1277,59 @@ ] ! ! -!UIPainterView methodsFor:'seraching property'! +!UIPainterView methodsFor:'specification'! + +addSpec:aSpecification builder:aBuilder in:aFrame + "build view and subviews from aSpecification into a frame. The top view + is returned. The contained components of a spec are set to nil + " + aBuilder applicationClass:(Smalltalk classNamed:className). + + aBuilder componentCreationHook:[:aView :aSpec :aBdr||sv p s| + p := ViewProperty new. + s := aSpec copy. + p spec:s. + p view:aView. + + s class supportsSubComponents ifTrue:[ + s component:nil + ]. + + (self propertyOfName:(s name)) notNil ifTrue:[ + s name:(self uniqueNameFor:(aView class)) + ]. + viewProperties add:p + ]. + + ^ aSpecification buildViewWithLayoutFor:aBuilder in:aFrame. -propertyOf:something - "returns property assigned to group or view +! + +fullSpecFor:anObject + "generate a full spec for an object " - ^ viewProperties detect:[:p| (p view == something or:[p group == something])] - ifNone:nil + |mySpec subSpecs| + + mySpec := self specFor:anObject. + + (mySpec notNil and:[mySpec class supportsSubComponents]) ifTrue:[ + (anObject subViews notNil) ifTrue:[ + anObject subViews do:[:aSubView||spec| + spec := self fullSpecFor:aSubView. + spec notNil ifTrue:[ + subSpecs isNil ifTrue:[ + subSpecs := OrderedCollection new + ]. + subSpecs add:spec. + ]. + ]. + subSpecs notNil ifTrue:[ + mySpec component:(SpecCollection new collection:subSpecs) + ] + ] + ]. + ^ mySpec + @@ -1569,37 +1337,67 @@ ! -propertyOfGroup:aGroup - "returns property assigned to group +specFor:anObject + "returns spec assigned to an object " - ^ viewProperties detect:[:p| p group == aGroup] ifNone:nil -! + |prop spec| -propertyOfIdentifier:anId - "returns property assigned to unique identifier - " - anId notNil ifTrue:[ - ^ viewProperties detect:[:p| p identifier == anId] ifNone:nil. + (prop := self propertyOfView:anObject) notNil ifTrue:[ + spec := prop spec copy. + spec layoutFromView:anObject ]. - ^ nil + ^ spec + + + ! -propertyOfName:aString - "returns property assigned to name +updateFromSpec:aSpec + "update current selected view from specification " - aString = 'self' ifFalse:[ - ^ viewProperties detect:[:p| p name = aString] ifNone:nil + |props name builder v| + + self singleSelection notNil ifTrue:[ + self withSelectionHiddenDo:[ + self transaction:#specification selectionDo:[:aView| + builder := UIBuilder new. + props := self propertyOfView:aView. + name := aSpec name. + + self undoSpecModify:(props identifier). + + name = (aView name) ifFalse:[ + name notNil ifTrue:[ + name := name withoutSeparators. + + (name isEmpty or:[(self propertyOfName:name) notNil]) ifTrue:[ + name := nil + ] + ]. + name isNil ifTrue:[ + aSpec name:(aView name). + ] + ]. + + aSpec needsRebuildForAttributes ifTrue:[ + v := aSpec buildViewWithLayoutFor:builder in:aView superView. + v realize. + aView destroy. + device sync. device flush. + aView becomeSameAs:v. + inputView raise. + ] ifFalse:[ + aSpec setAttributesIn:aView with:builder. + self elementChangedSize:aView. + ]. + + props spec:(aSpec copy). + ] + ]. + self changed:#tree ]. - ^ nil -! -propertyOfView:aView - "returns property assigned to view - " - (aView isNil or:[aView == self]) ifFalse:[ - ^ viewProperties detect:[:p| p view == aView] ifNone:nil - ]. - ^ nil + "Modified: 1.3.1997 / 01:39:53 / cg" ! ! !UIPainterView methodsFor:'testing'! @@ -1693,12 +1491,8 @@ undoCreate:aViewId "undo method when creating or pasting an object " - |view| - undoHistory addUndoBlock:[ - (view := self findViewWithId:aViewId) notNil ifTrue:[ - self removeObject:view - ] + self remove:(self findViewWithId:aViewId) ] ! @@ -1708,8 +1502,6 @@ " |view layout extent| - undoHistory isTransactionOpen ifFalse:[^ self]. - (view := self findViewWithId:aViewId) notNil ifTrue:[ (layout := view geometryLayout copy) isNil ifTrue:[ extent := view extent copy @@ -1740,40 +1532,30 @@ undoRemove:aViewId "undo method when removing an object " - |view prop spec parentId| - - undoHistory isTransactionOpen ifFalse:[^ self]. - - (view := self findViewWithId:aViewId) notNil ifTrue:[ - spec := (self generateSpecFor:view) first. - view := view superView. + |frame prop spec parentId| - (self canPasteInto:view) ifTrue:[ - (prop := self propertyOfView:view) notNil ifTrue:[ - parentId := prop identifier - ] - ]. - view := nil. - prop := nil. + frame := self findViewWithId:aViewId. + spec := self fullSpecFor:frame. + frame := frame superView. - undoHistory addUndoBlock:[ - |builder| - - builder := UIBuilder new. - view := self findViewWithId:parentId. + (self canPasteInto:frame) ifTrue:[ + (prop := self propertyOfView:frame) notNil ifTrue:[ + parentId := prop identifier + ] + ]. + frame := nil. + prop := nil. - view isNil ifTrue:[ - view := self - ]. + undoHistory addUndoBlock:[ + |view| - builder componentCreationHook:[:aView :aSpec :aBuilder | - self createdComponent:aView forSpec:aSpec builder:aBuilder. - ]. - - builder applicationClass:(Smalltalk classNamed:className). - (spec buildViewWithLayoutFor:builder in:view) realize. - inputView raise. + frame := self findViewWithId:parentId. + frame isNil ifTrue:[ + frame := self ]. + view := self addSpec:spec builder:(UIBuilder new) in:frame. + view realize. + inputView raise. ] ! @@ -1782,10 +1564,8 @@ " |builder view spec v| - undoHistory isTransactionOpen ifFalse:[^ self]. - (view := self findViewWithId:aViewId) notNil ifTrue:[ - spec := (self generateSpecFor:view) first. + spec := self specFor:view. view := nil. undoHistory addUndoBlock:[ @@ -1808,62 +1588,6 @@ ! ! -!UIPainterView methodsFor:'update from Specification'! - -updateFromSpec:aSpec - "update current selected view from specification - " - |props name builder v| - - self singleSelection notNil ifTrue:[ - self withSelectionHiddenDo:[ - self transaction:#specification selectionDo:[:aView| - builder := UIBuilder new. - props := self propertyOfView:aView. - name := aSpec name. - - self undoSpecModify:(props identifier). - - name = (aView name) ifFalse:[ - name notNil ifTrue:[ - name := name withoutSeparators. - - (name isEmpty or:[(self propertyOfName:name) notNil]) ifTrue:[ - name := nil - ] - ]. - name isNil ifTrue:[ - aSpec name:(aView name). - ] - ]. - - aSpec needsRebuildForAttributes ifTrue:[ - v := aSpec buildViewWithLayoutFor:builder in:aView superView. - v realize. - aView destroy. - device sync. device flush. - aView becomeSameAs:v. - inputView raise. - ] ifFalse:[ - aSpec setAttributesIn:aView with:builder. - self elementChangedSize:aView. - ]. - - props tabable:aSpec tabable. - props defaultable:aSpec defaultable. - props initiallyInvisible:aSpec initiallyInvisible. - props aspectSelector:aSpec modelSelector. - props changeSelector:aSpec changeSelector. - props labelSelector:aSpec labelSelector. - props menuSelector:aSpec menuSelector. - ] - ]. - self changed:#tree - ]. - - "Modified: 1.3.1997 / 01:39:53 / cg" -! ! - !UIPainterView::ViewProperty class methodsFor:'documentation'! version @@ -1881,48 +1605,6 @@ !UIPainterView::ViewProperty methodsFor:'accessing'! -aspectSelector - "return the value of the instance variable 'aspectSelector' (automatically generated)" - - ^ aspectSelector -! - -aspectSelector:something - "set the value of the instance variable 'aspectSelector' (automatically generated)" - - aspectSelector := something. -! - -changeSelector - "return the value of the instance variable 'changeSelector' (automatically generated)" - - ^ changeSelector! - -changeSelector:something - "set the value of the instance variable 'changeSelector' (automatically generated)" - - changeSelector := something.! - -defaultable - "return the value of the instance variable 'defaultable' (automatically generated)" - - ^ defaultable! - -defaultable:something - "set the value of the instance variable 'defaultable' (automatically generated)" - - defaultable := something.! - -elementClass - "return the value of the instance variable 'elementClass' (automatically generated)" - - ^ elementClass! - -elementClass:something - "set the value of the instance variable 'elementClass' (automatically generated)" - - elementClass := something.! - group ^ nil ! @@ -1933,67 +1615,15 @@ ^ identifier ! -initiallyInvisible - "return the value of the instance variable 'initiallyInvisible' (automatically generated)" - - ^ initiallyInvisible! - -initiallyInvisible:something - "set the value of the instance variable 'initiallyInvisible' (automatically generated)" - - initiallyInvisible := something.! - -labelSelector - "return the value of the instance variable 'labelSelector' (automatically generated)" - - ^ labelSelector! +spec + "return the value of the instance variable 'spec' (automatically generated)" -labelSelector:something - "set the value of the instance variable 'labelSelector' (automatically generated)" - - labelSelector := something.! - -menuSelector - "return the value of the instance variable 'menuSelector' (automatically generated)" - - ^ menuSelector! - -menuSelector:something - "set the value of the instance variable 'menuSelector' (automatically generated)" - - menuSelector := something.! + ^ spec! -name - "return the value of the instance variable 'name' (automatically generated)" - - ^ view name -! - -name:something - "set the value of the instance variable 'name' (automatically generated)" - - view name:something -! - -nameIndex - "return the value of the instance variable 'nameIndex' (automatically generated)" +spec:something + "set the value of the instance variable 'spec' (automatically generated)" - ^ nameIndex! - -nameIndex:something - "set the value of the instance variable 'nameIndex' (automatically generated)" - - nameIndex := something.! - -tabable - "return the value of the instance variable 'tabable' (automatically generated)" - - ^ tabable! - -tabable:something - "set the value of the instance variable 'tabable' (automatically generated)" - - tabable := something.! + spec := something.! view "return the value of the instance variable 'view' (automatically generated)" @@ -2012,6 +1642,48 @@ identifier := Identifier ! ! +!UIPainterView::ViewProperty methodsFor:'misc'! + +extractNumberStartingAt:anIndex + "return the number from the name starting at anIndex or 0. + " + |val| + + val := 0. + + self name from:anIndex do:[:c| + c isDigit ifTrue:[val := val * 10 + c digitValue] + ifFalse:[^ 0] + ]. + ^ val + +! ! + +!UIPainterView::ViewProperty methodsFor:'spec messages'! + +doesNotUnderstand:aMessage + spec notNil ifTrue:[ + (spec respondsTo:(aMessage selector)) ifTrue:[^ aMessage sendTo:spec] + ]. + ^ nil +! + +layout + spec layout +! + +layout:aLayout + spec layout:aLayout +! + +name + ^ spec name +! + +name:aName + spec name:aName +! ! + !UIPainterView::GroupProperties methodsFor:'accessing'! controlledObjects @@ -2025,21 +1697,27 @@ controlledObjects := something.! group - "return the value of the instance variable 'group' (automatically generated)" - - ^ group! + "return the value of the instance variable 'group' + " + ^ group +! group:something - "set the value of the instance variable 'group' (automatically generated)" - - group := something.! + "set the value of the instance variable 'group' + " + group := something. +! name - ^ groupName + "return the value of the group name + " + ^ name ! name:aName - groupName := aName + "set the value of the group name + " + name := aName ! ! !UIPainterView class methodsFor:'documentation'!