1 #import "ITKeyComboPanel.h"
4 #import "ITKeyBroadcaster.h"
5 #import "ITHotKeyCenter.h"
7 @implementation ITKeyComboPanel
9 static id _sharedKeyComboPanel = nil;
12 if (!_sharedKeyComboPanel) {
13 _sharedKeyComboPanel = [[self alloc] init];
15 return _sharedKeyComboPanel;
19 return [self initWithWindowNibName:@"ITKeyComboPanel"];
23 [[NSNotificationCenter defaultCenter] removeObserver:self];
28 - (void)windowDidLoad {
29 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(noteKeyBroadcast:) name:ITKeyBroadcasterKeyEvent object:mKeyBcaster];
32 - (void)_refreshContents {
34 [mComboField setStringValue:[mKeyCombo description]];
37 [mTitleField setStringValue:mKeyName];
44 [self window]; //Force us to load
46 [self _refreshContents];
47 [[self window] center];
48 [self showWindow:self];
49 resultCode = [[NSApplication sharedApplication] runModalForWindow:[self window]];
55 - (void)runModalForHotKey:(ITHotKey *)hotKey {
58 [self setKeyBindingName:[hotKey name]];
59 [self setKeyCombo:[hotKey keyCombo]];
61 resultCode = [self runModal];
63 if (resultCode == NSOKButton) {
64 [hotKey setKeyCombo:[self keyCombo]];
65 [[ITHotKeyCenter sharedCenter] registerHotKey:hotKey];
69 - (void)setKeyCombo:(ITKeyCombo *)combo {
70 [mKeyCombo autorelease];
71 mKeyCombo = [combo retain];
72 [self _refreshContents];
75 - (ITKeyCombo *)keyCombo {
79 - (void)setKeyBindingName:(NSString *)name {
80 [mKeyName autorelease];
81 mKeyName = [name retain];
82 [self _refreshContents];
85 - (NSString *)keyBindingName {
89 - (IBAction)ok:(id)sender {
90 [[NSApplication sharedApplication] stopModalWithCode:NSOKButton];
93 - (IBAction)cancel:(id)sender {
94 [[NSApplication sharedApplication] stopModalWithCode:NSCancelButton];
97 - (IBAction)clear:(id)sender {
98 [self setKeyCombo:[ITKeyCombo clearKeyCombo]];
99 [[NSApplication sharedApplication] stopModalWithCode:NSOKButton];
102 - (void)noteKeyBroadcast:(NSNotification *)note {
103 ITKeyCombo *keyCombo = [[note userInfo] objectForKey:@"keyCombo"];
104 [self setKeyCombo:keyCombo];