'From etoys2.2 of 24 September 2007 [latest update: #1745] on 1 November 2007 at 3:56:41 pm'! "Change Set: showSource-sw Date: 1 November 2007 Author: Scott Wallace React to the hitting of the show-source key on the xo by putting up a show-source menu allowing access to the inner Squeak world..."! !ParagraphEditor methodsFor: 'editing keys' stamp: 'sw 10/31/2007 02:25'! shiftEnclose: characterStream "Insert or remove bracket characters around the current selection. Flushes typeahead." | char left right startIndex stopIndex oldSelection which text | char _ sensor keyboard. char = $9 ifTrue: [ char _ $( ]. char = $, ifTrue: "[ char _ $< ]" [self closeTypeIn. ActiveWorld showSourceKeyHit. ^ true]. char = $[ ifTrue: [ char _ ${ ]. char = $' ifTrue: [ char _ $" ]. char asciiValue = 27 ifTrue: [ char _ ${ ]. "ctrl-[" self closeTypeIn. startIndex _ self startIndex. stopIndex _ self stopIndex. oldSelection _ self selection. which _ '([<{"''' indexOf: char ifAbsent: [1]. left _ '([<{"''' at: which. right _ ')]>}"''' at: which. text _ paragraph text. ((startIndex > 1 and: [stopIndex <= text size]) and: [(text at: startIndex-1) = left and: [(text at: stopIndex) = right]]) ifTrue: ["already enclosed; strip off brackets" self selectFrom: startIndex-1 to: stopIndex. self replaceSelectionWith: oldSelection] ifFalse: ["not enclosed; enclose by matching brackets" self replaceSelectionWith: (Text string: (String with: left), oldSelection string ,(String with: right) emphasis: emphasisHere). self selectFrom: startIndex+1 to: stopIndex]. ^true! ! !PasteUpMorph methodsFor: 'world menu' stamp: 'sw 11/1/2007 15:53'! buildShowSourceMenu: evt "Build and answer the show-source menu in response to the given event." ^(TheWorldMenu new world: self project: (self project ifNil: [Project current]) "mvc??" hand: evt hand) buildShowSourceMenu! ! !PasteUpMorph methodsFor: 'world menu' stamp: 'sw 11/1/2007 15:54'! putUpShowSourceMenu: evt title: aTitle "Put up a menu in response to the show-source button being hit" | menu | self bringTopmostsToFront. "put up the show-source menu" menu _ (TheWorldMenu new adaptToWorld: ActiveWorld) buildShowSourceMenu. menu addTitle: aTitle. menu popUpEvent: evt in: self. ^ menu! ! !PasteUpMorph methodsFor: 'world menu' stamp: 'sw 10/18/2007 14:32'! showSourceKeyHit "The user hit the 'show source' key on the XO. Our current take on this is simply to put up the world menu..." ^ self putUpShowSourceMenu: ActiveEvent title: 'etoys source' translated! ! !PasteUpMorph methodsFor: '*green' stamp: 'sw 11/1/2007 15:54'! keystrokeInWorld: evt "A keystroke was hit when no keyboard focus was set, so it is sent here to the world instead." | aChar isCmd ascii | aChar _ evt keyCharacter. (ascii _ aChar asciiValue) = 27 ifTrue: "escape key -- either put up a menu, or simply quietly gobble it" [^ Preferences escapeKeyProducesMenu ifTrue: [self putUpWorldMenuFromEscapeKey]]. (evt commandKeyPressed and: [ascii = 44]) "show-source on XO" ifTrue: [^ self showSourceKeyHit]. (evt controlKeyPressed not and: [(#(1 4 8 28 29 30 31 32 47) includes: ascii) "home, end, backspace, arrow keys, space, slash." and: [self keyboardNavigationHandler notNil]]) ifTrue: [self keyboardNavigationHandler navigateFromKeystroke: aChar]. isCmd _ evt commandKeyPressed and: [Preferences cmdKeysInText]. (evt commandKeyPressed and: [Preferences eToyFriendly]) ifTrue: [(aChar == $W) ifTrue: [^ self putUpWorldMenu: evt]]. (isCmd and: [Preferences honorDesktopCmdKeys]) ifTrue: [^ self dispatchCommandKeyInWorld: aChar event: evt]. "It was unhandled. Remember the keystroke." self lastKeystroke: evt keyString. self triggerEvent: #keyStroke! ! !PluggableListMorph methodsFor: '*green' stamp: 'sw 10/31/2007 02:34'! modifierKeyPressed: aChar "The user typed a character into the list pane, while holding down a modifier key." | args | (aChar = $, and: [ActiveEvent commandKeyPressed]) ifTrue: [^ ActiveWorld showSourceKeyHit]. (aChar asciiValue = 92 and: [ActiveEvent commandKeyPressed]) ifTrue: ["cycle windows" ^ SystemWindow rotateWindows]. keystrokeActionSelector isNil ifTrue: [^nil]. args := keystrokeActionSelector numArgs. args = 1 ifTrue: [^model perform: keystrokeActionSelector with: aChar]. args = 2 ifTrue: [^model perform: keystrokeActionSelector with: aChar with: self]. ^self error: 'keystrokeActionSelector must be a 1- or 2-keyword symbol'! ! !SystemWindow class methodsFor: '*green' stamp: 'sw 7/14/2006 01:26'! rotateWindows "Rotate the z-ordering of the windows." ActiveEvent shiftPressed ifTrue: [self sendTopWindowBackOne] ifFalse: [self sendTopWindowToBack]! ! !SystemWindow class methodsFor: '*green' stamp: 'sw 7/15/2006 03:14'! sendTopWindowBackOne "Rotate the window-list one downward, i.e., make the bottommost one be the active one, pushing the receiver to next-to-topmost." | dows | dows := ActiveWorld submorphs select: [:m | m isSystemWindow]. dows ifNotEmpty: [dows last expand; comeToFront]! ! !TextMorphEditor methodsFor: '*green' stamp: 'sw 10/18/2007 22:19'! showSourceKeyHit: characterStream "The user hit the show-source key (ctrl-a)" Smalltalk isMorphic ifTrue: [ActiveWorld showSourceKeyHit]. ^ true! ! !TheWorldMenu methodsFor: 'construction' stamp: 'sw 10/31/2007 02:53'! buildShowSourceMenu "Build the menu that is put up when the show-source button is hit." | menu | menu _ MenuMorph new defaultTarget: self. menu commandKeyHandler: self. self colorForDebugging: menu. menu addStayUpItem. self fillIn: menu from: { {'open...' translated. { self . #openWindow } }. {'windows...' translated. { self . #windowsDo } }. {'changes...' translated. { self . #changesDo } }}. self fillIn: menu from: { {'help...' translated. { self . #helpDo }. 'puts up a menu of useful items for updating the system, determining what version you are running, and much else' translated}. {'appearance...' translated. { self . #appearanceDo }. 'put up a menu offering many controls over appearance.' translated}}. self fillIn: menu from: { {'do...' translated. { Utilities . #offerCommonRequests} . 'put up an editible list of convenient expressions, and evaluate the one selected.' translated}}. self fillIn: menu from: { nil. {'objects (o)' translated. { #myWorld . #activateObjectsTool } . 'A tool for finding and obtaining many kinds of objects' translated}. {'new morph...' translated. { self . #newMorph }. 'Offers a variety of ways to create new objects' translated}. nil. {'authoring tools...' translated. { self . #scriptingDo } . 'A menu of choices useful for authoring' translated}. {'playfield options...' translated. { self . #playfieldDo } . 'A menu of options pertaining to this object as viewed as a playfield' translated}. {'flaps...' translated. { self . #flapsDo } . 'A menu relating to use of flaps. For best results, use "keep this menu up"' translated}. {'projects...' translated. { self . #projectDo }. 'A menu of commands relating to use of projects' translated}. {'debug...' translated. { self . #debugDo } . 'a menu of debugging items' translated}. nil. {'edit this menu' translated. { self . #editShowSourceMenu } . 'open a code editor on the method that defines this menu' translated}}. ^ menu! ! !TheWorldMenu methodsFor: 'as yet unclassified' stamp: 'sw 10/31/2007 02:04'! editShowSourceMenu "Invoked from menu, opens up a single-msg browser on the method that defines the show-source menu." | mr | mr _ MethodReference new setStandardClass: TheWorldMenu methodSymbol: #buildShowSourceMenu. self systemNavigation browseMessageList: {mr} name: 'show-source menu' translated autoSelect: nil! !