-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHotKeyListController.m
More file actions
executable file
·206 lines (173 loc) · 5.74 KB
/
Copy pathHotKeyListController.m
File metadata and controls
executable file
·206 lines (173 loc) · 5.74 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//
// HotKeyListController.m
// Shortcuts
extern CFStringRef kShortcutObserverPortName;
extern const UniChar kCmdGlyph;
extern const UniChar kOptionGlyph;
extern const UniChar kControlGlyph;
extern const UniChar kShiftGlyph;
enum
{
kMessagePrefsChanged = 1
};
#import "HotKeyListController.h"
#include "ShortcutList.h"
@implementation HotKeyListController
- (void)awakeFromNib
{
[mShortcutTableView noteNumberOfRowsChanged];
[mShortcutTableView deselectAll:self];
[mShortcutTableView setTarget:self];
[mShortcutTableView setDoubleAction: @selector(editShortcut:) ];
if(mEditButton != NULL)
[mEditButton setEnabled:FALSE];
if(mRemoveButton != NULL)
[mRemoveButton setEnabled:FALSE];
}
#pragma mark -
#pragma mark === DATA SOURCE ===
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
CFMutableArrayRef shortcutList = NULL;
if(mShortcutsController != NULL)
shortcutList = [mShortcutsController getShortcutList];
if(shortcutList != NULL)
return CFArrayGetCount(shortcutList);
return 0;
}
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
CFMutableArrayRef shortcutList = NULL;
if(mShortcutsController != NULL)
shortcutList = [mShortcutsController getShortcutList];
if( shortcutList != NULL )
{
CFIndex theCount = CFArrayGetCount(shortcutList);
if( (row >= 0) && (row < theCount) )
{
NSString *identifier = [tableColumn identifier];
if([identifier isEqualToString:@"MenuName"])
{
//return @"MenuName";
CFTypeRef theItem = CFArrayGetValueAtIndex(shortcutList, row);
if( (theItem != NULL) && (CFGetTypeID(theItem) == CFDictionaryGetTypeID()) )
{
CFDictionaryRef theDict = (CFDictionaryRef)theItem;
CFTypeRef theResult = CFDictionaryGetValue( theDict, CFSTR("NAME") );
if((theResult != NULL) && (CFStringGetTypeID() == CFGetTypeID(theResult)) )
{
NSString * __weak theName = (__bridge NSString *)theResult;
theResult = CFDictionaryGetValue( theDict, CFSTR("SUBMENU") );
if((theResult != NULL) && (CFStringGetTypeID() == CFGetTypeID(theResult)) )
{
NSString * __weak submenuPath = (__bridge NSString *)theResult;
NSMutableString *outStr = [NSMutableString stringWithString:submenuPath];
NSUInteger strLen = [outStr length];
if( (strLen > 0) && [outStr characterAtIndex:(strLen-1)] != '/' )
[outStr appendString:@"/"];
[outStr appendString:theName];
return outStr;
}
else
return theName;
}
}
}
else if([identifier isEqualToString:@"HotKey"])
{
CFStringRef keyChar = NULL;
CFIndex carbonModifiers = 0;
CFIndex keyCode = 0;
FetchShortcutKeyAndModifiers(shortcutList, row,
&keyChar, &carbonModifiers, &keyCode);
unsigned int modifiers = [ShortcutsController getModifiersFromCarbonModifiers: carbonModifiers];
NSString *shortcutString = [ShortcutsController getShortHotKeyString:(__bridge NSString *)keyChar withModifiers:modifiers];
if(shortcutString != NULL)
return shortcutString;
}
}
}
return @"";
}
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
{
/*
int selectedShortcutIndex = [mShortcutTableView selectedRow];
if((selectedShortcutIndex < 0) || (selectedShortcutIndex >= theCount) )
return;
*/
int selectedCount = [mShortcutTableView numberOfSelectedRows];
if(selectedCount == 1)
{
if(mEditButton != NULL)
[mEditButton setEnabled:YES];
if(mRemoveButton != NULL)
[mRemoveButton setEnabled:YES];
}
else if(selectedCount > 1)
{
if(mEditButton != NULL)
[mEditButton setEnabled:FALSE];
if(mRemoveButton != NULL)
[mRemoveButton setEnabled:YES];
}
else
{
if(mEditButton != NULL)
[mEditButton setEnabled:FALSE];
if(mRemoveButton != NULL)
[mRemoveButton setEnabled:FALSE];
}
}
- (IBAction)editShortcut:(id)sender
{
int numberOfSelectedRows = [mShortcutTableView numberOfSelectedRows];
if(numberOfSelectedRows == 1)
{
int selectedShortcutIndex = [mShortcutTableView selectedRow];
if(mShortcutsController != NULL)
{
[mShortcutsController editItem:(CFIndex)selectedShortcutIndex];
}
}
}
- (IBAction)removeShortcut:(id)sender
{
int numberOfSelectedRows = [mShortcutTableView numberOfSelectedRows];
if(numberOfSelectedRows == 0)
return;
CFMutableArrayRef shortcutList = NULL;
if(mShortcutsController != NULL)
shortcutList = [mShortcutsController getShortcutList];
NSArray *sortedIndexes = [[[mShortcutTableView selectedRowEnumerator] allObjects] sortedArrayUsingSelector:@selector(compare:)];
unsigned indexCount = [sortedIndexes count];
int firstIndex = -1;
if(indexCount > 0)
{
NSNumber *theNum = (NSNumber *)[sortedIndexes objectAtIndex:0];
firstIndex = [theNum intValue];
}
int i;
for(i = indexCount-1; i >= 0; i--)
{
NSNumber *theNum = (NSNumber *)[sortedIndexes objectAtIndex:i];
int theIndex = [theNum intValue];
if((theIndex >= 0) && (theIndex < CFArrayGetCount(shortcutList)))
CFArrayRemoveValueAtIndex( shortcutList, theIndex );
}
[mShortcutTableView reloadData];
CFIndex newCount = CFArrayGetCount(shortcutList);
if(newCount == 0)
firstIndex = -1;
if(firstIndex == -1)
[mShortcutTableView deselectAll:self];
else if((firstIndex-1) >= 0)
[mShortcutTableView selectRow:(firstIndex-1) byExtendingSelection:NO];
else if((firstIndex >= 0) && ((unsigned)firstIndex < newCount))
[mShortcutTableView selectRow:firstIndex byExtendingSelection:NO];
else
[mShortcutTableView deselectAll:self];
if(mShortcutsController != NULL)
[mShortcutsController savePreferences:self];
}
@end