slightly refactored to allow for more redefinition in a subclass
authorClaus Gittinger <cg@exept.de>
Mon, 19 Nov 2007 19:30:18 +0100
changeset 2198 804e778590fc
parent 2197 873c7b960233
child 2199 c542a84adeb6
slightly refactored to allow for more redefinition in a subclass (Expecco-UI-Painter)
UIPainter.st
--- a/UIPainter.st	Mon Nov 19 19:30:01 2007 +0100
+++ b/UIPainter.st	Mon Nov 19 19:30:18 2007 +0100
@@ -102,159 +102,9 @@
 
     ^super flyByHelpSpec addPairsFrom:#(
 
-#alignSelectionBottom
-'Align Bottom Edges'
-
-#alignSelectionCenterHor
-'Align Centers Vertically'
-
-#alignSelectionCenterVer
-'Align Centers Horizontally'
-
-#alignSelectionLeft
-'Align Left Edges'
-
-#alignSelectionLeftAndRight
-'Align Horizontal Edges'
-
-#alignSelectionRight
-'Align Right Edges'
-
-#alignSelectionTop
-'Align Top Edges'
-
-#alignSelectionTopAndBottom
-'Align Vertical Edges'
-
-#centerSelectionHor
-'Center Horizontally'
-
-#centerSelectionVer
-'Center Vertically'
-
-#changePositionDown
-'Move Towards Bottom'
-
-#changePositionLeft
-'Move Towards Left'
-
-#changePositionRight
-'Move Towards Right'
-
-#changePositionUp
-'Move Towards Top'
-
-#editCopy
-'Copy Widget'
-
-#editCut
-'Cut Widget'
-
-#editPaste
-'Paste Widget'
-
-#editDelete
-'Delete Widget'
-
-
-#editDimensionCopyExtent
-'Copy Extent'
-
-#editDimensionCopyLayout
-'Copy Layout'
-
-#editDimensionPasteExtent
-'Paste Extent'
-
-#editDimensionPasteHeight
-'Paste Height'
-
-#editDimensionPasteLayout
-'Paste Layout'
-
-#editDimensionPasteWidth
-'Paste Width'
-
-#editInspectSpec
-'Inspect Spec'
-
-#editBrowseViewClass
-'Browse Widgets Class'
-
-#editInspectView
-'Inspect Widget'
-
-#editOpenSpecDocumentation
-'WidgetDocumentation'
-
-#fileBrowseClass
-'Browse Applications Class'
-
-#fileBrowseAspectMethods
-'Browse Applications Aspect Methods'
-
-#fileLoad
-'Load Spec from Method'
-
-#fileLoadSubspec
-'Load SubSpec'
-
-#fileNew
-'New Spec'
-
-#filePickAnInterface
-'Pick Spec'
-
 #fileSave
-'Save Spec as Method'
-
-#fileSaveAs
-'Save Spec as'
-
-#fileShowWindowSpec
-'View Spec'
-
-#generateAspectMethods
-'Generate Aspect Methods'
-
-#generateHookMethods
-'Generate Hook Methods'
-
-#moveWidgetDown
-'Move Down'
-
-#moveWidgetInto
-'Move Into'
-
-#moveWidgetOut
-'Move Out'
-
-#moveWidgetUp
-'Move Up'
-
-#pasteBuffer
-'Paste'
-
-#pasteWithLayout
-'Paste With Layout'
-
-#settingsCanvas
-'Toggle Canvas'
-
-#settingsGallery
-'Toggle Gallery'
-
-#spreadSelectionHor
-'Spread Horizontally'
-
-#spreadSelectionVer
-'Spread Vertically'
-
-#testGeometryTestMode
-'Toggle Test Mode'
-
-#testStartApplication
-'Start Application'
+'Save Spec'
+
 
 )
 !
@@ -1343,6 +1193,7 @@
          (MenuItem
             label: 'Generate'
             translateLabel: true
+            isVisible: isNotEditingSpecOnly
             submenu: 
            (Menu
               (
@@ -1392,9 +1243,11 @@
                   label: 'Start Application'
                   itemValue: doStartApplication
                   translateLabel: true
+                  isVisible: isNotEditingSpecOnly
                 )
                (MenuItem
                   label: '-'
+                  isVisible: isNotEditingSpecOnly
                 )
                (MenuItem
                   activeHelpKey: testGeometryTestMode
@@ -1434,6 +1287,7 @@
                   label: 'Redefine Aspect Methods'
                   translateLabel: true
                   indication: redefineAspectMethods:
+                  isVisible: isNotEditingSpecOnly
                 )
                (MenuItem
                   activeHelpKey: settingsAspectsAsInstances
@@ -1441,6 +1295,7 @@
                   label: 'Aspects as InstanceVariables'
                   translateLabel: true
                   indication: generateAspectsAsInstanceVariables:
+                  isVisible: isNotEditingSpecOnly
                 )
                (MenuItem
                   label: 'AutoAccept on Selection-Change '
@@ -1558,8 +1413,6 @@
         nil
         nil
       )
-
-    "Modified: / 23-10-2006 / 23:16:26 / cg"
 !
 
 menuAlign
@@ -2069,7 +1922,7 @@
             translateLabel: true
             isButton: true
             isVisible: isStandAlone
-            labelImage: (ResourceRetriever XPToolbarIconLibrary newWindowSpecIcon)
+            labelImage: (ResourceRetriever ToolbarIconLibrary newWindowSpecIcon)
           )
          (MenuItem
             label: '-'
@@ -2082,7 +1935,7 @@
             translateLabel: true
             isButton: true
             isVisible: isStandAlone
-            labelImage: (ResourceRetriever XPToolbarIconLibrary loadFromMethodIcon)
+            labelImage: (ResourceRetriever ToolbarIconLibrary loadFromMethodIcon)
           )
          (MenuItem
             activeHelpKey: fileSave
@@ -2102,7 +1955,7 @@
             itemValue: undoLast
             translateLabel: true
             isButton: true
-            labelImage: (ResourceRetriever XPToolbarIconLibrary undoIcon)
+            labelImage: (ResourceRetriever ToolbarIconLibrary undoIcon)
           )
          (MenuItem
             label: '-'
@@ -2755,7 +2608,7 @@
     someObject == treeView model ifTrue:[
         (something == #selection
         or:[something == #selectionIndex]) ifTrue:[self treeSelectionChanged].
-      ^ self
+        ^ self
     ].
 
     someObject == self galleryShown ifTrue:[
@@ -2766,7 +2619,7 @@
         ] ifFalse:[
             self hideUIView:window
         ].
-      ^ self
+        ^ self
     ].
 
     someObject == self painterShown ifTrue:[
@@ -2777,7 +2630,7 @@
         ] ifFalse:[
             self hideUIView:window
         ].
-      ^ self
+        ^ self
     ].
 
     someObject == self autoAcceptOnSelectionChange ifTrue:[
@@ -2960,6 +2813,9 @@
     painter treeView:treeView.
     treeView model addDependent:self.
     painter enableChannel:(self enableChannel).
+
+    selectionPanel := self selectionPanelClass new.
+    selectionPanel allButOpenInterface:#windowSpec.
 ! !
 
 !UIPainter methodsFor:'menus-dynamic'!
@@ -3327,6 +3183,10 @@
     ^ self modifiedChannel value
 !
 
+isNotEditingSpecOnly
+    ^ true
+!
+
 isPainterEnabled
     "answers whether I am running in test mode"
 
@@ -3607,7 +3467,7 @@
     self setClass:aClass selector:selector.    
 
     (aClass respondsTo:selector) ifTrue:[   
-        self painter setupFromSpec:(aClass perform:selector).
+        self loadFromSpec:(aClass perform:selector).
     ]
 !
 
@@ -3618,41 +3478,26 @@
     self askForModification ifFalse:[^ self].
 
     classAndSelector notNil ifTrue:[
-        self loadFromClass:classAndSelector methodClass andSelector:classAndSelector methodSelector
+        self 
+            loadFromClass:classAndSelector methodClass 
+            andSelector:classAndSelector methodSelector
     ]
 !
 
+loadFromSpec:aSpec
+    "loads a window spec proper"
+
+    self askForModification ifFalse:[^ self].
+
+    self painter setupFromSpec:aSpec.
+!
+
 openInterface:aSymbol 
     "in addition to opening my interface, also open up a gallery and a painter"
     
-    |cls topView galleryWindow icon name|
-
-    self specClass notNil ifTrue:[
-        specClassName isBehavior ifTrue:[
-            name := specClassName nameWithoutPrefix.
-        ] ifFalse:[
-            name := specClassName printString string
-        ]
-    ].
-    (aspects at:#classNameChannel) value:(specClassName ? 'NewApplication').
-
-    specSuperclassName isNil ifTrue:[
-        specClassName notNil ifTrue:[
-            (cls := self resolveName:specClassName) notNil ifTrue:[
-                specSuperclassName := cls superclass name.
-            ]
-        ]
-    ].
-    aspects at:#superclassNameChannel
-        put:((specSuperclassName notNil 
-                ifTrue:[ specSuperclassName ]
-                ifFalse:[ 'ApplicationModel' ]) asValue).
-    aspects at:#superclassNameDefaults
-        put:#( 'ApplicationModel' 'SimpleDialog' ) asValue.
-    aspects at:#methodNameChannel
-        put:((specSelector notNil 
-                ifTrue:[ specSelector asValue ]
-                ifFalse:[ #windowSpec ]) asValue).
+    |topView|
+
+    self setupSpecClassAndSelector.
 
 "/    treeView := TreeView new.
 "/    treeView windowSpecClass:(self defaultWindowSpecClass).
@@ -3676,33 +3521,13 @@
 
     topView := self window.
     topView label:'GUI Painter'.
-    painterView openInGroup:(topView windowGroup).
-    painterView application:self.
-
-    selectionPanel := self selectionPanelClass new.
-    selectionPanel allButOpenInterface:#windowSpec.
-    galleryWindow := selectionPanel window.
-    galleryWindow beToolWindow.
-    galleryWindow openInGroup:(topView windowGroup).
-
-    selectionPanel masterApplication:self.
-    icon := Smalltalk imageFromFileNamed:'UIPainter.xbm' forClass:self class.
-    topView iconLabel:'GUI Painter'.
-    topView icon:icon.
-    painterView iconLabel:'GUI Canvas'.
-    painterView icon:icon.
-    
-"/    painterView topView raise.
-    topView bePartner.
-    painterView bePartner.
-    galleryWindow bePartner.
-    galleryWindow iconLabel:'GUI Gallery'.
-    galleryWindow icon:icon.
-
-    selectionPanel window waitUntilVisible.
-    painterView window waitUntilVisible.
-    self window waitUntilVisible.
-    [ Delay waitForSeconds:0.5. self window topView raise ] fork.
+
+"/    self setupCanvasAndSelectionPanel.
+"/
+"/    selectionPanel window waitUntilVisible.
+"/    painterView window waitUntilVisible.
+"/    self window waitUntilVisible.
+"/    [ Delay waitForSeconds:0.5. self window topView raise ] fork.
 
     "Modified: / 31-08-2006 / 10:13:16 / cg"
 !
@@ -3789,6 +3614,16 @@
         canvasWindow raise.
     ].
 
+    self setupCanvasAndSelectionPanel.
+
+"/    selectionPanel window waitUntilVisible.
+"/    painterView window waitUntilVisible.
+"/    self window waitUntilVisible.
+    [   Delay waitForSeconds:0.1. 
+        self window topView raise.
+        Delay waitForSeconds:0.25. 
+        self window topView raise 
+    ] fork.
     "Modified: / 13.7.1999 / 21:26:52 / cg"
 !
 
@@ -3796,6 +3631,34 @@
     ^ UISelectionPanel
 !
 
+setupCanvasAndSelectionPanel
+    |topView galleryWindow icon|
+
+    icon := Smalltalk imageFromFileNamed:'UIPainter.xbm' forClass:self class.
+
+    topView := self window.
+
+    painterView openInGroup:(topView windowGroup).
+    painterView application:self.
+
+    galleryWindow := selectionPanel window.
+    galleryWindow beToolWindow.
+    galleryWindow openInGroup:(topView windowGroup).
+
+    selectionPanel masterApplication:self.
+
+    topView iconLabel:'GUI Painter'.
+    topView icon:icon.
+    painterView iconLabel:'GUI Canvas'.
+    painterView icon:icon.
+    galleryWindow iconLabel:'GUI Gallery'.
+    galleryWindow icon:icon.
+    
+    topView bePartner.
+    painterView bePartner.
+    galleryWindow bePartner.
+!
+
 setupPainter
     "sets the painter's grid parameters, if defined"
 
@@ -3813,6 +3676,37 @@
     painter shown ifTrue:[painter clearView].
 
     "Modified: / 22.8.1998 / 17:41:34 / cg"
+!
+
+setupSpecClassAndSelector
+    |cls name|
+
+    self specClass notNil ifTrue:[
+        specClassName isBehavior ifTrue:[
+            name := specClassName nameWithoutPrefix.
+        ] ifFalse:[
+            name := specClassName printString string
+        ]
+    ].
+    (aspects at:#classNameChannel) value:(specClassName ? 'NewApplication').
+
+    specSuperclassName isNil ifTrue:[
+        specClassName notNil ifTrue:[
+            (cls := self resolveName:specClassName) notNil ifTrue:[
+                specSuperclassName := cls superclass name.
+            ]
+        ]
+    ].
+    aspects at:#superclassNameChannel
+        put:((specSuperclassName notNil 
+                ifTrue:[ specSuperclassName ]
+                ifFalse:[ 'ApplicationModel' ]) asValue).
+    aspects at:#superclassNameDefaults
+        put:#( 'ApplicationModel' 'SimpleDialog' ) asValue.
+    aspects at:#methodNameChannel
+        put:((specSelector notNil 
+                ifTrue:[ specSelector asValue ]
+                ifFalse:[ #windowSpec ]) asValue).
 ! !
 
 !UIPainter methodsFor:'user actions'!
@@ -4190,16 +4084,14 @@
 
     |spec|
 
-    (spec := self specForSelection) isNil ifTrue:[
-	treeView isCanvasSelected ifTrue:[
-	    spec := treeView canvasSpec.
-	]
+    (spec := self painter specForSelection) isNil ifTrue:[
+        treeView isCanvasSelected ifTrue:[
+            spec := treeView canvasSpec.
+        ]
     ].
     spec notNil ifTrue:[
-	spec inspect
+        spec inspect
     ]
-
-
 !
 
 doInspectView