-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathITKeyComboPanel.m
More file actions
107 lines (83 loc) · 2.27 KB
/
ITKeyComboPanel.m
File metadata and controls
107 lines (83 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#import "ITKeyComboPanel.h"
#import "ITHotKey.h"
#import "ITKeyCombo.h"
#import "ITKeyBroadcaster.h"
#import "ITHotKeyCenter.h"
@implementation ITKeyComboPanel
static id _sharedKeyComboPanel = nil;
+ (id)sharedPanel {
if (!_sharedKeyComboPanel) {
_sharedKeyComboPanel = [[self alloc] init];
}
return _sharedKeyComboPanel;
}
- (id)init {
return [self initWithWindowNibName:@"ITKeyComboPanel"];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[mKeyName release];
[super dealloc];
}
- (void)windowDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(noteKeyBroadcast:) name:ITKeyBroadcasterKeyEvent object:mKeyBcaster];
}
- (void)_refreshContents {
if (mComboField) {
[mComboField setStringValue:[mKeyCombo description]];
}
if (mTitleField) {
[mTitleField setStringValue:mKeyName];
}
}
- (int)runModal {
int resultCode;
[self window]; //Force us to load
[self _refreshContents];
[[self window] center];
[self showWindow:self];
resultCode = [[NSApplication sharedApplication] runModalForWindow:[self window]];
[self close];
return resultCode;
}
- (void)runModalForHotKey:(ITHotKey *)hotKey {
int resultCode;
[self setKeyBindingName:[hotKey name]];
[self setKeyCombo:[hotKey keyCombo]];
resultCode = [self runModal];
if (resultCode == NSOKButton) {
[hotKey setKeyCombo:[self keyCombo]];
[[ITHotKeyCenter sharedCenter] registerHotKey:hotKey];
}
}
- (void)setKeyCombo:(ITKeyCombo *)combo {
[mKeyCombo autorelease];
mKeyCombo = [combo retain];
[self _refreshContents];
}
- (ITKeyCombo *)keyCombo {
return mKeyCombo;
}
- (void)setKeyBindingName:(NSString *)name {
[mKeyName autorelease];
mKeyName = [name retain];
[self _refreshContents];
}
- (NSString *)keyBindingName {
return mKeyName;
}
- (IBAction)ok:(id)sender {
[[NSApplication sharedApplication] stopModalWithCode:NSOKButton];
}
- (IBAction)cancel:(id)sender {
[[NSApplication sharedApplication] stopModalWithCode:NSCancelButton];
}
- (IBAction)clear:(id)sender {
[self setKeyCombo:[ITKeyCombo clearKeyCombo]];
[[NSApplication sharedApplication] stopModalWithCode:NSOKButton];
}
- (void)noteKeyBroadcast:(NSNotification *)note {
ITKeyCombo *keyCombo = [[note userInfo] objectForKey:@"keyCombo"];
[self setKeyCombo:keyCombo];
}
@end