'From Squeak3.1alpha of 5 February 2001 [latest update: #3668] on 20 February 2001 at 3:48:49 am'! "Change Set: univGotchas-sw Date: 20 February 2001 Author: Scott Wallace Fixes several things that got broken in universal tiles by yesterday's big scriptor update."! !MethodWithInterface methodsFor: 'initialization' stamp: 'sw 2/20/2001 03:29'! isTextuallyCoded "Answer whether the receiver is in a textually-coded state. A leftover from much earlier times, this is a vacuous backstop" ^ false! ! !MethodWithInterface methodsFor: 'updating' stamp: 'sw 2/20/2001 03:43'! revertToLastSavedTileVersionFor: anEditor "revert to the last saved tile version. Only for universal tiles." anEditor removeAllButFirstSubmorph. anEditor insertUniversalTiles. anEditor showingMethodPane: false! ! !MethodWithInterface methodsFor: 'updating' stamp: 'sw 2/20/2001 03:41'! saveScriptVersion: timeStamp "Save the tile script version if I do that sort of thing"! ! !Player methodsFor: 'scripts-kernel' stamp: 'sw 2/20/2001 02:28'! isEmptyTileScript: aScriptName "Answer whether the script of the given name is an empty classic tile script. Presently disused -- formerly it was all too easy to propagate many empty tile scripts but this difficulty has receded considerably with recent changes, so this has no senders other than from an unusual menu item, and will perhaps die soon" | aUserScript | Preferences universalTiles ifTrue: [^ false]. aUserScript _ self class userScriptForPlayer: self selector: aScriptName. ^ (aUserScript instantiatedScriptEditorForPlayer: self) isEmpty ! ! !Player methodsFor: 'scripts-kernel' stamp: 'sw 2/20/2001 03:36'! newScriptorAround: aPhrase "Sprout a scriptor around aPhrase, thus making a new script. aPhrase may either be a PhraseTileMorph (classic tiles 1997-2001) or a SyntaxMorph (2001 onward)" | aScriptEditor aUniclassScript tw blk | aUniclassScript _ self class permanentUserScriptFor: self unusedScriptName player: self. aScriptEditor _ aUniclassScript instantiatedScriptEditorForPlayer: self. Preferences universalTiles ifTrue: [aScriptEditor install. aScriptEditor insertUniversalTiles. "Gets an empty SyntaxMorph for a MethodNode" tw _ aScriptEditor findA: TwoWayScrollPane. aPhrase ifNotNil: [blk _ tw scroller firstSubmorph "MethodNode" lastSubmorph "BlockNode". blk addMorphFront: aPhrase. aPhrase accept]. aScriptEditor hResizing: #shrinkWrap; vResizing: #shrinkWrap; cellPositioning: #topLeft] ifFalse: [aPhrase ifNotNil: [aScriptEditor phrase: aPhrase] "does an install" ifNil: [aScriptEditor install]]. self class allSubInstancesDo: [:anInst | anInst scriptInstantiationForSelector: aUniclassScript selector]. "The above assures the presence of a ScriptInstantiation for the new selector in all siblings" self updateAllViewersAndForceToShow: #scripts. ^ aScriptEditor! ! !ScriptEditorMorph methodsFor: 'buttons' stamp: 'sw 2/20/2001 00:43'! install "Accept the current classic tiles as the new source code for the script. In the case of universalTiles, initialize the method and its methodInterface if not already done." Preferences universalTiles ifFalse: [self removeSpaces]. scriptName ifNotNil: [playerScripted acceptScript: self topEditor for: scriptName asSymbol]! ! !ScriptEditorMorph methodsFor: 'other' stamp: 'sw 2/20/2001 03:22'! insertUniversalTiles "Insert universal tiles for the method at hand" self removeAllButFirstSubmorph. self insertUniversalTilesForClass: playerScripted class selector: scriptName! ! !ScriptEditorMorph methodsFor: 'other' stamp: 'sw 2/20/2001 00:37'! methodString "Answer the source-code string for the receiver. This is for use by classic tiles, but is also used in universal tiles to formulate an initial method declaration for a nascent user-defined script; in universalTiles mode, the codeString (at present anyway) is empty -- the actual code derives from the SyntaxMorph in that case" ^ String streamContents: [:aStream | aStream nextPutAll: scriptName; cr; cr; tab. aStream nextPutAll: self codeString] ! ! !ScriptEditorMorph methodsFor: 'other' stamp: 'sw 2/20/2001 03:30'! modernize "If the receiver appears to date from the past, try to fix it up" Preferences universalTiles ifFalse: [(self isTextuallyCoded and: [self showingMethodPane not]) ifTrue: ["Fix up old guys that are not showing the code in place" self showSourceInScriptor]]! ! !ScriptEditorMorph methodsFor: 'other' stamp: 'sw 2/20/2001 03:31'! offerScriptorMenu "Put up a menu in response to the user's clicking in the menu-request area of the scriptor's heaer" | aMenu count | self modernize. aMenu _ MenuMorph new defaultTarget: self. aMenu addTitle: scriptName asString. Preferences universalTiles ifFalse: [count _ self savedTileVersionsCount. self showingMethodPane ifFalse: "currently showing tiles" [aMenu add: 'show code textually' action: #showSourceInScriptor. count > 0 ifTrue: [aMenu add: 'revert to tile version...' action: #revertScriptVersion]. aMenu add: 'save this version' action: #saveScriptVersion] ifTrue: "current showing textual source" [count >= 1 ifTrue: [aMenu add: 'revert to tile version' action: #revertToTileVersion]]]. aMenu addList: #( - ('destroy this script' destroyScript) ('rename this script' renameScript) ('button to fire this script' tearOfButtonToFireScript) ('edit balloon help for this script' editMethodDescription) - ('fires per tick...' chooseFrequency) ('explain status alternatives' explainStatusAlternatives) - ('hand me a tile for self' tileForSelf) ('hand me a "random number" tile' handUserRandomTile) ('hand me a "button down?" tile' handUserButtonDownTile) ('hand me a "button up?" tile' handUserButtonUpTile) ). aMenu popUpInWorld: self currentWorld. " ('add parameter to this script' addParameter)" ! ! !ScriptEditorMorph methodsFor: 'other' stamp: 'sw 2/20/2001 00:34'! tileRows "If using classic tiles, return a collection of arrays of Tiles in which each array is one line of tiles. (John Maloney's original design and code)." | rows r | rows _ OrderedCollection new. Preferences universalTiles ifTrue: [^ rows]. firstTileRow to: submorphs size do: [:i | r _ submorphs at: i. r submorphCount > 0 ifTrue: [rows addLast: r submorphs]]. ^ rows ! ! !ScriptEditorMorph methodsFor: 'tiles from method' stamp: 'sw 2/20/2001 02:03'! fromExistingMethod: aSelector forPlayer: aPlayer "Create tiles for this method. " self initialize. playerScripted _ aPlayer. self setMorph: aPlayer costume scriptName: aSelector. self insertUniversalTiles! ! !SyntaxMorph methodsFor: 'dropping/grabbing' stamp: 'sw 2/20/2001 03:39'! morphToDropInPasteUp: aPasteUp "If property #beScript is true, create a scriptor around me." | actualObject itsSelector aScriptor adjustment handy tw blk | (self valueOfProperty: #beScript ifAbsent: [false]) ifFalse: [^ self]. self removeProperty: #beScript. (actualObject _ self actualObject) ifNil: [^ self]. actualObject assureUniClass. itsSelector _ self userScriptSelector. aScriptor _ itsSelector isEmptyOrNil ifFalse: [adjustment _ 0@0. actualObject scriptEditorFor: itsSelector] ifTrue: [adjustment _ 60 @ 20. actualObject newScriptorAround: self]. handy _ aPasteUp primaryHand. aScriptor ifNotNil: [aScriptor position: handy position - adjustment. aPasteUp addMorphFront: aScriptor. "do this early so can find World" aScriptor showingMethodPane ifFalse: [(tw _ aScriptor findA: TwoWayScrollPane) ifNil: [itsSelector ifNil: ["blank script" tw _ aScriptor findA: TwoWayScrollPane. blk _ tw scroller firstSubmorph "MethodNode" lastSubmorph "BlockNode". blk addMorphFront: self]]. aScriptor hResizing: #shrinkWrap; vResizing: #shrinkWrap; cellPositioning: #topLeft]]. ^ aScriptor ifNil: [self] ! ! ScriptEditorMorph removeSelector: #recreateTileVersion!