--- a/UIPainter.st Thu Mar 12 23:02:28 1998 +0100
+++ b/UIPainter.st Thu Mar 12 23:05:33 1998 +0100
@@ -14,7 +14,7 @@
ToolApplicationModel subclass:#UIPainter
instanceVariableNames:'treeView selectionPanel tabSelection specClass specSelector
specSuperclass aspects layoutCanvas helpCanvas specCanvas
- transcript'
+ transcript modified'
classVariableNames:''
poolDictionaries:''
category:'Interface-UIPainter'
@@ -267,6 +267,7 @@
'Starts current application on current window spec.'
)
+
! !
!UIPainter class methodsFor:'helpers'!
@@ -1150,7 +1151,7 @@
#label: 'Paste With Layout'
#value: #pasteWithLayout
#activeHelpKey: #pasteWithLayout
- #enabled: #canKeepLayoutInSelection
+ #enabled: #valueOfCanPasteWithKeepingLayout
)
#(#MenuItem
#label: '-'
@@ -1363,11 +1364,11 @@
#labelImage: #(#ResourceRetriever nil #copyIcon)
)
#(#MenuItem
- #label: 'Paste'
+ #label: 'Paste With Layout'
#isButton: true
- #value: #pasteBuffer
+ #value: #pasteWithLayout
#activeHelpKey: #editPaste
- #enabled: #valueOfCanPaste
+ #enabled: #valueOfCanPasteWithKeepingLayout
#labelImage: #(#ResourceRetriever nil #pasteIcon)
)
#(#MenuItem
@@ -1617,8 +1618,9 @@
] ifFalse:[
self painter updateFromSpec:spec.
]
- ].
+ ].
self modifiedChannel value:false.
+ modified := true.
!
addWidget: aSpecClass
@@ -1670,6 +1672,7 @@
view columnDescriptors:(spec columns)
].
self modifiedChannel value:false.
+ modified := false
]
!
@@ -1867,6 +1870,18 @@
"returns the selection tree view which holds all widget identifiers
"
^ treeView
+!
+
+valueOfCanPasteWithKeepingLayout
+
+ |holder|
+ (holder := builder bindingAt:#valueOfCanPasteWithKeepingLayout) isNil ifTrue:[
+ builder aspectAt:#valueOfCanPasteWithKeepingLayout put:(holder := false asValue).
+ ].
+ ^ holder
+
+
+
! !
!UIPainter methodsFor:'building editors'!
@@ -1898,7 +1913,7 @@
openEditMenu
"opens a menu editor on current widget
"
- |cls aspect editor|
+ |cls selectorOrMenu editor selectedSpec|
cls := self resolveName:specClass.
@@ -1907,29 +1922,30 @@
].
cls notNil ifTrue:[
- (aspect := self specTool specification menuSelector) notNil ifTrue:[
- aspect := aspect asSymbol
+ (selectorOrMenu := self specTool specification menuSelector) notNil ifTrue:[
+ selectorOrMenu := selectorOrMenu asSymbol
] ifFalse:[
"/ cg: q&d hack ...
- aspect := treeView propertySelected.
- aspect notNil ifTrue:[
+ (selectedSpec := treeView propertySelected) notNil ifTrue:[
Object errorSignal handle:[:ex |
- aspect := nil.
+ selectorOrMenu := nil.
] do:[
- aspect := aspect view asMenu.
+ selectorOrMenu := selectedSpec view asMenu.
]
].
].
-
+
editor := MenuEditor new.
editor masterApplication:self.
editor specClass: cls.
- editor useHelpTool: self helpTool.
- editor openModalOnClass:cls andSelector:aspect.
+ editor useHelpTool: self helpTool.
+ selectorOrMenu class ~~ Menu
+ ifTrue: [editor openModalOnClass:cls andSelector:selectorOrMenu]
+ ifFalse: [editor openModalOnMenu:selectorOrMenu].
self helpTool updateList.
- editor selectorName ~= aspect ifTrue:[
+ editor selectorName ~= selectorOrMenu ifTrue:[
editor didInstall ifTrue:[
self specTool specification menuSelector:editor selectorName asSymbol.
self modifiedChannel value:true.
@@ -1980,7 +1996,7 @@
]
!
-openSubSpecGuiPainter
+openSubSpecGUIPainter
"opens a GUI Painter on the current subspecification"
|spec cls meta sel|
@@ -1988,7 +2004,7 @@
spec := self specTool specification.
cls := spec majorKey.
cls isNil ifTrue:[
- cls := self specClass.
+ cls := specClass.
].
(cls isNil or:[(cls := self resolveName:cls) isNil]) ifTrue:[
spec majorKey isNil ifTrue:[
@@ -2146,10 +2162,30 @@
!UIPainter methodsFor:'private'!
+askForModification
+ "check interface modification
+ "
+
+ self treeSelection. "accept modifications"
+
+ (modified or: [self painter isModified or: [self helpTool isModified]])
+ ifTrue:
+ [
+ ((YesNoBox title:'Window Spec was modified!!')
+ noText:'Cancel';
+ yesText:'Waste it and proceed';
+ showAtPointer;
+ accepted) ifFalse: [^false].
+ modified := false.
+ self painter resetModification
+ ].
+ ^true
+!
+
checkModified
"check interface modification
- "
- (self painter isModified or: [self helpTool isModified])
+ "
+ (self isModified and: [self isModified or: [self helpTool isModified]])
ifTrue:
[
((YesNoBox title:'Window Spec was modified!!')
@@ -2192,7 +2228,7 @@
resourceMessage: aString
- aString notNil "and: [self askForModification])"
+ (aString notNil and: [self askForModification])
ifTrue:
[
|msg cls sel|
@@ -2330,7 +2366,7 @@
!
isModified
- "returns true if current specification or layout is modified
+ "return true if current specification or layout is modified
"
^ self modifiedChannel value
!
@@ -2457,8 +2493,8 @@
self valueOfCanCut value: canCutOrCopy.
self valueOfCanCopy value: canCutOrCopy.
- self valueOfCanPaste value: canPaste
-
+ self valueOfCanPaste value: canPaste.
+ self valueOfCanPasteWithKeepingLayout value: (canPaste & self canKeepLayoutInSelection)
! !
!UIPainter methodsFor:'startup / release'!
@@ -2467,7 +2503,7 @@
"close all windows open by builder
"
- self checkModified ifFalse:[^self].
+ self askForModification ifFalse:[^self].
treeView model removeDependent:self.
self painter release.
@@ -2515,6 +2551,8 @@
"
|painterView painter cls topView|
+ modified := false.
+
aspects := IdentityDictionary new.
aspects at:#classNameChannel put:(
@@ -2679,6 +2717,8 @@
"
|code|
+ self treeSelection. "accept modifications"
+
self hasSpecClassAndSelector ifFalse:[
self defineClassAndSelector
].
@@ -2701,6 +2741,8 @@
"
|code|
+ self treeSelection. "accept modifications"
+
self hasSpecClassAndSelector ifFalse:[
self defineClassAndSelector
].
@@ -2721,6 +2763,8 @@
doLoad
+ self askForModification ifFalse: [^nil].
+
self loadFromMessage:
(ResourceSelectionBrowser
request: 'Load Window Spec From Class'
@@ -2733,6 +2777,9 @@
doLoadSubspec
|subSpecMessage|
+
+ self treeSelection. "ask for modification"
+
(subSpecMessage := ResourceSelectionBrowser
request: 'Load Subspec From Class'
onSuperclass: nil
@@ -2760,12 +2807,15 @@
doNew
"remove all components and associated resources
"
- self painter isModified ifTrue:[
- (self confirm:'Edit a new window spec without saving current?') ifFalse:[
- ^ self
- ]
- ].
+
+ self askForModification ifFalse: [^nil].
+ specClass := specSelector := nil.
self painter removeAll.
+ treeView canvas topView name: UIPainter defaultNameOfCanvas.
+ treeView canvas topView label: UIPainter defaultNameOfCanvas.
+ treeView selection:#(1).
+ self treeSelection.
+ self updateInfoLabel.
!
doPickAView
@@ -2773,11 +2823,7 @@
"
|painter view cls spec app|
- self painter isModified ifTrue:[
- (self confirm:'Pick another window spec without saving your modifications?') ifFalse:[
- ^ self
- ]
- ].
+ self askForModification ifFalse: [^nil].
(view := Screen current viewFromUser) notNil ifTrue:[
view == Screen current rootView ifFalse:[
@@ -2786,18 +2832,19 @@
"/ ok, got it
- (app := view application) notNil ifTrue:[
+ " (app := view application) notNil ifTrue:[
cls := app class
] ifFalse:[
cls := view class
- ].
+ ].
self setClass:cls selector:nil.
-
+ "
painter setupFromSpec:spec.
]
- ]
-
- "Modified: / 1.11.1997 / 13:47:49 / cg"
+ ].
+
+ self updateInfoLabel
+
!
doRedefineMethods
@@ -2823,8 +2870,10 @@
"
|code painter|
+ self treeSelection. "ask for modification"
+
self hasSpecClassAndSelector ifFalse:[
- self defineClassAndSelector
+ (self defineClassAndSelector) isNil ifTrue: [^nil]
].
(specClass notNil and: [(Smalltalk at: specClass asSymbol) isClass])
@@ -2856,6 +2905,7 @@
self helpTool installHelpSpecsOnClass:specClass.
self updateInfoLabel.
+ modified := false.
self painter resetModification.
((Smalltalk at: specClass asSymbol) class implements: specSelector)
@@ -2872,6 +2922,8 @@
|resourceMessage|
+ self treeSelection. "ask for modification"
+
(resourceMessage := ResourceSelectionBrowser
request: 'Save In Class'
onSuperclass: #Object
@@ -2895,6 +2947,8 @@
"
|cls app infoMessage|
+ self treeSelection. "accept modifications"
+
(specClass isNil or:[specSelector size < 2]) ifTrue:[
self painter isModified ifTrue:[
infoMessage := 'Class and selector must be defined,\and the window spec must be saved first!!' withCRs.
@@ -2951,6 +3005,8 @@
"
|code v|
+ self treeSelection. "accept modifications"
+
code := self painter generateWindowSpecMethodSource.
v := CodeView open.
@@ -2961,7 +3017,7 @@
loadFromMessage: aMessage
- ((aMessage size > 0) and: [self checkModified])
+ ((aMessage size > 0) and: [self askForModification])
ifTrue:
[
|readStream aClass aSelector|
@@ -2999,7 +3055,7 @@
self warn:'No class named ' , specSuperclass , ' exists!!'.
^ false.
].
- (self confirm:'Create ' , specClass , '?') ifTrue:[
+ (self confirm:'Create class ' , specClass asBoldText, '?') ifTrue:[
superclass subclass:(specClass asSymbol)
instanceVariableNames:''
classVariableNames:''
@@ -3078,6 +3134,10 @@
selector:specSelector.
]
]
+ ifFalse:
+ [
+ ^nil
+ ]
] doWhile:[again].
@@ -3294,9 +3354,7 @@
].
model root name: UIPainter defaultNameOfCanvas asBoldText.
model root children:(OrderedCollection new).
- model recomputeList.
- self selection:nil.
-
+ model recomputeList.
!