[squeak-dev] The Inbox: Tools-ct.1068.mcz

commits at source.squeak.org commits at source.squeak.org
Mon Nov 1 18:01:31 UTC 2021

A new version of Tools was added to project The Inbox:

==================== Summary ====================

Name: Tools-ct.1068
Author: ct
Time: 1 November 2021, 7:01:28.288014 pm
UUID: f6d09127-a2e9-c34e-8573-bc2aa252cf00
Ancestors: Tools-eem.1065

Fixes CustomMenu >> #add:submenu:target:selector:argumentList: and updates example analogously to Morphic-ct.1791.

=============== Diff against Tools-eem.1065 ===============

Item was changed:
  ----- Method: CustomMenu class>>example (in category 'example') -----
  	"CustomMenu example"
  	| menu |
  	menu := CustomMenu new.
  	menu add: 'apples' action: #apples.
  	menu add: 'oranges' action: #oranges.
  	menu addLine.
  	menu addLine.  "extra lines ignored"
  	menu add: 'peaches' action: #peaches.
  	menu addLine.
  	menu add: 'pears' action: #pears.
  	menu addLine.
+ 	menu add: 'test' subMenu: (CustomMenu new
+ 		add: 'foo' action: #inspect;
+ 		yourself) target: 42 selector: #inform: argumentList: #('hello').
+ 	^ menu invokeOn: nil
- 	^ menu startUp: #apples
  "NB:  The following is equivalent to the above, but uses the compact #fromArray: consruct:
  	(CustomMenu fromArray:
  		#(	('apples'		apples)
  			('oranges'		oranges)
  			('peaches'		peaches)
  			('pears'			pears)
  				startUp: #apples"!

Item was changed:
  ----- Method: CustomMenu>>add:action: (in category 'construction') -----
  add: aString action: actionItem
  	"Add the given string as the next menu item. If it is selected, the given action (usually but not necessarily a symbol) will be returned to the client."
  	| s |
  	aString ifNil: [^ self addLine].
  	s := String new: aString size + 2.
  	s at: 1 put: Character space.
  	s replaceFrom: 2 to: s size - 1 with: aString.
  	s at: s size put: Character space.
  	labels addLast: s.
+ 	targets addLast: nil.
+ 	arguments addLast: nil.
  	selections addLast: actionItem.!

Item was changed:
  ----- Method: CustomMenu>>add:subMenu:target:selector:argumentList: (in category 'compatibility') -----
  add: aString subMenu: aMenu target: target selector: aSymbol argumentList: argList
  	"Create a sub-menu with the given label. This isn't really a sub-menu the way Morphic does it; it'll just pop up another menu."
  		add: aString
+ 		target: self
+ 		selector: #invokeSubmenu:target:selector:argumentList:
+ 		argumentList: {aMenu. target. aSymbol. argList asArray}.!
- 		target: aMenu
- 		selector: #invokeOn:
- 		argumentList: argList asArray.!

Item was changed:
  ----- Method: CustomMenu>>add:target:selector:argumentList: (in category 'compatibility') -----
  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 atLast: 1 put: target.
+ 	arguments atLast: 1 put: argList asArray
- 	targets addLast: target.
- 	arguments addLast: argList asArray

Item was changed:
  ----- Method: CustomMenu>>invokeOn:orSendTo: (in category 'invocation') -----
  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 := nil.
+ 		((targets := self targets) notNil and: [anIndex <= targets size])
+ 			ifTrue: [recipient := targets at: anIndex].
+ 		recipient
+ 			ifNil: [recipient := targetObject].
- 		recipient := ((targets := self targets) isEmptyOrNil or: [anIndex > targets size])
- 			ifTrue:
- 				[targetObject]
- 			ifFalse:
- 				[targets at: anIndex].
  		aSelector numArgs = 0
  				[recipient perform: aSelector orSendTo: anObject]
  				[recipient perform: aSelector withArguments: (self arguments at: anIndex)]]!

Item was added:
+ ----- Method: CustomMenu>>invokeSubmenu:target:selector:argumentList: (in category 'invocation') -----
+ invokeSubmenu: aMenu target: target selector: aSymbol argumentList: argList
+ 	target perform: aSymbol withArguments: argList.
+ 	^ aMenu invokeOn: target!

More information about the Squeak-dev mailing list