'From Squeak5.1 of 23 August 2016 [latest update: #16548] on 29 August 2016 at 5:15:50 pm'! !TextEditor methodsFor: 'editing keys' stamp: 'sumim 11/14/2015 10:08'! changeEmphasis: aKeyboardEvent "Change the emphasis of the current selection or prepare to accept characters with the change in emphasis. Emphasis change amounts to a font change. Keeps typeahead." "control 0..9 -> 0..9" | keyCode attribute oldAttributes index thisSel colors extras | keyCode := ('0123456789-=' indexOf: aKeyboardEvent keyCharacter ifAbsent: [ 0]) - 1. keyCode = -1 ifTrue: [keyCode := '!!@#$%' indexOf: aKeyboardEvent keyCharacter ifAbsent: [0]]. oldAttributes := paragraph text attributesAt: self pointIndex. thisSel := self selection. "Decipher keyCodes for Command 0-9..." (keyCode between: 1 and: 5) ifTrue: [attribute := TextFontChange fontNumber: keyCode]. keyCode = 6 ifTrue: [ colors := #(#black #magenta #red #yellow #green #blue #cyan #white). extras := self emphasisExtras. index := UIManager default chooseFrom:colors , #('choose color...' ), extras lines: (Array with: colors size + 1). index = 0 ifTrue: [^true]. index <= colors size ifTrue: [attribute := TextColor color: (Color perform: (colors at: index))] ifFalse: [ index := index - colors size - 1. "Re-number!!!!!!" index = 0 ifTrue: [attribute := self chooseColor] ifFalse:[^self handleEmphasisExtra: index with: aKeyboardEvent] "handle an extra"]]. (keyCode between: 7 and: 11) ifTrue: [ aKeyboardEvent shiftPressed ifTrue: [ keyCode = 10 ifTrue: [attribute := TextKern kern: -1]. keyCode = 11 ifTrue: [attribute := TextKern kern: 1]] ifFalse: [ attribute := TextEmphasis perform: (#(#bold #italic #narrow #underlined #struckOut) at: keyCode - 6). oldAttributes do: [:att | (att dominates: attribute) ifTrue: [attribute turnOff]]]]. keyCode = 0 ifTrue: [attribute := TextEmphasis normal]. attribute ifNotNil: [ thisSel size = 0 ifTrue: [ "only change emphasisHere while typing" self insertTypeAhead. emphasisHere := Text addAttribute: attribute toArray: oldAttributes ] ifFalse: [ self replaceSelectionWith: (thisSel asText addAttribute: attribute) ]]. ^true! ! !SmalltalkEditor methodsFor: 'editing keys' stamp: 'sumim 11/14/2015 11:42'! changeEmphasis: characterStream "Change emphasis without styling if necessary" | okToStyle | okToStyle := (morph respondsTo: #editView) and: [morph editView okToStyle]. okToStyle ifTrue: [('12345' includes: characterStream keyCharacter) ifTrue: [^self typeMethodArgument: characterStream]]. okToStyle ifFalse: [^super changeEmphasis: characterStream]. ^morph editView styler evaluateWithoutStyling: [super changeEmphasis: characterStream].! ! !SmalltalkEditor methodsFor: 'private' stamp: 'nice 8/3/2011 20:47'! typeMethodArgument: aKeyboardEvent "Replace the current text selection with the name of the method argument represented by the keyCode." | keyCode | keyCode := ('1234' indexOf: aKeyboardEvent keyCharacter ifAbsent: [1]). self addString: (self methodArgument: keyCode). ^ false! ! !SmalltalkEditor class methodsFor: 'keyboard shortcut tables' stamp: 'sumim 8/29/2016 16:10'! initializeCmdKeyShortcuts "Initialize the (unshifted) command-key (or alt-key) shortcut table." "NOTE: if you don't know what your keyboard generates, use Sensor kbdTest" "SmalltalkEditor initialize" | cmds | super initializeCmdKeyShortcuts. cmds := #($b #browseIt: $d #doIt: $i #inspectIt: $l #cancel: $m #implementorsOfIt: $n #sendersOfIt: $o #spawnIt: $p #printIt: $q #querySymbol: $s #save: ). 1 to: cmds size by: 2 do: [ : i | cmdActions at: (cmds at: i) asciiValue + 1 put: (cmds at: i + 1)]. "Set up type-method argument hot keys, 1-4.." "dispatch in #changeEmphasis: 11-13-2015 sumim" "'1234' do: [ : eachKeyboardChar | cmdActions at: eachKeyboardChar asciiValue + 1 put: #typeMethodArgument: ]"! ! !SmalltalkEditor class methodsFor: 'keyboard shortcut tables' stamp: 'sumim 8/29/2016 16:11'! initializeShiftCmdKeyShortcuts "Initialize the shift-command-key (or control-key) shortcut table." "NOTE: if you don't know what your keyboard generates, use Sensor kbdTest" "wod 11/3/1998: Fix setting of cmdMap for shifted keys to actually use the capitalized versions of the letters. TPR 2/18/99: add the plain ascii values back in for those VMs that don't return the shifted values." "SmalltalkEditor initialize" | cmds | super initializeShiftCmdKeyShortcuts. '!!@#$%' do: [:char | shiftCmdActions at: char asciiValue + 1 put: #changeEmphasis:]. cmds := #( $a argAdvance: $b browseItHere: $d debugIt: $e methodStringsContainingIt: $f displayIfFalse: $g fileItIn: $i exploreIt: $n referencesToIt: $s invokePrettyPrint: $t displayIfTrue: $v pasteInitials: $w methodNamesContainingIt: ). 1 to: cmds size by: 2 do: [ :i | shiftCmdActions at: ((cmds at: i) asciiValue + 1) put: (cmds at: i + 1). "plain keys" shiftCmdActions at: ((cmds at: i) asciiValue - 32 + 1) put: (cmds at: i + 1). "shifted keys" shiftCmdActions at: ((cmds at: i) asciiValue - 96 + 1) put: (cmds at: i + 1). "ctrl keys" ].! ! !TextMorph methodsFor: 'initialization' stamp: 'sumim 11/14/2015 19:37'! beAllFont: aFont textStyle := (TextStyle named: aFont familyName asSymbol) copy. textStyle defaultFontIndex: (textStyle fontArray indexOf: aFont). self releaseCachedState; changed! ! "Postscript:" SmalltalkEditor initialize. !