Source

Translate Text / PRHActionTextView.m

Full commit
//
//  PRHActionTextView.m
//  Translate Text
//
//  Created by Peter Hosey on 2008-06-21.
//  Copyright 2008 Peter Hosey. All rights reserved.
//

#import "PRHActionTextView.h"

@implementation PRHActionTextView

- target {
	return target;
}
- (void) setTarget:newTarget {
	target = newTarget;
}

- (SEL) action {
	return action;
}
- (void) setAction:(SEL)newAction {
	action = newAction;
}

#pragma mark Events

- (void) keyDown:(NSEvent *)event {
	enum {
		enterKey = 76,
		tabKey = 48,
	};
	NSWindow *window;
	if ([event keyCode] == enterKey) {
		window = [self window];
		[window makeFirstResponder:[window contentView]];

		[NSApp sendAction:action to:target from:self];
	} else if ([event keyCode] == tabKey) {
		NSUInteger modifiers = [event modifierFlags] & NSDeviceIndependentModifierFlagsMask;
		if (modifiers == 0)
			[[self window] selectNextKeyView:nil];
		else if (modifiers == NSShiftKeyMask)
			[[self window] selectPreviousKeyView:nil];
	} else {
		[super keyDown:event];
	}
}

@end