cog/Preferences/General/HotKeyPane.m

120 lines
4.7 KiB
Matlab
Raw Normal View History

2006-09-04 18:06:23 +00:00
//
// HotKeyPane.m
// Preferences
//
// Created by Vincent Spader on 9/4/06.
// Copyright 2006 Vincent Spader. All rights reserved.
2006-09-04 18:06:23 +00:00
//
#import "HotKeyPane.h"
2006-09-10 21:27:20 +00:00
#import "NDHotKeyEvent.h"
2006-09-04 18:06:23 +00:00
@implementation HotKeyPane
- (void)awakeFromNib
{
2006-09-10 21:27:20 +00:00
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object: [view window]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object: [view window]];
[prevHotKeyControl setKeyCode: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPreviousKeyCode"] ];
[prevHotKeyControl setCharacter: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPreviousCharacter"] ];
[prevHotKeyControl setModifierFlags: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPreviousModifiers"] ];
[prevHotKeyControl updateStringValue];
[nextHotKeyControl setKeyCode: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyNextKeyCode"] ];
[nextHotKeyControl setCharacter: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyNextCharacter"] ];
[nextHotKeyControl setModifierFlags: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyNextModifiers"] ];
[nextHotKeyControl updateStringValue];
[playHotKeyControl setKeyCode: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPlayKeyCode"] ];
[playHotKeyControl setCharacter: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPlayCharacter"] ];
[playHotKeyControl setModifierFlags: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPlayModifiers"] ];
[playHotKeyControl updateStringValue];
[spamHotKeyControl setKeyCode: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeySpamKeyCode"] ];
[spamHotKeyControl setCharacter: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeySpamCharacter"] ];
[spamHotKeyControl setModifierFlags: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeySpamModifiers"] ];
[spamHotKeyControl updateStringValue];
2006-09-10 21:27:20 +00:00
}
- (NSString *)title
{
return NSLocalizedStringFromTableInBundle(@"Hot Keys", nil, [NSBundle bundleForClass:[self class]], @"");
}
- (NSImage *)icon
{
return [[[NSImage alloc] initWithContentsOfFile:[[NSBundle bundleForClass:[self class]] pathForImageResource:@"hot_keys"]] autorelease];
}
2006-09-10 21:27:20 +00:00
/*- (void)windowDidBecomeKey:(id)notification
{
if ([notification object] == [view window]) {
[playHotKeyControl startObserving];
[prevHotKeyControl startObserving];
[nextHotKeyControl startObserving];
}
}
*/
- (void)windowDidResignKey:(id)notification
{
if ([notification object] == [view window]) {
[playHotKeyControl stopObserving];
[prevHotKeyControl stopObserving];
[nextHotKeyControl stopObserving];
[spamHotKeyControl stopObserving];
2006-09-10 21:27:20 +00:00
}
}
- (IBAction) grabPlayHotKey:(id)sender
{
[playHotKeyControl startObserving];
}
- (IBAction) grabPrevHotKey:(id)sender
{
[prevHotKeyControl startObserving];
}
- (IBAction) grabNextHotKey:(id)sender
{
[nextHotKeyControl startObserving];
}
- (IBAction) grabSpamHotKey:(id)sender
{
[spamHotKeyControl startObserving];
}
2006-09-10 21:27:20 +00:00
- (IBAction) hotKeyChanged:(id)sender
{
if (sender == playHotKeyControl) {
[[NSUserDefaults standardUserDefaults] setInteger:[playHotKeyControl character] forKey:@"hotKeyPlayCharacter"];
[[NSUserDefaults standardUserDefaults] setInteger:[playHotKeyControl modifierFlags] forKey:@"hotKeyPlayModifiers"];
[[NSUserDefaults standardUserDefaults] setInteger:[playHotKeyControl keyCode] forKey:@"hotKeyPlayKeyCode"];
}
else if (sender == prevHotKeyControl) {
[[NSUserDefaults standardUserDefaults] setInteger:[prevHotKeyControl character] forKey:@"hotKeyPreviousCharacter"];
[[NSUserDefaults standardUserDefaults] setInteger:[prevHotKeyControl modifierFlags] forKey:@"hotKeyPreviousModifiers"];
[[NSUserDefaults standardUserDefaults] setInteger:[prevHotKeyControl keyCode] forKey:@"hotKeyPreviousKeyCode"];
}
else if (sender == nextHotKeyControl) {
[[NSUserDefaults standardUserDefaults] setInteger:[nextHotKeyControl character] forKey:@"hotKeyNextCharacter"];
[[NSUserDefaults standardUserDefaults] setInteger:[nextHotKeyControl modifierFlags] forKey:@"hotKeyNextModifiers"];
[[NSUserDefaults standardUserDefaults] setInteger:[nextHotKeyControl keyCode] forKey:@"hotKeyNextKeyCode"];
}
else if (sender == spamHotKeyControl) {
[[NSUserDefaults standardUserDefaults] setInteger:[spamHotKeyControl character] forKey:@"hotKeySpamCharacter"];
[[NSUserDefaults standardUserDefaults] setInteger:[spamHotKeyControl modifierFlags] forKey:@"hotKeySpamModifiers"];
[[NSUserDefaults standardUserDefaults] setInteger:[spamHotKeyControl keyCode] forKey:@"hotKeySpamKeyCode"];
}
2006-09-10 21:27:20 +00:00
[sender stopObserving];
2006-09-04 18:06:23 +00:00
}
@end