4 // Created by Quentin Carnicelli on Sun Aug 03 2003.
5 // Copyright (c) 2003 iThink Software. All rights reserved.
8 #import "ITKeyComboPanel.h"
11 #import "ITKeyCombo.h"
12 #import "ITKeyBroadcaster.h"
13 #import "ITHotKeyCenter.h"
16 #import "NSObjectAdditions.h"
19 @implementation ITKeyComboPanel
21 static id _sharedKeyComboPanel = nil;
25 if( _sharedKeyComboPanel == nil )
27 _sharedKeyComboPanel = [[self alloc] init];
30 [_sharedKeyComboPanel releaseOnTerminate];
34 return _sharedKeyComboPanel;
39 return [self initWithWindowNibName: @"ITKeyComboPanel"];
44 [[NSNotificationCenter defaultCenter] removeObserver: self];
52 [[NSNotificationCenter defaultCenter]
54 selector: @selector( noteKeyBroadcast: )
55 name: ITKeyBroadcasterKeyEvent
59 - (void)_refreshContents
62 [mComboField setStringValue: [mKeyCombo description]];
65 [mTitleField setStringValue:mKeyName];
72 [self window]; //Force us to load
74 [self _refreshContents];
75 [[self window] center];
76 [self showWindow: self];
77 resultCode = [[NSApplication sharedApplication] runModalForWindow: [self window]];
83 - (void)runModalForHotKey: (ITHotKey*)hotKey
87 [self setKeyBindingName: [hotKey name]];
88 [self setKeyCombo: [hotKey keyCombo]];
90 resultCode = [self runModal];
92 if( resultCode == NSOKButton )
94 [hotKey setKeyCombo: [self keyCombo]];
95 [[ITHotKeyCenter sharedCenter] registerHotKey: hotKey];
101 - (void)setKeyCombo: (ITKeyCombo*)combo
106 [self _refreshContents];
109 - (ITKeyCombo*)keyCombo
114 - (void)setKeyBindingName: (NSString*)name
119 [self _refreshContents];
122 - (NSString*)keyBindingName
129 - (IBAction)ok: (id)sender
131 [[NSApplication sharedApplication] stopModalWithCode: NSOKButton];
134 - (IBAction)cancel: (id)sender
136 [[NSApplication sharedApplication] stopModalWithCode: NSCancelButton];
139 - (IBAction)clear: (id)sender
141 [self setKeyCombo: [ITKeyCombo clearKeyCombo]];
142 [[NSApplication sharedApplication] stopModalWithCode: NSOKButton];
145 - (void)noteKeyBroadcast: (NSNotification*)note
147 ITKeyCombo* keyCombo;
149 keyCombo = [[note userInfo] objectForKey: @"keyCombo"];
151 [self setKeyCombo: keyCombo];