cog/Preferences/General/HotKeyPane.m

98 lines
3.8 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
{
[self setName:NSLocalizedStringFromTableInBundle(@"Hot Keys", nil, [NSBundle bundleForClass:[self class]], @"") ];
2006-09-04 18:06:23 +00:00
[self setIcon:@"hot_keys"];
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];
}
/*- (void)windowDidBecomeKey:(id)notification
{
if ([notification object] == [view window]) {
NSLog(@"BECAME KEY: %@", notification);
[playHotKeyControl startObserving];
[prevHotKeyControl startObserving];
[nextHotKeyControl startObserving];
}
}
*/
- (void)windowDidResignKey:(id)notification
{
if ([notification object] == [view window]) {
NSLog(@"RESIGNED KEY: %@", notification);
[playHotKeyControl stopObserving];
[prevHotKeyControl stopObserving];
[nextHotKeyControl stopObserving];
}
}
- (IBAction) grabPlayHotKey:(id)sender
{
[playHotKeyControl startObserving];
}
- (IBAction) grabPrevHotKey:(id)sender
{
[prevHotKeyControl startObserving];
}
- (IBAction) grabNextHotKey:(id)sender
{
[nextHotKeyControl startObserving];
}
- (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"];
}
[sender stopObserving];
2006-09-04 18:06:23 +00:00
}
@end