'From Squeak3.3alpha of 18 January 2002 [latest update: #4921] on 22 July 2002 at 6:39:07 pm'! "Change Set: paramFixups-sw Date: 22 July 2002 Author: Scott Wallace Published to 3.3a as 4922paramFixups-sw.cs. ¥ Fixes a glitch in backing out of renaming a script -- we had not been allowing the user to retain an existing name if it had a colon in it. ¥ If you change a parameter type in such a manner that it introduces a type error for any tile phrases in the script that called for the parameter when it was a different type, the tiles fix themselves up to keep everything type-rosy. ¥ Adds a menu item to TilePad's halo menu allowing you to restore the default literal tile for the particular type. This allows you, albeit somewhat obscurely, to revert a Parameter tile to a plain numeric tile, for example."! !ParameterTile methodsFor: 'type' stamp: 'sw 7/22/2002 17:48'! assureTypeStillValid "Consider the possibility that the parameter type of my surrounding method has changed and that hence I no longer represent a possible value for the parameter of the script. If this condition obtains, then banish me in favor of a default literal tile of the correct type" (self ownerThatIsA: TilePadMorph) ifNotNilDo: [:aPad | aPad type = self scriptEditor typeForParameter ifFalse: [aPad setToBearDefaultLiteral]]! ! !Player methodsFor: 'costume' stamp: 'sw 7/22/2002 18:23'! ceaseHavingAParameterFor: aSelector "Make the script represented by aSelector cease bearing a parameter" | newSel | self renameScript: aSelector newSelector: (newSel _ (aSelector copyWithout: $:) asSymbol). (self scriptEditorFor: newSel) assureParameterTilesValid! ! !Player methodsFor: 'costume' stamp: 'sw 7/22/2002 17:44'! setParameterFor: aSelector toType: aTypeSymbol "Set the parameter type for the given selector" | aUniclassScript | aTypeSymbol isEmptyOrNil ifTrue: [^ self]. (self typeforParameterFor: aSelector) = aTypeSymbol ifTrue: [^ self]. aUniclassScript _ self class scripts at: aSelector. aUniclassScript argumentVariables first variableType: aTypeSymbol. aUniclassScript currentScriptEditorDo: [:aScriptEditor | aScriptEditor assureParameterTilesValid]. self updateAllViewersAndForceToShow: #scripts ! ! !Player methodsFor: 'scripts-kernel' stamp: 'sw 7/22/2002 18:09'! acceptableScriptNameFrom: originalString forScriptCurrentlyNamed: currentName "Produce an acceptable script name, derived from the current name, for the receiver. This method will always return a valid script name that will be suitable for use in the given situation, though you might not like its beauty sometimes." | aString stemAndSuffix proscribed stem suffix withoutColon currentNumArgs withColon | withoutColon _ originalString copyWithoutAll: {$:. $ }. (currentName notNil and: [(currentName copyWithout: $:) = withoutColon]) ifTrue: [^ currentName]. "viz. no change; otherwise, the #respondsTo: check gets in the way" currentNumArgs _ currentName ifNil: [0] ifNotNil: [currentName numArgs]. aString _ withoutColon asIdentifier: false. "get an identifier starting with a lowercase letter" stemAndSuffix _ aString stemAndNumericSuffix. proscribed _ #(self super thisContext costume costumes dependents true false size). stem _ stemAndSuffix first. suffix _ stemAndSuffix last. withoutColon _ aString asSymbol. withColon _ (withoutColon, ':') asSymbol. [(proscribed includes: withoutColon) or: [self respondsTo: withoutColon] or: [self respondsTo: withColon] or: [Smalltalk includesKey: withoutColon] or: [Smalltalk includesKey: withColon]] whileTrue: [suffix _ suffix + 1. withoutColon _ (stem, suffix printString) asSymbol. withColon _ (withoutColon, ':') asSymbol]. ^ currentNumArgs = 0 ifTrue: [withoutColon] ifFalse: [withColon]! ! !ScriptEditorMorph methodsFor: 'dropping/grabbing' stamp: 'sw 7/22/2002 17:49'! assureParameterTilesValid "Make certain that parameter tiles in my interior are still type valid; replace any that now intimate type errors" self isTextuallyCoded ifFalse: [(self allMorphs select: [:m | m isKindOf: ParameterTile]) do: [:aTile | aTile assureTypeStillValid]. self install]! ! !ScriptEditorMorph methodsFor: 'testing' stamp: 'sw 7/22/2002 18:24'! typeForParameter "Answer a symbol representing the type of my parameter" scriptName numArgs > 0 ifTrue: [(playerScripted class scripts at: scriptName ifAbsent: [nil]) ifNotNilDo: [:aScript | ^ aScript argumentVariables first variableType]]. ^ #Error! ! !TilePadMorph methodsFor: 'miscellaneous' stamp: 'sw 7/22/2002 18:38'! addCustomMenuItems: aCustomMenu hand: aHandMorph "Add custom menu items to the menu" super addCustomMenuItems: aCustomMenu hand: aHandMorph. aCustomMenu add: 'restore default tile' action: #restoreDefaultTile.! ! !TilePadMorph methodsFor: 'miscellaneous' stamp: 'sw 7/22/2002 18:32'! restoreDefaultTile "Restore the receiver to showing only its default literal tile" self setToBearDefaultLiteral. (self ownerThatIsA: ScriptEditorMorph) ifNotNilDo: [:aScriptEditor | aScriptEditor install]! ! !TilePadMorph methodsFor: 'miscellaneous' stamp: 'sw 7/22/2002 17:50'! setToBearDefaultLiteral "Set the receiver so that it contains only a tile reflecting the default literal value for a pad of this type" self removeAllMorphs. self addMorphBack: (Vocabulary vocabularyForType: type) defaultArgumentTile! ! !UniclassScript methodsFor: 'script editor' stamp: 'sw 7/22/2002 17:44'! currentScriptEditorDo: aBlock "Evaluate a block on behalf of my current script editor, if any" currentScriptEditor ifNotNil: [aBlock value: currentScriptEditor]! !