From VisualWorks®, 7.6 of February 1, 2008 on February 1, 2008 at 12:49:09 pm (Dialog confirm: 'You are filing-in a Parcel source file!\\While this is possible it will not have\the same effect as loading the parcel.\None of the Parcel''s prerequisites will\be loaded and none of its load actions\will be performed.\\Are you sure you want to file-in?' withCRs) ifFalse: [self error: 'Parcel file-in abandoned. Choose terminate or close.'] <class> <name>MenuPragma1Example</name> <environment>Examples</environment> <super>UI.ApplicationModel</super> <private>false</private> none files <imports></imports> <category>Examples-Help</category> <attributes> <package>MenuPragma1-Example</package> </attributes> </class> <comment> Examples.MenuPragma1Example
This example class demonstrates how to implement a menu of commands (as opposed to a menu of values) in each of the three types of menu: menu bar, menu button and pop-up menu. In this variation of MenuCommandExample, the menu is composed entirely from menu pragmas.
</comment> <methods> Examples.MenuPragma1Example <category>testing</category>
anyFileSelected ^self files selection notNil
</methods> <methods> Examples.MenuPragma1Example <category>aspects</category>
files ^files
performer ^self
</methods> <methods> Examples.MenuPragma1Example <category>initialize-release</category>
initialize files := SelectionInList new.
</methods> <methods> Examples.MenuPragma1Example <category>interface opening</category>
postBuildWith: aBuilder (aBuilder menuAt: #menuBar) augmentFrom: self class to: self class menuName: #menuBar.
</methods> <methods> Examples.MenuPragma1Example class <category>resources</category>
menuBar ^Menu new
workspaceIcon ^VisualLauncher workspaceIcon
</methods> <methods> Examples.MenuPragma1Example <category>menu messages</category>
addFile "Prompt for a filename and add it to the list." <menuItem:'&Add' nameKey: nil shortcutKeyCharacter: $A shortcutModifiers: 8 "InputState altMask" menu: #(#menuBar #file) position: 10.02> | name list selectionInList | name := Dialog requestFileName: 'File to add' default: '' version: #mustBeOld. name isEmpty ifFalse: [name asFilename isDirectory ifTrue: [^Dialog warn: 'A directory cannot be added.' for: ScheduledControllers activeController view]. selectionInList := self files. list := selectionInList list. selectionInList selection isNil ifTrue: [list add: name] ifFalse: [list add: name before: selectionInList selection]. selectionInList list: list]
deleteFile "Remove the selected file from the list." <menuItem:'&Delete' nameKey: nil enablement: #anyFileSelected indication: nil shortcutKeyCharacter: $D shortcutModifiers: 8 "InputState altMask" menu: #(#menuBar #file) position:10.03> | selectionInList list | selectionInList := self files. list := selectionInList list. list removeAtIndex: selectionInList selectionIndex. selectionInList list: list.
explainUsage "Tell how to use the example." <menuItem:'Usage' nameKey: nil menu: #(menuBar #help) position:10.01> Dialog warn: ' This example demonstrates a menu of commands that is accessible via a menu bar, a menu button or a pop-up menu. It can also be used to list your most-used text files for quick editing. '
openFile "Open a File Editor on the selected file." <menuItem:'Open' nameKey: nil enablement: #anyFileSelected indication: nil shortcutKeyCharacter: $O shortcutModifiers: 8 "InputState altMask" menu: #(#menuBar #file) position:10.01> | selectedFile | selectedFile := self files selection. selectedFile asFilename edit.
openWorkspace <menuItem: #(#workspace #menus '&Workspace') icon: #workspaceIcon nameKey: nil shortcutKeyCharacter: #F6 shortcutModifiers: 0 menu:#(#menuBar #file) position:20.01> Workspace open
</methods> <methods> Examples.MenuPragma1Example <category>menus</category>
fileMenu <submenu:#(#fileMenu #menus '&File') nameKey:#file menu:#(menuBar) position: 10.0>
helpMenu <submenu:#(#helpMenu #menus '&Help') nameKey:#help menu:#(menuBar) position: 30.0>
</methods> <methods> Examples.MenuPragma1Example class <category>interface specs</category>
windowSpec "UIPainter new openOnClass: self andSelector: #windowSpec" <resource: #canvas> ^#(#{UI.FullSpec} #window: #(#{UI.WindowSpec} #label: 'MenuCommandExample' #min: #(#{Core.Point} 174 142 ) #max: #(#{Core.Point} 300 300 ) #bounds: #(#{Graphics.Rectangle} 859 611 1152 838 ) #flags: 4 #menu: #menuBar ) #component: #(#{UI.SpecCollection} #collection: #( #(#{UI.SequenceViewSpec} #layout: #(#{Graphics.LayoutFrame} 10 0 35 0 -10 1 -10 1 ) #model: #files #menu: #menuBar ) #(#{UI.MenuButtonSpec} #layout: #(#{Graphics.LayoutFrame} -50 0.5 5 0 50 0.5 30 0 ) #model: #performer #label: 'Actions' #menu: #menuBar ) ) ) )
</methods> "Imported Classes:" self error: 'Attempting to file-in parcel imports. Choose terminate or close' <class> <name>ApplicationModel</name> <environment>UI</environment> <super>UI.Model</super> <private>false</private> none builder uiSession eventHandlers savedWindowInformation <imports></imports> <category>UIBuilder-Framework</category> <attributes> <package>UIBuilder-Framework</package> </attributes> </class>