From VisualWorks®, 7.6 of February 1, 2008 on February 1, 2008 at 12:48:58 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>ToolCommandExample</name> <environment>Examples</environment> <super>UI.ApplicationModel</super> <private>false</private> none files anySelection onHook leakyTap phoneImage tapImage hideHook hideTap <imports></imports> <category>Examples-Help</category> <attributes> <package>ToolCommand-Example</package> </attributes> </class> <comment> Examples.ToolCommandExample
ToolCommandExample demonstrates a menu of commands may be accessible via a menu bar, a menu button, a tool bar, or a pop-up menu. It demonstrates that menu and tool bar items might change enablement, label, image, visibility, and indication state with selections. Instance Variables: anySelection <PluggableAdaptor> model for whether a selection has been made in files files <SelectionInList> model of selection among file name choices hideHook <ValueModel with:Boolean> true value to hide connection tool bar button hideTap <ValueModel with:Boolean> true value to hide issues (water tap) tool bar button leakyTap <Boolean> true to display a leaky tap in the menu and tool bar onHook <Boolean> true to display a leaky tap in the menu and tool bar phoneImage <ValueModel with: OpaqueImageWithEnablement> model of current icon for connection tool bar button tapImage <ValueModel with: OpaqueImageWithEnablement> model of current icon for issues (water tap) tool bar button
</comment> <methods> Examples.ToolCommandExample <category>menu messages</category>
addFile "Prompt for a filename and add it to the list." | 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]
beFault | menuBar | menuBar := self builder menuAt: #menuBar. leakyTap := true. (menuBar atNameKey: #leakyTap) hidden: false. (menuBar atNameKey: #fixedTap) hidden: true. self tapImage value: self class leakyTapIcon. ((self builder componentAt:#toolBar) componentAt: #issues) widget helpText: 'Fix'
beFixed | menuBar | menuBar := self builder menuAt: #menuBar. leakyTap := false. (menuBar atNameKey: #leakyTap) hidden: true. (menuBar atNameKey: #fixedTap) hidden: false. self tapImage value: self class fixedTapIcon. ((self builder componentAt:#toolBar) componentAt: #issues) widget helpText: 'Fault'
beOffHook | menuBar| menuBar := self builder menuAt: #menuBar. onHook := false. (menuBar atNameKey: #onHook) hidden: false. (menuBar atNameKey: #offHook) hidden: true. self phoneImage value: self class offHookIcon. ((self builder componentAt: #toolBar) componentAt: #connection) widget helpText: 'Disconnect'
beOnHook | menuBar | menuBar := self builder menuAt:#menuBar. onHook := true. (menuBar atNameKey: #onHook) hidden: true. (menuBar atNameKey: #offHook) hidden: false. self phoneImage value: self class onHookIcon. ((self builder componentAt:#toolBar) componentAt: #connection) widget helpText: 'Connect'
deleteFile "Remove the selected file from the list." | selectionInList list | selectionInList := self files. list := selectionInList list. list removeAtIndex: selectionInList selectionIndex. selectionInList list: list.
explainUsage "Tell how to use the example." Dialog warn: ' This example demonstrates a menu of commands that is accessible via a menu bar, a menu button, a tool bar, or a pop-up menu. It demonstrates that menu and tool bar items might change state with selections. It can also be used to list your most-used text files for quick editing. '
openFile "Open a File Editor on the selected file." | selectedFile | selectedFile := self files selection. selectedFile asFilename edit.
toggleHideHook self hideHook value: self hideHook value not
toggleHideTap self hideTap value: self hideTap value not
toggleHook onHook ifTrue:[self beOffHook] ifFalse:[self beOnHook].
toggleTap leakyTap ifTrue:[self beFixed] ifFalse:[self beFault].
</methods> <methods> Examples.ToolCommandExample <category>testing</category>
anyFileSelected ^anySelection isNil ifTrue:[anySelection := (PluggableAdaptor on: self files selectionHolder) getBlock:[:m| m value notNil] putBlock:[:m :v| ] updateBlock:[:m :a :v| true]] ifFalse:[anySelection]
</methods> <methods> Examples.ToolCommandExample <category>aspects</category>
files ^files
hideHook ^hideHook
hideTap ^hideTap
performer ^self
phoneImage ^phoneImage
showHook ^hideHook value not
showTap ^hideTap value not
tapImage ^tapImage
</methods> <methods> Examples.ToolCommandExample <category>initialize-release</category>
initialize files := SelectionInList new. leakyTap := true. onHook := true. phoneImage := self class onHookIcon asValue. tapImage := self class leakyTapIcon asValue. hideHook := false asValue. hideTap := false asValue.
</methods> <methods> Examples.ToolCommandExample <category>interface opening</category>
postBuildWith: aBuilder | toolMenu | toolMenu := aBuilder menuAt: #toolBar. (toolMenu atNameKey: #connection) labelImage: self phoneImage; hidden: self hideHook. (toolMenu atNameKey: #issues) labelImage: self tapImage; hidden: self hideTap.
</methods> <methods> Examples.ToolCommandExample class <category>resources</category>
fixedTapIcon ^OpaqueImageWithEnablement figure: self fixedTapImage shape: self fixedTapMask inactiveMask: self fixedTapMask
leakyTapIcon ^OpaqueImageWithEnablement figure: self leakyTapImage shape: self leakyTapMask inactiveMask: self leakyTapMask
minusIcon ^OpaqueImageWithEnablement figure: self minusIconImage shape: self minusIconMask inactiveMask: self minusIconMask
offHookIcon ^OpaqueImageWithEnablement figure: self offHookImage shape: self offHookMask inactiveMask: self offHookMask
onHookIcon ^OpaqueImageWithEnablement figure: self onHookImage shape: self onHookMask inactiveMask: self onHookMask
openIcon ^OpaqueImageWithEnablement figure: self openIconImage shape: self openIconMask inactiveMask: self openIconMask
fixedTapImage "Tools.UIMaskEditor new openOnClass: self andSelector: #fixedTapImage" <resource: #image> ^(Image extent: 20@20 depth: 2 bitsPerPixel: 2 palette: (Graphics.MappedPalette withColors: ((Core.Array new: 4) at: 1 put: Graphics.ColorValue black; at: 2 put: (Graphics.ColorValue scaledRed: 5460 scaledGreen: 5460 scaledBlue: 5460); at: 3 put: Graphics.ColorValue white; at: 4 put: (Graphics.ColorValue scaledRed: 4111 scaledGreen: 4111 scaledBlue: 4111); yourself)) usingBits: #[170 170 170 170 170 0 0 0 170 168 42 10 170 0 0 0 170 162 192 178 170 0 0 0 170 168 51 15 170 0 0 0 170 170 243 254 170 0 0 0 170 170 0 40 42 0 0 0 170 0 42 2 58 0 0 0 168 170 170 162 58 0 0 0 162 85 85 81 58 0 0 0 161 127 255 243 58 0 0 0 163 240 0 3 58 0 0 0 160 3 255 252 58 0 0 0 171 255 170 170 250 0 0 0 170 170 170 170 170 0 0 0 170 170 170 170 170 0 0 0 170 170 170 170 170 0 0 0 170 170 170 170 170 0 0 0 170 170 170 170 170 0 0 0 170 170 170 170 170 0 0 0 170 170 170 170 170 0 0 0])
fixedTapMask "Tools.UIMaskEditor new openOnClass: self andSelector: #tightTapMask" <resource: #image> ^(Image extent: 20@20 depth: 1 bitsPerPixel: 1 palette: CoveragePalette monoMaskPalette usingBits: #[0 0 0 0 1 140 0 0 2 246 0 0 1 255 0 0 0 254 0 0 0 249 128 0 15 142 192 0 16 2 192 0 47 255 192 0 63 255 192 0 63 255 192 0 63 255 192 0 31 0 192 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0])
helpIcon "Tools.UIMaskEditor new openOnClass: self andSelector: #helpIcon" <resource: #image> ^(Image extent: 20@20 depth: 1 bitsPerPixel: 1 palette: CoveragePalette monoMaskPalette usingBits: #[0 0 0 0 0 0 0 0 1 240 0 0 3 252 0 0 6 28 0 0 12 14 0 0 14 14 0 0 14 14 0 0 0 12 0 0 0 60 0 0 0 120 0 0 0 240 0 0 0 224 0 0 0 224 0 0 0 0 0 0 0 224 0 0 0 224 0 0 0 224 0 0 0 0 0 0 0 0 0 0])
leakyTapImage "Tools.UIMaskEditor new openOnClass: self andSelector: #leakyTapImage" <resource: #image> ^(Image extent: 20@20 depth: 3 bitsPerPixel: 4 palette: (Graphics.MappedPalette withColors: ((Core.Array new: 6) at: 1 put: Graphics.ColorValue black; at: 2 put: Graphics.ColorValue white; at: 3 put: (Graphics.ColorValue scaledRed: 5460 scaledGreen: 5460 scaledBlue: 5460); at: 4 put: (Graphics.ColorValue scaledRed: 4111 scaledGreen: 4111 scaledBlue: 4111); at: 5 put: Graphics.ColorValue cyan; at: 6 put: (Graphics.ColorValue scaledRed: 0 scaledGreen: 4111 scaledBlue: 4111); yourself)) usingBits: (ByteArray fromPackedString: 'DQDQDQDQDQDQDP@@DQDQD@DQ@ADQDP@@DQDQ@S@@D0DQDP@@DQDQD@LC@CLQDP@@DQDQDSLCL3DQDP@@DQDQDP@@@Q@ADP@@DQD@@@DQ@@DCDP@@DQ@QDQDQDPDCDP@@DPD"H"H"H HCDP@@DPH#L3L3L0LCDP@@DPL3@@@@@@LCDP@@DP@@@3L3L3@CDP@@DQL4L1DQDQD3DP@@DQDTDQDQDQDQDP@@DQEETQDQDQDQDP@@DQDUDQDQDQDQDP@@DQDQDQDQDQDQDP@@DQDTDQDQDQDQDP@@DQEETQDQDQDQDP@@DQDQDQDQDQDQDP@@'))
leakyTapMask "Tools.UIMaskEditor new openOnClass: self andSelector: #leakyTapMask" <resource: #image> ^(Image extent: 20@20 depth: 1 bitsPerPixel: 1 palette: CoveragePalette monoMaskPalette usingBits: #[0 0 0 0 1 140 0 0 2 246 0 0 1 255 0 0 0 254 0 0 0 249 128 0 15 142 192 0 16 2 192 0 47 255 192 0 63 255 192 0 63 255 192 0 63 255 192 0 31 0 192 0 4 0 0 0 14 0 0 0 4 0 0 0 0 0 0 0 4 0 0 0 14 0 0 0 0 0 0 0])
menuBar "Tools.MenuEditor new openOnClass: self andSelector: #menuBar" <resource: #menu> ^#(#{UI.Menu} #( #(#{UI.MenuItem} #rawLabel: 'File' #submenu: #(#{UI.Menu} #( #(#{UI.MenuItem} #rawLabel: 'Open' #nameKey: #open #value: #openFile #enablementSelector: #anyFileSelected #shortcutKeyCharacter: $O #shortcutModifiers: 8 ) #(#{UI.MenuItem} #rawLabel: 'Add' #value: #addFile #shortcutKeyCharacter: $A #shortcutModifiers: 8 ) #(#{UI.MenuItem} #rawLabel: 'Delete' #nameKey: #delete #value: #deleteFile #enablementSelector: #anyFileSelected #shortcutKeyCharacter: $D #shortcutModifiers: 8 ) ) #(1 2 ) nil ) ) #(#{UI.MenuItem} #rawLabel: 'View' #submenu: #(#{UI.Menu} #( #(#{UI.MenuItem} #rawLabel: 'Phone' #value: #toggleHideHook #indication: true #indicationSelector: #showHook ) #(#{UI.MenuItem} #rawLabel: 'Leaky Tap' #value: #toggleHideTap #indication: true #indicationSelector: #showTap ) ) #(2 ) nil ) ) #(#{UI.MenuItem} #rawLabel: 'Tools' #nameKey: #tools #submenu: #(#{UI.Menu} #( #(#{UI.MenuItem} #rawLabel: 'Connect' #nameKey: #offHook #value: #beOffHook #labelImage: #(#{UI.ResourceRetriever} #{ToolCommandExample} #onHookIcon ) ) #(#{UI.MenuItem} #rawLabel: 'Disconnect' #nameKey: #onHook #value: #beOnHook #hidden: true #labelImage: #(#{UI.ResourceRetriever} #{ToolCommandExample} #offHookIcon ) ) #(#{UI.MenuItem} #rawLabel: 'Fix' #nameKey: #leakyTap #value: #beFixed #labelImage: #(#{UI.ResourceRetriever} #{ToolCommandExample} #leakyTapIcon ) ) #(#{UI.MenuItem} #rawLabel: 'Fault' #nameKey: #fixedTap #value: #beFault #hidden: true #labelImage: #(#{UI.ResourceRetriever} #{ToolCommandExample} #fixedTapIcon ) ) ) #(4 ) nil ) ) #(#{UI.MenuItem} #rawLabel: 'Help' #submenu: #(#{UI.Menu} #( #(#{UI.MenuItem} #rawLabel: 'Usage' #value: #explainUsage ) ) #(1 ) nil ) ) ) #(4 ) nil ) decodeAsLiteralArray
minusIconImage "Tools.UIMaskEditor new openOnClass: self andSelector: #minusIconImage" <resource: #image> ^(Image extent: 20@20 depth: 1 bitsPerPixel: 1 palette: MonoMappedPalette blackWhite usingBits: #[255 255 240 0 255 255 240 0 255 255 240 0 255 255 240 0 255 255 240 0 255 255 240 0 255 255 240 0 255 255 240 0 255 255 240 0 240 0 240 0 240 0 240 0 255 255 240 0 255 255 240 0 255 255 240 0 255 255 240 0 255 255 240 0 255 255 240 0 255 255 240 0 255 255 240 0 255 255 240 0])
minusIconMask "Tools.UIMaskEditor new openOnClass: self andSelector: #minusIconMask" <resource: #image> ^(Image extent: 20@20 depth: 1 bitsPerPixel: 1 palette: CoveragePalette monoMaskPalette usingBits: #[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15 255 0 0 15 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0])
offHookImage "Tools.UIMaskEditor new openOnClass: self andSelector: #offHook" <resource: #image> ^(Image extent: 20@20 depth: 2 bitsPerPixel: 2 palette: (Graphics.MappedPalette withColors: ((Core.Array new: 3) at: 1 put: Graphics.ColorValue black; at: 2 put: Graphics.ColorValue red; at: 3 put: Graphics.ColorValue white; yourself)) usingBits: #[170 170 170 170 170 0 0 0 170 170 170 170 170 0 0 0 170 128 0 10 170 0 0 0 170 21 85 82 170 0 0 0 170 16 0 16 42 0 0 0 170 2 170 2 42 0 0 0 170 170 170 170 138 0 0 0 170 170 170 170 42 0 0 0 170 170 170 170 138 0 0 0 170 160 168 42 42 0 0 0 170 161 1 42 138 0 0 0 170 133 85 74 42 0 0 0 170 21 33 82 138 0 0 0 170 21 137 82 42 0 0 0 170 21 33 82 138 0 0 0 170 21 85 80 42 0 0 0 170 0 0 2 170 0 0 0 170 170 170 170 170 0 0 0 170 170 170 170 170 0 0 0 170 170 170 170 170 0 0 0])
offHookMask "Tools.UIMaskEditor new openOnClass: self andSelector: #offHookMask" <resource: #image> ^(Image extent: 20@20 depth: 1 bitsPerPixel: 1 palette: CoveragePalette monoMaskPalette usingBits: #[0 0 0 0 0 0 0 0 7 252 0 0 15 254 0 0 15 255 128 0 14 14 128 0 0 0 64 0 0 0 128 0 0 0 64 0 3 24 128 0 3 248 64 0 7 252 128 0 15 190 64 0 15 94 128 0 15 190 64 0 15 255 128 0 15 254 0 0 0 0 0 0 0 0 0 0 0 0 0 0])
onHookImage "Tools.UIMaskEditor new openOnClass: self andSelector: #onHookImage" <resource: #image> ^(Image extent: 20@20 depth: 2 bitsPerPixel: 2 palette: (Graphics.MappedPalette withColors: ((Core.Array new: 3) at: 1 put: Graphics.ColorValue black; at: 2 put: Graphics.ColorValue red; at: 3 put: Graphics.ColorValue white; yourself)) usingBits: #[170 170 170 170 170 0 0 0 170 170 170 170 170 0 0 0 170 170 170 170 170 0 0 0 170 170 170 170 170 0 0 0 170 170 170 170 170 0 0 0 170 170 170 170 170 0 0 0 170 128 0 10 170 0 0 0 170 21 85 82 170 0 0 0 170 16 0 16 42 0 0 0 170 2 170 2 42 0 0 0 170 160 0 42 138 0 0 0 170 133 85 74 42 0 0 0 170 21 33 82 138 0 0 0 170 21 137 82 42 0 0 0 170 21 33 82 138 0 0 0 170 21 85 80 42 0 0 0 170 0 0 2 170 0 0 0 170 170 170 170 170 0 0 0 170 170 170 170 170 0 0 0 170 170 170 170 170 0 0 0])
onHookMask "Tools.UIMaskEditor new openOnClass: self andSelector: #onHookMask" <resource: #image> ^(Image extent: 20@20 depth: 1 bitsPerPixel: 1 palette: CoveragePalette monoMaskPalette usingBits: #[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 252 0 0 15 254 0 0 15 255 128 0 14 14 128 0 3 248 64 0 7 252 128 0 15 190 64 0 15 94 128 0 15 190 64 0 15 255 128 0 15 254 0 0 0 0 0 0 0 0 0 0 0 0 0 0])
openIconImage "Tools.UIMaskEditor new openOnClass: self andSelector: #openIconImage" <resource: #image> ^(Image extent: 20@20 depth: 2 bitsPerPixel: 2 palette: (Graphics.MappedPalette withColors: ((Core.Array new: 4) at: 1 put: Graphics.ColorValue black; at: 2 put: Graphics.ColorValue white; at: 3 put: (Graphics.ColorValue scaledRed: 8191 scaledGreen: 8191 scaledBlue: 4111); at: 4 put: (Graphics.ColorValue scaledRed: 4111 scaledGreen: 4111 scaledBlue: 0); yourself)) usingBits: #[85 85 85 85 85 0 0 0 85 85 85 85 85 0 0 0 85 85 85 85 85 0 0 0 85 85 85 85 85 0 0 0 85 85 84 5 85 0 0 0 85 85 81 81 21 0 0 0 85 85 85 84 21 0 0 0 84 5 85 80 21 0 0 0 82 160 0 21 85 0 0 0 82 170 170 21 85 0 0 0 82 170 170 21 85 0 0 0 82 168 0 0 5 0 0 0 82 163 255 255 21 0 0 0 82 143 255 252 85 0 0 0 82 63 255 241 85 0 0 0 80 255 255 197 85 0 0 0 80 0 0 21 85 0 0 0 85 85 85 85 85 0 0 0 85 85 85 85 85 0 0 0 85 85 85 85 85 0 0 0])
openIconMask "Tools.UIMaskEditor new openOnClass: self andSelector: #openIconMask" <resource: #image> ^(Image extent: 20@20 depth: 1 bitsPerPixel: 1 palette: CoveragePalette monoMaskPalette usingBits: #[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 28 0 0 0 34 128 0 0 1 128 0 28 3 128 0 63 248 0 0 63 248 0 0 63 248 0 0 63 255 192 0 63 255 128 0 63 255 0 0 63 254 0 0 63 252 0 0 63 248 0 0 0 0 0 0 0 0 0 0 0 0 0 0])
plusIcon "Tools.UIMaskEditor new openOnClass: self andSelector: #plusIcon" <resource: #image> ^(Image extent: 20@20 depth: 1 bitsPerPixel: 1 palette: CoveragePalette monoMaskPalette usingBits: #[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 96 0 0 0 96 0 0 0 96 0 0 0 96 0 0 0 96 0 0 15 255 0 0 15 255 0 0 0 96 0 0 0 96 0 0 0 96 0 0 0 96 0 0 0 96 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0])
toolBar "Tools.MenuEditor new openOnClass: self andSelector: #toolBar" <resource: #menu> ^#(#{UI.Menu} #( #(#{UI.MenuItem} #rawLabel: 'Open' #nameKey: #openButton #value: #openFile #enablementSelector: #anyFileSelected #labelImage: #(#{UI.ResourceRetriever} #{ToolCommandExample} #openIcon ) ) #(#{UI.MenuItem} #rawLabel: 'Add' #value: #addFile #labelImage: #(#{UI.ResourceRetriever} #{ToolCommandExample} #plusIcon ) ) #(#{UI.MenuItem} #rawLabel: 'Delete' #nameKey: #deleteButton #value: #deleteFile #enablementSelector: #anyFileSelected #labelImage: #(#{UI.ResourceRetriever} #{ToolCommandExample} #minusIcon ) ) #(#{UI.MenuItem} #rawLabel: 'Usage' #value: #explainUsage #labelImage: #(#{UI.ResourceRetriever} #{ToolCommandExample} #helpIcon ) ) #(#{UI.MenuItem} #rawLabel: 'Connection' #nameKey: #connection #value: #toggleHook #helpText: 'Connect' ) #(#{UI.MenuItem} #rawLabel: 'Issues' #nameKey: #issues #value: #toggleTap #helpText: 'Fix' ) ) #(3 1 2 ) nil ) decodeAsLiteralArray
</methods> <methods> Examples.ToolCommandExample class <category>interface specs</category>
windowSpec "Tools.UIPainter new openOnClass: self andSelector: #windowSpec" <resource: #canvas> ^#(#{UI.FullSpec} #window: #(#{UI.WindowSpec} #label: 'ToolCommandExample' #min: #(#{Core.Point} 233 200 ) #bounds: #(#{Graphics.Rectangle} 800 600 1033 800 ) #flags: 4 #menu: #menuBar #toolBar: #toolBar ) #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>