From VisualWorks®, 7.6 of February 1, 2008 on February 1, 2008 at 12:49:11 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>MenuPragma2Example</name> <environment>Examples</environment> <super>UI.ApplicationModel</super> <private>false</private> none classes textStyle readOnly comment <imports></imports> <category>Examples-Help</category> <attributes> <package>MenuPragma2-Example</package> </attributes> </class> <comment> Examples.MenuPragma2Example
As a variation of Editor1Example, MenuPragma2Example demonstrates use of a menu bar using a computed submenu pragma.
</comment> <methods> Examples.MenuPragma2Example <category>actions</category>
alignCenter | widget style | widget := (self builder componentAt: #comment) widget. style := widget textStyle copy. style alignment: 2. widget textStyle: style. widget invalidate.
alignLeft | widget style | widget := (self builder componentAt: #comment) widget. style := widget textStyle copy. style alignment: 0. widget textStyle: style. widget invalidate.
alignRight | widget style | widget := (self builder componentAt: #comment) widget. style := widget textStyle copy. style alignment: 1. widget textStyle: style. widget invalidate.
</methods> <methods> Examples.MenuPragma2Example <category>change messages</category>
changedClass "When the list selection changes, update the comment view." | selectedClass txt start wrapper | selectedClass := self classes selection. selectedClass isNil ifTrue: [self comment value: '' asText] ifFalse: [ txt := (selectedClass asQualifiedReference value) comment. self comment value: txt. "Find and highlight the class name in the text." start := txt indexOfSubCollection: selectedClass asString startingAt: 1. start > 0 ifTrue: [ wrapper := (self builder componentAt: #comment). wrapper widget controller selectAndScrollFrom: start to: start + selectedClass asString size - 1. wrapper takeKeyboardFocus]].
changedReadOnly | c | c := (self builder componentAt: #comment) widget controller. c readOnly: (self readOnly value).
changedStyle "A text style was selected -- apply it to the current selection in the comment." | c selectedText style | "Get the selected text." c := (builder componentAt: #comment) widget controller. selectedText := c selection. "If nothing is selected, take no action." selectedText isEmpty ifTrue: [^self]. "If 'Plain' was selected, remove all emphases; otherwise add the new emphasis." style := self textStyle value. style == #plain ifTrue: [selectedText emphasizeAllWith: nil] ifFalse: [ selectedText addEmphasis: (Array with: style) removeEmphasis: nil allowDuplicates: false]. "Ask the controller to insert the modified text, then update the view." c replaceSelectionWith: selectedText. c view resetSelections. c view invalidate.
</methods> <methods> Examples.MenuPragma2Example <category>aspects</category>
classes ^classes
comment ^comment
readOnly ^readOnly
textStyle ^textStyle
</methods> <methods> Examples.MenuPragma2Example <category>initialize-release</category>
initialize super initialize. comment := '' asValue. classes := SelectionInList with: Core classNames. textStyle := #plain asValue. textStyle onChangeSend: #changedStyle to: self. readOnly := false asValue
</methods> <methods> Examples.MenuPragma2Example <category>interface opening</category>
postBuildWith: aBuilder (aBuilder menuAt: #menuBar) augmentFrom: self class to: self class menuName: #menuBar for: self
</methods> <methods> Examples.MenuPragma2Example class <category>resources</category>
alignCenterImage ^(ToolbarIconLibrary visualFor: #alignVCenter)
alignLeftImage ^(ToolbarIconLibrary visualFor: #alignLeft)
alignRightImage ^(ToolbarIconLibrary visualFor: #alignRight)
textStylesMenu "UIMenuEditor new openOnClass: self andSelector: #textStylesMenu" | mb | mb := MenuBuilder new. mb add: 'Plain' -> #plain; add: 'Bold' -> #bold; add: 'Italic' -> #italic; add: 'Underlined' -> #underline. ^mb menu
</methods> <methods> Examples.MenuPragma2Example <category>menus</category>
emphasisChoices "Emphasize the text selected with an emphasis from this menu" <computedSubmenu:'Emphasis' nameKey: #emphasis menu: #(menuBar text) position:10.02> | mb | mb := MenuBuilder new. mb add: 'Plain' -> [textStyle value: #plain]; add: 'Bold' -> [textStyle value: #bold]; add: 'Italic' -> [textStyle value:#italic]; add: 'Underlined' -> [textStyle value:#underline]. ^mb menu
styleChoices "Select a text style from a styles submenu" <computedSubmenu:'Styles' nameKey: #styles menu: #(menuBar text) position:10.03> | styles editor | styles := TextAttributes styles asArray. editor := (builder componentAt: #comment) widget. ^Menu labelArray: styles values: (styles collect: [:style | [editor textStyle: (TextAttributes styleNamed: style). editor resetSelections invalidate]])
</methods> <methods> Examples.MenuPragma2Example class <category>resources</category>
menuBar "Tools.MenuEditor new openOnClass: self andSelector: #menuBar" <resource: #menu> ^#(#{UI.Menu} #( #(#{UI.MenuItem} #rawLabel: 'Text' #nameKey: #text #submenu: #(#{UI.Menu} #( #(#{UI.MenuItem} #rawLabel: 'Alignment' #submenu: #(#{UI.Menu} #( #(#{UI.MenuItem} #rawLabel: 'Left' #value: #alignLeft #labelImage: #(#{UI.ResourceRetriever} nil #alignLeftImage ) ) #(#{UI.MenuItem} #rawLabel: 'Center' #value: #alignCenter #labelImage: #(#{UI.ResourceRetriever} nil #alignCenterImage ) ) #(#{UI.MenuItem} #rawLabel: 'Right' #value: #alignRight #labelImage: #(#{UI.ResourceRetriever} nil #alignRightImage ) ) ) #(3 ) nil ) ) ) #(1 ) nil ) ) ) #(1 ) nil ) decodeAsLiteralArray
</methods> <methods> Examples.MenuPragma2Example class <category>interface specs</category>
windowSpec "Tools.UIPainter new openOnClass: self andSelector: #windowSpec" <resource: #canvas> ^#(#{UI.FullSpec} #window: #(#{UI.WindowSpec} #label: 'Editor Menu Example' #min: #(#{Core.Point} 497 262 ) #max: #(#{Core.Point} 1128 900 ) #bounds: #(#{Graphics.Rectangle} 800 600 1297 1010 ) #flags: 4 #menu: #menuBar ) #component: #(#{UI.SpecCollection} #collection: #( #(#{UI.TextEditorSpec} #layout: #(#{Graphics.LayoutFrame} 0 0.249497 60 0 0 0.995976 0 0.997561 ) #name: #comment #model: #comment #tabRequiresControl: true ) #(#{UI.LabelSpec} #layout: #(#{Graphics.LayoutOrigin} 5 0.25 40 0 ) #label: 'Class Comment' ) #(#{UI.LabelSpec} #layout: #(#{Core.Point} 5 40 ) #label: 'Class Names' ) #(#{UI.ActionButtonSpec} #layout: #(#{Graphics.LayoutFrame} 47 0.25 5 0 69 0.25 27 0 ) #model: #alignLeft #label: #alignLeftImage #hasCharacterOrientedLabel: false ) #(#{UI.ActionButtonSpec} #layout: #(#{Graphics.LayoutFrame} 73 0.25 5 0 95 0.25 27 0 ) #model: #alignCenter #label: #alignCenterImage #hasCharacterOrientedLabel: false ) #(#{UI.ActionButtonSpec} #layout: #(#{Graphics.LayoutFrame} 98 0.25 5 0 120 0.25 27 0 ) #model: #alignRight #label: #alignRightImage #hasCharacterOrientedLabel: false ) #(#{UI.CheckBoxSpec} #layout: #(#{Graphics.LayoutOrigin} 252 0.25 4 0 ) #model: #readOnly #callbacksSpec: #(#{UI.UIEventCallbackSubSpec} #valueChangeSelector: #changedReadOnly ) #label: 'Read Only' ) #(#{UI.SequenceViewSpec} #layout: #(#{Graphics.LayoutFrame} 1 0 60 0 0 0.25 -1 1 ) #flags: 15 #model: #classes #callbacksSpec: #(#{UI.UIEventCallbackSubSpec} #valueChangeSelector: #changedClass ) ) #(#{UI.MenuButtonSpec} #layout: #(#{Graphics.LayoutFrame} 140 0.25 5 0 222 0.25 23 0 ) #model: #textStyle #label: 'Emphasis' #menu: #textStylesMenu ) ) ) )
</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>