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];
46 [mTitleFormat release];
53 mTitleFormat = [[mTitleField stringValue] retain];
55 [[NSNotificationCenter defaultCenter]
57 selector: @selector( noteKeyBroadcast: )
58 name: ITKeyBroadcasterKeyEvent
62 - (void)_refreshContents
65 [mComboField setStringValue: [mKeyCombo description]];
68 [mTitleField setStringValue: [NSString stringWithFormat: mTitleFormat, mKeyName]];
75 [self window]; //Force us to load
77 [self _refreshContents];
78 [[self window] center];
79 [self showWindow: self];
80 resultCode = [[NSApplication sharedApplication] runModalForWindow: [self window]];
86 - (void)runModalForHotKey: (ITHotKey*)hotKey
90 [self setKeyBindingName: [hotKey name]];
91 [self setKeyCombo: [hotKey keyCombo]];
93 resultCode = [self runModal];
95 if( resultCode == NSOKButton )
97 [hotKey setKeyCombo: [self keyCombo]];
98 [[ITHotKeyCenter sharedCenter] registerHotKey: hotKey];
104 - (void)setKeyCombo: (ITKeyCombo*)combo
109 [self _refreshContents];
112 - (ITKeyCombo*)keyCombo
117 - (void)setKeyBindingName: (NSString*)name
122 [self _refreshContents];
125 - (NSString*)keyBindingName
132 - (IBAction)ok: (id)sender
134 [[NSApplication sharedApplication] stopModalWithCode: NSOKButton];
137 - (IBAction)cancel: (id)sender
139 [[NSApplication sharedApplication] stopModalWithCode: NSCancelButton];
142 - (IBAction)clear: (id)sender
144 [self setKeyCombo: [ITKeyCombo clearKeyCombo]];
145 [[NSApplication sharedApplication] stopModalWithCode: NSOKButton];
148 - (void)noteKeyBroadcast: (NSNotification*)note
150 ITKeyCombo* keyCombo;
152 keyCombo = [[note userInfo] objectForKey: @"keyCombo"];
154 [self setKeyCombo: keyCombo];