'From Squeak3.3alpha of 12 January 2002 [latest update: #4761] on 17 February 2002 at 5:45:42 am'! "Change Set: customMenu-sumim Date: 17 February 2002 Author: Masato Sumi Allows CustomMenus to have target-lists and argument-lists, in support of the file-list registry architecture vis a vis the 'all possible services' menu. Tweaks by Scott Wallace"! SelectionMenu subclass: #CustomMenu instanceVariableNames: 'labels dividers lastDivider title targets arguments ' classVariableNames: '' module: #(Squeak MVC Menus)! !CustomMenu methodsFor: 'initialize-release' stamp: 'sumim 2/10/2002 01:26'! initialize labels _ OrderedCollection new. selections _ OrderedCollection new. dividers _ OrderedCollection new. lastDivider _ 0. targets _ OrderedCollection new. arguments _ OrderedCollection new ! ! !CustomMenu methodsFor: 'invocation' stamp: 'sw 2/17/2002 04:48'! invokeOn: targetObject "Pop up this menu and return the result of sending to the target object the selector corresponding to the menu item selected by the user. Return nil if no item is selected. If the chosen selector has arguments, obtain them from my arguments" ^ self invokeOn: targetObject orSendTo: nil! ! !CustomMenu methodsFor: 'invocation' stamp: 'sw 2/17/2002 04:38'! invokeOn: targetObject orSendTo: anObject "Pop up this menu and return the result of sending to the target object the selector corresponding to the menu item selected by the user. Return nil if no item is selected. If the chosen selector has arguments, obtain appropriately. If the recipient does not respond to the resulting message, send it to the alternate object provided" | aSelector anIndex recipient | ^ (aSelector _ self startUp) ifNotNil: [anIndex _ self selection. recipient _ (targets _ self targets) isEmptyOrNil ifTrue: [targetObject] ifFalse: [targets at: anIndex]. aSelector numArgs == 0 ifTrue: [recipient perform: aSelector orSendTo: anObject] ifFalse: [recipient perform: aSelector withArguments: (self arguments at: anIndex)]]! ! !CustomMenu methodsFor: 'compatibility' stamp: 'sumim 2/10/2002 01:23'! add: aString target: target selector: aSymbol argument: arg "Append a menu item with the given label. If the item is selected, it will send the given selector to the target object with the given argument." self add: aString target: target selector: aSymbol argumentList: (Array with: arg)! ! !CustomMenu methodsFor: 'compatibility' stamp: 'sumim 2/10/2002 01:18'! add: aString target: target selector: aSymbol argumentList: argList "Append a menu item with the given label. If the item is selected, it will send the given selector to the target object with the given arguments. If the selector takes one more argument than the number of arguments in the given list, then the triggering event is supplied as as the last argument." self add: aString action: aSymbol. targets addLast: target. arguments addLast: argList asArray ! ! !CustomMenu methodsFor: 'compatibility' stamp: 'sumim 2/10/2002 01:21'! addService: aService for: serviceUser "Append a menu item with the given service. If the item is selected, it will perform the given service." self add: aService label target: aService selector: aService requestSelector argument: serviceUser ! ! !CustomMenu methodsFor: 'compatibility' stamp: 'sumim 2/10/2002 01:19'! addServices2: services for: served extraLines: linesArray services withIndexDo: [:service :i | self add: service label target: service selector: service requestSelector argument: (service getArgumentsFrom: served). (linesArray includes: i) | service useLineAfter ifTrue: [self addLine] ]! ! !CustomMenu methodsFor: 'compatibility' stamp: 'sumim 2/10/2002 01:20'! addServices: services for: served extraLines: linesArray services withIndexDo: [:service :i | self addService: service for: served. (linesArray includes: i) | service useLineAfter ifTrue: [self addLine]]! ! !CustomMenu methodsFor: 'compatibility' stamp: 'sw 2/16/2002 00:57'! arguments "Answer my arguments, initializing them to an empty collection if they're found to be nil." ^ arguments ifNil: [arguments _ OrderedCollection new]! ! !CustomMenu methodsFor: 'compatibility' stamp: 'sw 2/16/2002 00:57'! targets "Answer my targets, initializing them to an empty collection if found to be nil" ^ targets ifNil: [targets _ OrderedCollection new]! ! !MouseMenuController methodsFor: 'pluggable menus' stamp: 'sw 2/17/2002 04:35'! pluggableYellowButtonActivity: shiftKeyState "Invoke the model's popup menu." | menu | (menu _ self getPluggableYellowButtonMenu: shiftKeyState) ifNil: [sensor waitNoButton] ifNotNil: [self terminateAndInitializeAround: [menu invokeOn: model orSendTo: self]]! ! !CustomMenu reorganize! ('initialize-release' initialize title:) ('construction' add:action: addLine addList: balloonTextForLastItem: labels:font:lines: labels:lines:selections:) ('invocation' invokeOn: invokeOn:defaultSelection: invokeOn:orSendTo: startUp startUp: startUp:withCaption: startUpWithCaption:) ('compatibility' add:target:selector:argument: add:target:selector:argumentList: addService:for: addServices2:for:extraLines: addServices:for:extraLines: arguments targets) ('private' build preSelect:) !