[comp.lang.smalltalk] Mac Cut/Paste

sticken@pleiades.cps.msu.edu (06/18/91)

How can I get the normal macintosh cut/paste (<apple>C and <apple>V) using PP
ST r4? Its pretty annoying to a mac user new to smalltalk to have to keep using
the menu for cut/paste operations.

Thanks,
  ---jon---

benson@milton.u.washington.edu (Dan Benson) (06/19/91)

In article <1991Jun18.133240.22383@msuinfo.cl.msu.edu> sticken@pleiades.cps.msu.edu writes:
>How can I get the normal macintosh cut/paste (<apple>C and <apple>V) using PP
>ST r4? Its pretty annoying to a mac user new to smalltalk to have to keep using
>the menu for cut/paste operations.
>
>Thanks,
>  ---jon---

Jon,

This may not be what you want but I have an extended keyboard on my
Mac and I've assigned the Cut, Copy, Paste, and other common functions to
the function keys on my keyboard.  Below are the modifications to
the Paragraph Editor methods required to make this work.  It's not perfect
but it's handy.  Perhaps you can get some idea from this to do what you
really want to do.

Good luck,

Dan Benson

-=-=-=-=-
'From Objectworks(r)\Smalltalk, Release 4 of 25 October 1990 on 3 June 1991 at 7:26:02 pm'!



!ParagraphEditor methodsFor: 'DANs ADDITIONS'!

accept: characterStream key: aChar
	self accept.
	^true!

again: characterStream key: aChar
	self again.
	^true!

copy: characterStream key: aChar
	self copySelection.
	^nil!

doIt: characterStream key: aChar
	self doIt.
	^true!

inspectIt: characterStream key: aChar
	self inspectIt.
	^true!

printIt: characterStream key: aChar
	self printIt.
	^true!

undo: characterStream key: aChar
	self undo.
	^true! !

!ParagraphEditor class methodsFor: 'class initialization'!

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.

"Here are my additions"
	Keyboard bindValue: #undo:key:  to: #F1.
	Keyboard bindValue: #cut:key:  to: #F2.
	Keyboard bindValue: #copy:key:  to: #F3.
	Keyboard bindValue: #paste:key:  to: #F4.
	Keyboard bindValue: #again:key:  to: #F5.
	Keyboard bindValue: #doIt:key:  to: #F6.
	Keyboard bindValue: #printIt:key:  to: #F7.
	Keyboard bindValue: #inspectIt:key:  to: #F8.
	Keyboard bindValue: #accept:key:  to: #F9.

	'<''"[{(' 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! !



-- 
| Dan Benson                        benson@ee.washington.edu    |
| Dept. of Elec. Engr., FT-10                                   |
| University of Washington          (206) 685-7567              |
| Seattle, WA  98195                                            |

bsch@ifi.unizh.ch (bruno schaeffer) (06/20/91)

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! !