--- a/MenuEditor.st Fri Feb 10 17:11:56 2006 +0100
+++ b/MenuEditor.st Mon Feb 13 09:50:37 2006 +0100
@@ -602,6 +602,51 @@
)
)
+!
+
+windowSpecInBrowser
+ "This resource specification was automatically generated
+ by the UIPainter of ST/X."
+
+ "Do not manually edit this!! If it is corrupted,
+ the UIPainter may not be able to read the specification."
+
+ "
+ UIPainter new openOnClass:MenuEditor andSelector:#windowSpecInBrowser
+ MenuEditor new openInterface:#windowSpecInBrowser
+ "
+
+ <resource: #canvas>
+
+ ^
+ #(FullSpec
+ name: windowSpecInBrowser
+ window:
+ (WindowSpec
+ label: 'Menu Editor'
+ name: 'Menu Editor'
+ min: (Point 400 320)
+ bounds: (Rectangle 0 0 450 350)
+ menu: menu
+ )
+ component:
+ (SpecCollection
+ collection: (
+ (MenuPanelSpec
+ name: 'ToolBar1'
+ layout: (LayoutFrame 0 0 0 0 0 1 30 0)
+ menu: menu
+ )
+ (UISubSpecification
+ name: 'SubSpecification1'
+ layout: (LayoutFrame 0 0 30 0 0 1 0 1)
+ majorKey: MenuEditor
+ minorKey: windowSpec
+ )
+ )
+
+ )
+ )
! !
!MenuEditor class methodsFor:'menu specs'!
@@ -809,71 +854,76 @@
<resource: #menu>
^
- #(#Menu
- #(
- #(#MenuItem
- #activeHelpKey: #fileNew
- #label: 'New'
- #itemValue: #doNew
- #translateLabel: true
+ #(Menu
+ (
+ (MenuItem
+ activeHelpKey: fileNew
+ label: 'New'
+ itemValue: doNew
+ translateLabel: true
)
- #(#MenuItem
- #label: '-'
+ (MenuItem
+ label: '-'
+ )
+ (MenuItem
+ activeHelpKey: fileLoad
+ label: 'Load...'
+ itemValue: doLoad
+ translateLabel: true
)
- #(#MenuItem
- #activeHelpKey: #fileLoad
- #label: 'Load...'
- #itemValue: #doLoad
- #translateLabel: true
+ (MenuItem
+ label: '-'
)
- #(#MenuItem
- #label: '-'
+ (MenuItem
+ activeHelpKey: fileSave
+ label: 'Save'
+ itemValue: doSave
+ translateLabel: true
)
- #(#MenuItem
- #activeHelpKey: #fileSave
- #label: 'Save'
- #itemValue: #doSave
- #translateLabel: true
+ (MenuItem
+ activeHelpKey: fileSaveAs
+ label: 'Save As...'
+ itemValue: doSaveAs
+ translateLabel: true
)
- #(#MenuItem
- #activeHelpKey: #fileSaveAs
- #label: 'Save As...'
- #itemValue: #doSaveAs
- #translateLabel: true
+ (MenuItem
+ label: '-'
)
- #(#MenuItem
- #label: '-'
+ (MenuItem
+ activeHelpKey: filePickAMenu
+ label: 'Pick a Menu...'
+ itemValue: doPickAMenu
+ translateLabel: true
)
- #(#MenuItem
- #activeHelpKey: #filePickAMenu
- #label: 'Pick a Menu...'
- #itemValue: #doPickAMenu
- #translateLabel: true
+ (MenuItem
+ label: '-'
+ isVisible: isStandAlone
)
- #(#MenuItem
- #label: '-'
+ (MenuItem
+ activeHelpKey: fileBrowseClass
+ enabled: hasValidSpecClass
+ label: 'Browse Class'
+ itemValue: doBrowseClass
+ translateLabel: true
+ isVisible: isStandAlone
)
- #(#MenuItem
- #activeHelpKey: #fileShowMenuSpec
- #label: 'Show Menu Spec'
- #itemValue: #doShowMenuSpec
- #translateLabel: true
+ (MenuItem
+ activeHelpKey: fileShowMenuSpec
+ label: 'Show Menu Spec'
+ itemValue: doShowMenuSpec
+ translateLabel: true
+ isVisible: isStandAlone
)
- #(#MenuItem
- #activeHelpKey: #fileBrowseClass
- #enabled: #hasValidSpecClass
- #label: 'Browse Class'
- #itemValue: #doBrowseClass
- #translateLabel: true
+ (MenuItem
+ label: '-'
+ isVisible: isStandAlone
)
- #(#MenuItem
- #label: '-'
- )
- #(#MenuItem
- #activeHelpKey: #fileExit
- #label: 'Exit'
- #itemValue: #closeRequest
- #translateLabel: true
+ (MenuItem
+ activeHelpKey: fileExit
+ label: 'Exit'
+ itemValue: closeRequest
+ translateLabel: true
+ isVisible: isStandAlone
)
)
nil
@@ -1025,6 +1075,7 @@
(MenuItem
label: 'History'
translateLabel: true
+ isVisible: isStandAlone
submenuChannel: menuHistory
)
(MenuItem
@@ -1480,7 +1531,7 @@
useHelpTool:aHelpTool
"take the help dictionaries from aHelpTool into my helpTool
"
- self helpTool buildFromHelpTool:aHelpTool.
+ self helpTool loadFromHelpTool:aHelpTool.
! !
!MenuEditor methodsFor:'actions'!
@@ -1515,7 +1566,7 @@
rscRetrHolder value:(imageTool resourceRetriever).
helpKeyHolder value:(helpTool helpKey).
selectedItem fromAspects:aspects.
- modified := true.
+ self setModified.
selectedItem isRootItem ifTrue:[
"/ update specSelector
@@ -1631,30 +1682,6 @@
!MenuEditor methodsFor:'building'!
-buildFromClass:aSpecClass andSelector:aSpecSelector
- "rebuild menu from a class and selector
- "
- |cls menu|
-
- menu := nil.
-
- self isStandAlone ifTrue:[ self helpTool buildFromClass:aSpecClass ].
-
- aSpecSelector notNil ifTrue:[
- aSpecClass ifNotNil:[
- cls := self resolveName:aSpecClass.
- menu := cls perform:aSpecSelector ifNotUnderstood:nil.
-
- menu ifNotNil:[
- (menu isMemberOf:Menu) ifFalse:[
- menu := Menu new fromLiteralArrayEncoding:menu
- ].
- ]
- ].
- ].
- self buildFromMenu:menu selector:aSpecSelector.
-!
-
buildFromMenu:aMenu selector:aSelector
"rebuild menu from a Menu
"
@@ -1675,9 +1702,42 @@
!
buildFromResourceSpec:aResourceSpec
- "rebuild menu from a resource spec
- "
+ "rebuild the menu from a resource spec"
+
self buildFromMenu:aResourceSpec selector:nil
+!
+
+loadFromClass:aClass andSelector:aSelector
+ "rebuild menu from a class and selector"
+
+ |cls menu|
+
+ self assert:(aClass isNil or:[aClass isClass]).
+
+ menu := nil.
+
+ self isStandAlone ifTrue:[ self helpTool loadFromClass:aClass ].
+
+ specClass := aClass.
+ specSelector := aSelector.
+
+ aSelector notNil ifTrue:[
+ aClass notNil ifTrue:[
+ cls := aClass isBehavior ifTrue:[ aClass ] ifFalse:[ self resolveName:aClass].
+
+ (cls respondsTo:aSelector) ifTrue:[
+ menu := cls perform: aSelector.
+ ].
+
+ menu notNil ifTrue:[
+ (menu isMemberOf:Menu) ifFalse:[
+ menu := Menu new fromLiteralArrayEncoding:menu
+ ].
+ ]
+ ].
+ ].
+ self buildFromMenu:menu selector:aSelector.
+ self clearModified.
! !
!MenuEditor methodsFor:'change & update'!
@@ -2124,7 +2184,7 @@
"ask for modification
"
self valueOfEnablingCommitButtons value ifTrue:[
- modified := true.
+ self setModified.
self askForListModification.
modified ifTrue:[^ self].
self clearModified.
@@ -2225,14 +2285,15 @@
intoItem add:newItem beforeIndex:index.
selectionHolder value:(Array with:newItem).
].
- modified := true.
+ self setModified.
].
^ newItem
!
clearModified
- "clear the modifiedChannel and the commitPanel
- "
+ "clear the modifiedChannel and the commitPanel"
+
+ modified := false.
self valueOfEnablingCommitButtons value:false.
self clearModifiedFlag.
!
@@ -2448,19 +2509,18 @@
!
doPickAMenu
- "pick a menu from user
- "
+ "pick a menu from user"
+
|view|
self askForModification ifTrue:[
- ( (view := Screen current viewFromUser) isNil
- or:[view == Screen current rootView]
- ) ifTrue:[
+ view := Screen current viewFromUser.
+ (view isNil or:[view == Screen current rootView]) ifTrue:[
^ self
].
view specClass == MenuPanelSpec ifTrue:[
specSelector := #pickedMenu.
- ^ self buildFromMenu:(view asMenu) selector:specSelector.
+ self buildFromMenu:(view asMenu) selector:specSelector.
].
].
!
@@ -2515,7 +2575,7 @@
self updateHistory.
hasSaved := true.
- modified := false.
+ self clearModified.
!
doSaveAs
@@ -2537,6 +2597,10 @@
spec ifNotNil:[
CodeView openWith:spec title: 'Menu Spec'
].
+!
+
+save
+ self doSave
! !
!MenuEditor methodsFor:'user actions-creation'!
@@ -2685,7 +2749,7 @@
toDelete do:[:el| el remove ].
].
self selectedItem:(nextItem ? prevItem).
- modified := true.
+ self setModified.
self updateChannels.
!
@@ -2733,7 +2797,7 @@
item ifNil:[^ self].
aDirection == #inNext ifTrue:[ item canMoveInNext ifFalse:[^ self] ]
- ifFalse:[ item canMoveInAbove ifFalse:[^ self] ].
+ ifFalse:[ item canMoveInAbove ifFalse:[^ self] ].
self askForItemModification ifFalse:[ ^ self ].
@@ -2741,18 +2805,18 @@
idx := parent identityIndexOf:item.
aDirection == #inNext ifTrue:[ toParent := parent at:(idx + 1) ifAbsent:nil ]
- ifFalse:[ toParent := parent at:(idx - 1) ifAbsent:nil ].
+ ifFalse:[ toParent := parent at:(idx - 1) ifAbsent:nil ].
self withoutNotifyDo:[
- selectionHolder setValue:#().
- parent removeIndex:idx.
-
- aDirection == #inNext ifTrue:[ toParent addFirst:item ]
- ifFalse:[ toParent addLast:item ].
- item makeVisible.
+ selectionHolder setValue:#().
+ parent removeIndex:idx.
+
+ aDirection == #inNext ifTrue:[ toParent addFirst:item ]
+ ifFalse:[ toParent addLast:item ].
+ item makeVisible.
].
self selectedItem:item.
- modified := true.
+ self setModified.
!
doMoveInNext
@@ -2783,13 +2847,13 @@
index := grandParent identityIndexOf:parent.
self withoutNotifyDo:[
- selectionHolder setValue:#().
- parent remove:item.
- index > grandParent size ifTrue:[ grandParent add:item ]
- ifFalse:[ grandParent add:item afterIndex:index ]
+ selectionHolder setValue:#().
+ parent remove:item.
+ index > grandParent size ifTrue:[ grandParent add:item ]
+ ifFalse:[ grandParent add:item afterIndex:index ]
].
self selectedItem:item.
- modified := true.
+ self setModified.
!
doMoveUp
@@ -2810,24 +2874,24 @@
self askForItemModification ifFalse:[ ^ self ].
self withoutNotifyDo:[
- parent := item parent.
- children := parent children.
- index := children identityIndexOf:item.
-
- selectionHolder setValue:#().
- children removeIndex:index.
-
- aDirection == #up ifTrue:[
- index == 1 ifTrue:[ children add:item ]
- ifFalse:[ children add:item beforeIndex:index - 1 ]
- ] ifFalse:[
- index > children size ifTrue:[ children addFirst:item ]
- ifFalse:[ children add:item afterIndex:index ]
- ].
- parent childrenOrderChanged.
+ parent := item parent.
+ children := parent children.
+ index := children identityIndexOf:item.
+
+ selectionHolder setValue:#().
+ children removeIndex:index.
+
+ aDirection == #up ifTrue:[
+ index == 1 ifTrue:[ children add:item ]
+ ifFalse:[ children add:item beforeIndex:index - 1 ]
+ ] ifFalse:[
+ index > children size ifTrue:[ children addFirst:item ]
+ ifFalse:[ children add:item afterIndex:index ]
+ ].
+ parent childrenOrderChanged.
].
self selectedItem:item.
- modified := true.
+ self setModified.
! !
!MenuEditor::Item class methodsFor:'defaults'!
@@ -4914,21 +4978,19 @@
doBrowseForImageResource
"opens a browser on image-resource methods"
- |msg|
-
- msg := ResourceSelectionBrowser
- request:'Use Image From Class'
- onSuperclass:nil
- andClass:(self retrieverClass)
- andSelector:(selectorHolder value)
- withResourceTypes:#(image fileImage programImage).
-
- msg ifNil:[ ^ self ].
- msg := msg asCollectionOfWords.
- msg size == 2 ifFalse:[ ^ self ].
-
- retrieverHolder value:(msg first asSymbol).
- selectorHolder value:(msg last asSymbol).
+ |classAndSelector|
+
+ classAndSelector := ResourceSelectionBrowser
+ request:'Use Image From Class'
+ onSuperclass:nil
+ andClass:(self retrieverClass)
+ andSelector:(selectorHolder value)
+ withResourceTypes:#(image fileImage programImage).
+
+ classAndSelector isNil ifTrue:[ ^ self ].
+
+ retrieverHolder value:(classAndSelector methodClass) name.
+ selectorHolder value:(classAndSelector methodSelector).
!
doEditImage