Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!spool.mu.edu!uunet!mcsun!cernvax!chx400!unizh!bsch From: bsch@ifi.unizh.ch (bruno schaeffer) Newsgroups: comp.lang.smalltalk Subject: Re: Mac Cut/Paste Message-ID: <1991Jun19.191123.5134@ifi.unizh.ch> Date: 19 Jun 91 19:11:23 GMT References: <1991Jun18.133240.22383@msuinfo.cl.msu.edu> Organization: University of Zurich, Department of Computer Science Lines: 174 This is the source code (ST-80 R4) for Command-Copy/Cut/Paste on the Mac. It also assigns often used menu commands to the function keys on the extended keyboard. You can see the mapping from the method initializeAdditionalDT: File in the modifications to ParagraphEditor class, ParagraphEditor and StringHolderController. After then execute the expression "ParagraphEditor initializeDispatchTable.". The expression is enclosed in the comment for initializeDispatchTable. Bruno Schaeffer UBILAB (UBS Informatics Laboratory) Union Bank of Switzerland P.O. Box CH-8021 Zuerich e-mail: bsch@CHZH10.ubs.ubs.arcom.ch 'From Objectworks(r)\Smalltalk, Release 4 of 25 October 1990 on 26 April 1991 at 11:02:32 am'! !ParagraphEditor class methodsFor: 'class initialization'! initializeAdditionalDT: aDispatchTable "Initialize the Dispatch Table with additional keys" aDispatchTable bindValue: #undo:key: to: #F1. aDispatchTable bindValue: #cut:key: to: #F2. aDispatchTable bindValue: #copy:key: to: #F3. aDispatchTable bindValue: #paste:key: to: #F4. aDispatchTable bindValue: #accept:key: to: #F5. aDispatchTable bindValue: #cancel:key: to: #F6. aDispatchTable bindValue: #doIt:key: to: #F9. aDispatchTable bindValue: #printIt:key: to: #F10. aDispatchTable bindValue: #inspectIt:key: to: #F11! initializeDispatchTable "Initialize the keyboard dispatch table" "ParagraphEditor initializeDispatchTable." Keyboard := DispatchTable new. Keyboard defaultForCharacters: #normalCharacter:key:. Keyboard defaultForNonCharacters: #ignoreInput:key:. Keyboard bindValue: #backspace:key: to: Cut. Keyboard bindValue: #paste:key: to: Paste. Keyboard bindValue: #backspace:key: to: BS. Keyboard bindValue: #backWord:key: to: Ctrlw. Keyboard bindValue: #displayIfTrue:key: to: Ctrlt. Keyboard bindValue: #displayIfFalse:key: to: Ctrlf. Keyboard bindValue: #displayDate:key: to: Ctrld. Keyboard bindValue: #displayColonEqual:key: to: Ctrlg. '<''"[{(' do: [:char | Keyboard bindValue: #enclose:key: to: ESC followedBy: char]. 'sSuUbBiIx' do: [:char | Keyboard bindValue: #changeEmphasis:key: to: ESC followedBy: char]. Keyboard bindValue: #miniFormat:key: to: ESC followedBy: $f. Keyboard bindValue: #selectCurrentTypeIn:key: to: ESC followedBy: Tab. self initializeAdditionalDT: Keyboard! ! 'From Objectworks(r)\Smalltalk, Release 4 of 25 October 1990 on 26 April 1991 at 9:06:36 am'! !ParagraphEditor methodsFor: 'editing'! cancel: characterStream key: aChar "Relay to method cancel" self cancel. ^true! copy: characterStream key: aChar "Copy the current text selection." self copySelection. ^true! dispatchKeyboardEvent: aKeyboardEvent withTypeAhead: typeAhead "Dispatch on the keyboard character as it comes in" | currentCharacter val newEvent | newEvent := self checkCommandKey: aKeyboardEvent. CurrentEvent := newEvent. currentCharacter := CurrentEvent keyValue. val := nil. self dispatchTable add: currentCharacter do: [:char :sel | val := self perform: sel with: typeAhead with: char]. val == nil ifTrue: ["If the dispatch block was not evaluated, make the text selection visible again" self select. val := true]. ^val! doIt: characterStream key: aChar "Ignore in ParagraphEditor, to be overwritten in subclass" ^self ignoreInput: characterStream key: aChar! inspectIt: characterStream key: aChar "Ignore in ParagraphEditor, to be overwritten in subclass" ^self ignoreInput: characterStream key: aChar! printIt: characterStream key: aChar "Ignore in ParagraphEditor, to be overwritten in subclass" ^self ignoreInput: characterStream key: aChar! undo: characterStream key: aChar "Relay to method undo" self undo. ^true! ! !ParagraphEditor methodsFor: 'private'! checkCommandKey: aKeyboardEvent "for Mac only: check for Cmd-x, Cmd-c, and Cmd-v and return corresp. fkey" aKeyboardEvent metaState = 8 ifTrue: [aKeyboardEvent keyValue = $x ifTrue: [^KeyboardEvent code: #F2 meta: 0]. aKeyboardEvent keyValue = $c ifTrue: [^KeyboardEvent code: #F3 meta: 0]. aKeyboardEvent keyValue = $v ifTrue: [^KeyboardEvent code: #F4 meta: 0]]. ^aKeyboardEvent! ! 'From Objectworks(r)\Smalltalk, Release 4 of 25 October 1990 on 26 April 1991 at 9:09:42 am'! !StringHolderController methodsFor: 'editing'! doIt: characterStream key: aChar "" self doIt. ^true! inspectIt: characterStream key: aChar "" self inspectIt. ^true! printIt: characterStream key: aChar "" self printIt. ^true! !