'From Squeak3.2gamma of 14 January 2002 [latest update: #4653] on 14 January 2002 at 8:25:20 pm'! "Change Set: DoitButton Date: 14 January 2002 Author: David N. Smith harvested by sd Add DoItSimpleButton that is like a SimpleButtonMorph except that evaluate a string when pressed"! SimpleButtonMorph subclass: #DoitButtonMorph instanceVariableNames: 'doitString ' classVariableNames: '' poolDictionaries: '' category: 'Morphic-Widgets'! !DoitButtonMorph commentStamp: '' prior: 0! I am a button, like SimpleButtonMorph, except that I evaluate a string when pressed. I can be used to add buttons on the screen wherever you want, and which do most anything a DoIt will do. The Halo menu lets the label and doit string be changed when you wish. DoitButtonMorph new openInWorld Useful variations are: DoitButtonMorph new label: 'Open Selector Browser'; doitString: 'SelectorBrowser new open'; openInWorld and, to exit a project: DoitButtonMorph new label: ' ^ '; doitString: 'Project returnToPreviousProject'; openInWorld! !SimpleButtonMorph methodsFor: 'menu' stamp: 'dns 11/1/2001 18:13'! addButtonCustomMenuItems: aCustomMenu hand: aHandMorph (target isKindOf: BookMorph) ifTrue: [aCustomMenu add: 'set page sound' action: #setPageSound:. aCustomMenu add: 'set page visual' action: #setPageVisual:] ifFalse: [aCustomMenu add: 'change action selector' action: #setActionSelector. aCustomMenu add: 'change arguments' action: #setArguments. aCustomMenu add: 'change when to act' action: #setActWhen. ((self world rootMorphsAt: aHandMorph targetOffset) size > 1) ifTrue: [aCustomMenu add: 'set target' action: #setTarget:]]. ! ! !SimpleButtonMorph methodsFor: 'menu' stamp: 'dns 11/1/2001 18:13'! addCustomMenuItems: aCustomMenu hand: aHandMorph super addCustomMenuItems: aCustomMenu hand: aHandMorph. self addLabelItemsTo: aCustomMenu hand: aHandMorph. self addButtonCustomMenuItems: aCustomMenu hand: aHandMorph! ! !DoitButtonMorph methodsFor: 'initialization' stamp: 'dns 11/2/2001 17:43'! initializeAllButLabel super initializeAllButLabel. target _ self. actionSelector _ #runDoit. doitString := 'Smalltalk beep'.! ! !DoitButtonMorph methodsFor: 'initialization' stamp: 'dns 11/2/2001 17:44'! setDefaultLabel self label: 'Doit Button'.! ! !DoitButtonMorph methodsFor: 'events' stamp: 'dns 10/31/2001 17:54'! doButtonAction "Perform the action of this button. Subclasses may override this method. The default behavior is to send the button's actionSelector to its target object with its arguments." Cursor normal showWhile: [ self runDoit ]. ! ! !DoitButtonMorph methodsFor: 'events' stamp: 'dns 10/31/2001 17:41'! runDoit (doitString isNil or: [doitString isEmpty]) ifTrue: [ ^ self ]. Compiler evaluate: doitString! ! !DoitButtonMorph methodsFor: 'menu' stamp: 'dns 11/1/2001 18:15'! addButtonCustomMenuItems: aCustomMenu hand: aHandMorph (target isKindOf: BookMorph) ifTrue: [aCustomMenu add: 'set page sound' action: #setPageSound:. aCustomMenu add: 'set page visual' action: #setPageVisual:] ifFalse: [aCustomMenu add: 'change doit string' action: #setDoitString. aCustomMenu add: 'change when to act' action: #setActWhen]. ! ! !DoitButtonMorph methodsFor: 'menu' stamp: 'dns 10/31/2001 17:50'! setDoitString doitString _ FillInTheBlank request: 'Please type the DoIt string.' initialAnswer: doitString! ! !DoitButtonMorph methodsFor: 'accessing' stamp: 'dns 10/31/2001 17:59'! doitString ^ doitString! ! !DoitButtonMorph methodsFor: 'accessing' stamp: 'dns 10/31/2001 17:58'! doitString: aString doitString := aString! ! !DoitButtonMorph methodsFor: 'copying' stamp: 'dns 10/31/2001 18:41'! veryDeepInner: deepCopier "Copy all of my instance variables. Some need to be not copied at all, but shared. Warning!!!! Every instance variable defined in this class must be handled. We must also implement veryDeepFixupWith:. See DeepCopier class comment." super veryDeepInner: deepCopier. doitString _ doitString veryDeepCopyWith: deepCopier! ! !DoitButtonMorph class methodsFor: 'as yet unclassified' stamp: 'dns 10/31/2001 17:33'! defaultNameStemForInstances ^ 'doitButton'! ! !DoitButtonMorph class methodsFor: 'example1' stamp: 'dns 10/31/2001 18:01'! example1 " DoitButtonMorph example1 " DoitButtonMorph new label: 'Press Me Now'; doitString: 'Smalltalk beep'; openInWorld! !