From VisualWorks®, 7.6 of February 1, 2008 on February 1, 2008 at 12:47:41 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>MenuModifyExample</name> <environment>Examples</environment> <super>UI.ApplicationModel</super> <private>false</private> none jobTitle benefit <imports></imports> <category>Examples-Help</category> <attributes> <package>MenuModify-Example</package> </attributes> </class> <comment> Examples.MenuModifyExample
MenuModifyExample demonstrates a technique for modifying a menu while the application is running.
</comment> <methods> Examples.MenuModifyExample <category>actions</category>
addTitle "Prompt for a new job title and add it to the list." | newTitle jMenu | newTitle := Dialog request: 'New title?'. newTitle isEmpty ifTrue: [^self]. jMenu := self builder menuAt: #jobTitlesMenu. jMenu addItemLabel: newTitle value: newTitle asSymbol. self jobTitle value: newTitle asSymbol.
deleteTitle "Prompt for a title and remove it from the list." | jMenu removableTitles title item | jMenu := self builder menuAt: #jobTitlesMenu. "Don't permit the president to be overthrown." removableTitles := jMenu labels reject: [ :nextTitle | nextTitle = 'President']. title := Dialog choose: 'Delete Title' fromList: removableTitles values: removableTitles lines: 8 cancel: [^nil] for: ScheduledControllers activeController view. item := jMenu menuItemLabeled: title. jMenu removeItem: item. "If the deleted title is showing, pick the first title." self jobTitle value == title asSymbol ifTrue: [self jobTitle value: #President].
</methods> <methods> Examples.MenuModifyExample <category>change messages</category>
adjustBenefitList "Hide benefit items that are not available to the currently selected job title." | bMenu item | bMenu := self builder menuAt: #benefitsMenu. item := bMenu menuItemLabeled: 'Golden Parachute'. "Only the President gets the Golden Parachute." self jobTitle value == #President ifTrue: [bMenu unhideItem: item] ifFalse: [bMenu hideItem: item].
</methods> <methods> Examples.MenuModifyExample <category>aspects</category>
benefit ^benefit
jobTitle ^jobTitle
</methods> <methods> Examples.MenuModifyExample <category>initialize-release</category>
initialize | jMenu bMenu | jMenu := self class jobTitlesMenu. jobTitle := (jMenu valueForMenuItem: (jMenu menuItemAt: 1)) asValue. jobTitle onChangeSend: #adjustBenefitList to: self. bMenu := self class benefitsMenu. benefit := (bMenu valueForMenuItem: (bMenu menuItemAt: 1)) asValue.
</methods> <methods> Examples.MenuModifyExample class <category>resources</category>
benefitsMenu | mb menu | mb := MenuBuilder new. mb add: 'Health Insurance' -> #health; add: 'Retirement Fund' -> #retirement; add: 'Life Insurance' -> #life; add: 'Stock Options' -> #stock; add: 'Golden Parachute' -> #parachute. menu := mb menu. menu backgroundColor: ColorValue chartreuse. (menu menuItemLabeled: 'Golden Parachute') color: ColorValue red. ^menu
jobTitlesMenu "UIMenuEditor new openOnClass: self andSelector: #jobTitlesMenu" <resource: #menu> ^#(#Menu #( #(#MenuItem #label: 'President' ) #(#MenuItem #label: 'Vice President' ) #(#MenuItem #label: 'Manager' ) #(#MenuItem #label: 'Programmer' ) ) #(4 ) #(#President #'Vice President' #Manager #Programmer ) ) decodeAsLiteralArray
</methods> <methods> Examples.MenuModifyExample class <category>interface specs</category>
windowSpec "UIPainter new openOnClass: self andSelector: #windowSpec" <resource: #canvas> ^#(#FullSpec #window: #(#WindowSpec #label: 'MenuModifyExample' #min: #(#Point 318 157 ) #max: #(#Point 318 157 ) #bounds: #(#Rectangle 664 227 982 384 ) ) #component: #(#SpecCollection #collection: #( #(#MenuButtonSpec #layout: #(#Rectangle 97 19 277 52 ) #model: #jobTitle #menu: #jobTitlesMenu ) #(#LabelSpec #layout: #(#Point 12 23 ) #label: 'Job Title' ) #(#LabelSpec #layout: #(#Point 12 112 ) #label: 'Benefit' ) #(#MenuButtonSpec #layout: #(#Rectangle 97 108 277 141 ) #model: #benefit #menu: #benefitsMenu ) #(#ActionButtonSpec #layout: #(#Point 91 56 ) #model: #addTitle #label: 'Add Title' #defaultable: true ) #(#ActionButtonSpec #layout: #(#Point 189 56 ) #model: #deleteTitle #label: 'Delete Title' #defaultable: true ) ) ) )
</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>