forked from quicksilver/Quicksilver
/
QSMainPreferencePanes.m
539 lines (467 loc) · 21 KB
/
QSMainPreferencePanes.m
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
//
// QSPreferencePane.m
// Quicksilver
//
// Created by Alcor on 11/2/04.
// Copyright 2004 Blacktree. All rights reserved.
//
#import "QSMainPreferencePanes.h"
#import "QSRegistry.h"
#import "QSResourceManager.h"
#import "QSMacros.h"
#import "QSApp.h"
#import "QSHelp.h"
#import "QSUpdateController.h"
#import "QSNotifications.h"
#import "QSController.h"
#import "QSInterfaceMediator.h"
#import "QSPreferenceKeys.h"
#import "NSBundle_BLTRExtensions.h"
#import "QSHotKeyEvent.h"
#import "QSModifierKeyEvents.h"
// Imports for the actions pref pane
#import "QSExecutor.h"
#import "QSLibrarian.h"
#import "QSTableView.h"
#import <Carbon/Carbon.h>
#define QSTableRowsType @"QSTableRowsType"
#import "NSSortDescriptor+BLTRExtensions.h"
#import "NSIndexSet+Extensions.h"
#import "QSPlugInManager.h"
#import "QSPlugIn.h"
#import "LaunchAtLoginController.h"
@interface QSPreferencePane (Helper)
- (void)selectItemInPopUp:(NSPopUpButton *)popUp representedObject:(id)object;
@end
@implementation QSPreferencePane (Helper)
- (void)selectItemInPopUp:(NSPopUpButton *)popUp representedObject:(id)object {
NSInteger index = [popUp indexOfItemWithRepresentedObject:object];
if (index == -1 && [popUp numberOfItems]) index = 0;
[popUp selectItemAtIndex:index];
}
@end
@implementation QSSearchPrefPane
- (void)awakeFromNib {
#if 0
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NDHotKeyEvent *activationKey = [NDHotKeyEvent getHotKeyForKeyCode:[[defaults objectForKey:kHotKeyCode] unsignedShortValue] character:0 modifierFlags:[[defaults objectForKey:kHotKeyModifiers] unsignedIntegerValue]];
[hotKeyButton setTitle:[activationKey stringValue]];
#endif
NSUserDefaultsController *defaultsController = [NSUserDefaultsController sharedUserDefaultsController];
[defaultsController addObserver:self forKeyPath:@"values.QSModifierActivationCount" options:0 context:nil];
[defaultsController addObserver:self forKeyPath:@"values.QSModifierActivationKey" options:0 context:nil];
[self updateKeyboardPopUp];
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(updateKeyboardPopUp) name:(NSString*)kTISNotifyEnabledKeyboardInputSourcesChanged object:nil];
}
- (void)dealloc {
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self];
[[NSDistributedNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
- (void)setModifier:(NSInteger)modifier count:(NSInteger)count {
QSModifierKeyEvent *event = [QSModifierKeyEvent eventWithIdentifier:@"QSModKeyActivation"];
[event disable];
if (count) {
event = [[[QSModifierKeyEvent alloc] init] autorelease];
[event setModifierActivationMask:modifier];
[event setModifierActivationCount:count];
[event setTarget:[NSApp delegate]];
[event setIdentifier:@"QSModKeyActivation"];
[event setAction:@selector(activateInterface:)];
[event enable];
}
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[self setModifier:[defaults integerForKey:@"QSModifierActivationKey"] count:[defaults integerForKey:@"QSModifierActivationCount"]];
}
- (BOOL)showChildrenInSplitView {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"QSResultsShowChildren"];
}
- (void)setShowChildrenInSplitView:(BOOL)flag {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setBool:flag forKey:@"QSResultsShowChildren"];
[defaults synchronize];
[NSApp requestRelaunch:nil];
}
- (void)updateKeyboardPopUp {
[keyboardPopUp removeAllItems];
NSMutableDictionary *sourceNames = [NSMutableDictionary dictionaryWithCapacity:5];
for (NSString *type in [NSArray arrayWithObjects:(NSString *)kTISTypeKeyboardLayout, (NSString *)kTISTypeKeyboardInputMode, nil]) {
NSDictionary *filter = [NSDictionary dictionaryWithObject:type forKey:(NSString *)kTISPropertyInputSourceType];
CFArrayRef sourceList= TISCreateInputSourceList((CFDictionaryRef)filter, false);
if (!sourceList) {
continue;
}
CFIndex count = CFArrayGetCount(sourceList);
for (int i = 0; i < count; i++ ) {
TISInputSourceRef source = (TISInputSourceRef)CFArrayGetValueAtIndex(sourceList, i);
NSString *title = (NSString *)TISGetInputSourceProperty(source, kTISPropertyLocalizedName);
NSString *sourceId = TISGetInputSourceProperty(source, kTISPropertyInputSourceID);
[sourceNames setObject:sourceId forKey:title];
}
CFRelease(sourceList);
}
for(NSString *title in [sourceNames allKeys]) {
NSMenuItem *item = [[keyboardPopUp menu] addItemWithTitle:title action:nil keyEquivalent:@""];
[item setRepresentedObject:[sourceNames objectForKey:title]];
}
NSString *forcedKeyboardId = [[NSUserDefaults standardUserDefaults] objectForKey:@"QSForcedKeyboardIDOnActivation"];
[self selectItemInPopUp:keyboardPopUp representedObject:forcedKeyboardId];
NSString *selectedKeyboardId = [[keyboardPopUp selectedItem] representedObject];
if (![selectedKeyboardId isEqualToString:forcedKeyboardId]) {
[[NSUserDefaults standardUserDefaults] setObject:selectedKeyboardId forKey:@"QSForcedKeyboardIDOnActivation"];
}
}
@end
@implementation QSAppearancePrefPane
- (IBAction)customize:(id)sender {
[[QSReg preferredCommandInterface] performSelector:@selector(customize:) withObject:sender];
}
- (IBAction)preview:(id)sender {
id win = [[QSReg preferredCommandInterface] window];
if ([win isVisible])
[win orderOut:sender];
else
[win orderFront:sender];
}
- (void)mainViewDidLoad {
[self updateInterfacePopUp];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateInterfacePopUp) name:QSPlugInLoadedNotification object:nil];
[customizeButton setHidden:![[QSReg preferredCommandInterface] respondsToSelector:@selector(customize:)]];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
- (void)updateInterfacePopUp {
NSMenuItem *item;
[interfacePopUp removeAllItems];
NSDictionary *interfaces = [QSReg tableNamed:kQSCommandInterfaceControllers];
NSMutableDictionary *interfaceNames = [NSMutableDictionary dictionaryWithCapacity:[interfaces count]];
// localize titles/names of interfaces
NSString *title;
for(NSString *key in interfaces) {
title = [[QSReg bundleForClassName:[interfaces objectForKey:key]] safeLocalizedStringForKey:key value:key table:nil];
[interfaceNames setObject:key forKey:title];
}
// sort localized names
NSArray *titles = [interfaceNames allKeys];
titles = [titles sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
// add interfaces to popup menu
for(title in titles) {
item = (NSMenuItem *)[[interfacePopUp menu] addItemWithTitle:title action:nil keyEquivalent:@""];
[item setRepresentedObject:[interfaceNames objectForKey:title]];
}
// select active interface
[self selectItemInPopUp:interfacePopUp representedObject:[QSReg preferredCommandInterfaceID]];
}
- (NSString *)commandInterface {
return [QSReg preferredCommandInterfaceID];
}
- (IBAction)setCommandInterface:(id)sender {
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *newInterface = [[sender selectedItem] representedObject];
[defaults setObject:newInterface forKey:kQSCommandInterfaceControllers];
[self setValue:newInterface forMediator:kQSCommandInterfaceControllers];
[nc postNotificationName:QSReleaseAllCachesNotification object:self];
[nc postNotificationName:QSInterfaceChangedNotification object:self];
[defaults synchronize];
[customizeButton setHidden:![[QSReg preferredCommandInterface] respondsToSelector:@selector(customize:)]];
}
- (BOOL)setValue:(NSString *)newMediator forMediator:(NSString *)mediatorType {
[[NSUserDefaults standardUserDefaults] setObject:newMediator forKey:mediatorType];
[QSReg removePreferredInstanceOfTable:mediatorType];
return YES;
}
- (IBAction)resetColors:(id)sender {
#if 0
NSArray *colorDefaults = [NSArray arrayWithObjects:kQSAppearance1B, kQSAppearance1A, kQSAppearance1T, kQSAppearance2B, kQSAppearance2A, kQSAppearance2T, kQSAppearance3B, kQSAppearance3A, kQSAppearance3T, nil];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
for(NSString * key in colorDefaults) {
[defaults willChangeValueForKey:key];
[defaults removeObjectForKey:key];
[defaults didChangeValueForKey:key];
}
#endif
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *colourDefaults = [NSArray arrayWithObjects: kQSAppearance1B, kQSAppearance1A, kQSAppearance1T, kQSAppearance2B, kQSAppearance2A, kQSAppearance2T, kQSAppearance3B, kQSAppearance3A, kQSAppearance3T, nil];
@synchronized(defaults) {
for (NSString *eachDefault in colourDefaults) {
[defaults willChangeValueForKey:eachDefault];
[defaults removeObjectForKey:eachDefault];
[defaults didChangeValueForKey:eachDefault];
}
}
[defaults synchronize];
}
@end
@implementation QSApplicationPrefPane
- (NSNumber *)panePriority {
return [NSNumber numberWithInteger:10];
}
- (BOOL)shouldLaunchAtLogin {
LaunchAtLoginController *launchController = [[LaunchAtLoginController alloc] init];
BOOL shouldLaunch = [launchController willLaunchAtLogin:[[NSBundle mainBundle] bundleURL]];
[launchController release];
return shouldLaunch;
}
- (void)setShouldLaunchAtLogin:(BOOL)launch {
LaunchAtLoginController *launchController = [[LaunchAtLoginController alloc] init];
[launchController setLaunchAtLogin:launch forURL:[[NSBundle mainBundle] bundleURL]];
[launchController release];
}
- (BOOL)dockIconIsHidden {
return ![[NSUserDefaults standardUserDefaults] boolForKey:kHideDockIcon];
}
- (void)setDockIconIsHidden:(BOOL)flag {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setBool:!flag forKey:kHideDockIcon];
if (![defaults objectForKey:@"QSShowMenuIcon"])
[defaults setInteger:1 forKey:@"QSShowMenuIcon"];
[defaults synchronize];
[NSApp requestRelaunch:nil];
}
- (IBAction)checkNow:(id)sender {
[[QSUpdateController sharedInstance] threadedRequestedCheckForUpdate:sender];
}
- (void)deleteSupportFiles {
// !!! Andre Berg 20091013: updated to new 10.5/10.6 API with regards to removeFileAtPath:handler: and the new removeItemAtPath:error:
NSFileManager *fm = [NSFileManager defaultManager];
NSError * err = nil;
[fm removeItemAtPath:QSApplicationSupportSubPath(@"Actions.plist", NO) error:&err];
if (err) {
NSLog(@"QSMainPreferencePanes:%s: Error: %@", __PRETTY_FUNCTION__, err);
err = nil;
}
[fm removeItemAtPath:QSApplicationSupportSubPath(@"Catalog.plist", NO) error:&err];
if (err) {
NSLog(@"QSMainPreferencePanes:%s: Error: %@", __PRETTY_FUNCTION__, err);
err = nil;
}
[fm removeItemAtPath:pIndexLocation error:&err];
if (err) {
NSLog(@"QSMainPreferencePanes:%s: Error: %@", __PRETTY_FUNCTION__, err);
err = nil;
}
[fm removeItemAtPath:QSApplicationSupportSubPath(@"Mnemonics.plist", NO) error:&err];
if (err) {
NSLog(@"QSMainPreferencePanes:%s: Error: %@", __PRETTY_FUNCTION__, err);
err = nil;
}
[fm removeItemAtPath:QSApplicationSupportSubPath(@"PlugIns", NO) error:&err];
if (err) {
NSLog(@"QSMainPreferencePanes:%s: Error: %@", __PRETTY_FUNCTION__, err);
err = nil;
}
[fm removeItemAtPath:QSApplicationSupportSubPath(@"PlugIns.plist", NO) error:&err];
if (err) {
NSLog(@"QSMainPreferencePanes:%s: Error: %@", __PRETTY_FUNCTION__, err);
err = nil;
}
[fm removeItemAtPath:QSApplicationSupportSubPath(@"Shelves", NO) error:&err];
if (err) {
NSLog(@"QSMainPreferencePanes:%s: Error: %@", __PRETTY_FUNCTION__, err);
err = nil;
}
[fm removeItemAtPath:[@"~/Library/Caches/Quicksilver" stringByStandardizingPath] error:&err];
if (err) {
NSLog(@"QSMainPreferencePanes:%s: Error: %@", __PRETTY_FUNCTION__, err);
err = nil;
}
[[NSUserDefaults standardUserDefaults] synchronize];
[fm removeItemAtPath:[[NSString stringWithFormat:@"~/Library/Preferences/%@.plist",kQSBundleID]stringByStandardizingPath] error:&err];
if (err) {
NSLog(@"QSMainPreferencePanes:%s: Error: %@", __PRETTY_FUNCTION__, err);
err = nil;
}
}
- (void)deleteApplication {
NSError * err = nil;
[[NSFileManager defaultManager] removeItemAtPath:[[NSBundle mainBundle] bundlePath] error:&err];
if (err) {
NSLog(@"QSMainPreferencePanes:%s: Error: %@", __PRETTY_FUNCTION__, err);
err = nil;
}
}
// !!! Andre Berg 20091013: this is no longer needed since I upgraded the all the calls to removeFileAtPath:handler: to the new 10.5+ API (removeItemAtPath:error:);
// this should also have the side effect of being faster...
- (BOOL)fileManager:(NSFileManager *)manager shouldProceedAfterError:(NSDictionary *)errorInfo {
NSLog(@"error: %@", errorInfo);
return YES;
}
- (IBAction)resetQS:(id)sender {
if (!NSRunAlertPanel(@"Reset Quicksilver", @"Would you like to delete all preferences and application support files, returning Quicksilver to the default state? This operation cannot be undone and requires a relaunch", @"Cancel", @"Reset and Relaunch", nil) ) {
[self deleteSupportFiles];
[NSApp relaunch:self];
}
}
- (IBAction)runSetup:(id)sender {
[[NSApp delegate] runSetupAssistant:nil];
}
- (IBAction)uninstallQS:(id)sender {
if (!NSRunAlertPanel(@"Uninstall Quicksilver", @"Would you like to delete Quicksilver, all its preferences, and application support files? This operation cannot be undone.", @"Cancel", @"Uninstall", nil) ) {
[self deleteSupportFiles];
[self deleteApplication];
[NSApp terminate:self];
}
}
@end
@implementation QSActionsPrefPane
- (NSString *)mainNibName { return @"QSActionsPrefPane"; }
#define kQSAllActionsCategory @"QSAllActions"
- (id)init {
if (self = [super initWithBundle:[NSBundle bundleForClass:[QSActionsPrefPane class]]]) {
displayMode = 0;
}
return self;
}
- (void)awakeFromNib {
[self updateGroups];
[groupController addObserver:self forKeyPath:@"selectedObjects" options:0 context:@"test"];
[actionController setSortDescriptors:[NSSortDescriptor descriptorArrayWithKey:@"userRank" ascending:YES]];
[groupController setSelectionIndex:0];
[self selectCategories:[groupController selectedObjects]];
}
- (void)selectCategories:(NSArray *)categories {
NSMutableSet *newActions = [NSMutableSet set];
switch (displayMode) {
case 0: {
for(id category in categories) {
NSString *type = [category objectForKey:@"group"];
[newActions addObjectsFromArray: ([type isEqual:kQSAllActionsCategory])?[QSExec actions]:[QSExec actionsArrayForType:type] ];
}
break;
}
case 1: {
for(id category in categories) {
NSString *plugin = [category objectForKey:@"group"];
[newActions addObjectsFromArray: ([plugin isEqual:kQSAllActionsCategory])?[QSExec actions]:[QSExec getArrayForSource:plugin] ];
}
break;
}
default: break;
}
[self setActions:[[[newActions allObjects] mutableCopy] autorelease]];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
[self selectCategories:[groupController selectedObjects]];
}
- (NSMutableArray *)actions { return actions; }
- (void)setActions:(NSMutableArray *)newActions {
if(newActions != actions){
[actions release];
actions = [newActions retain];
}
}
- (NSMutableArray *)groups { return groups; }
- (void)setGroups:(NSMutableArray *)newGroups {
if(newGroups != groups){
[groups release];
groups = [newGroups retain];
}
}
- (NSInteger) displayMode { return displayMode; }
- (void)setDisplayMode:(NSInteger)newDisplayMode {
displayMode = newDisplayMode;
[self updateGroups];
[groupController setSelectionIndex:0];
}
- (void)updateGroups {
NSMutableArray *array = [NSMutableArray array];
switch (displayMode) {
case 0: {
NSDictionary *infoTable = [QSReg tableNamed:@"QSTypeDefinitions"];
NSArray *newGroups = [infoTable allKeys];
for(NSString * group in newGroups) {
NSDictionary *info = [infoTable objectForKey:group];
if (!info) continue;
NSString *name = [info objectForKey:@"name"];
if (!name) name = group;
[array addObject:[NSDictionary dictionaryWithObjectsAndKeys:
group, @"group", name, @"name", [QSResourceManager imageNamed:[info objectForKey:@"icon"]], @"icon", nil]];
}
NSSortDescriptor *desc = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
[array sortUsingDescriptors:[NSArray arrayWithObject:desc]];
[desc release];
[array insertObject:[NSDictionary dictionaryWithObjectsAndKeys:kQSAllActionsCategory, @"group", @"All Actions", @"name", [QSResourceManager imageNamed:@"Quicksilver"] , @"icon", nil] atIndex:0];
[array insertObject:[NSDictionary dictionaryWithObjectsAndKeys:@"*", @"group", @"Any Type", @"name", [QSResourceManager imageNamed:@"Quicksilver"] , @"icon", nil] atIndex:1];
break;
}
case 1: {
foreachkey(pluginId, plugin, [[QSPlugInManager sharedInstance] loadedPlugIns]) {
NSString *name = [plugin shortName];
if (!name) name = [plugin identifier];
NSArray *actionsArray = [QSExec getArrayForSource:[plugin identifier]];
if ([actionsArray count]) {
name = [name stringByAppendingFormat:@" - %lu", (unsigned long)[actionsArray count]];
[array addObject:[NSDictionary dictionaryWithObjectsAndKeys:
[plugin identifier] , @"group", name, @"name", [plugin icon] , @"icon", nil]];
}
}
NSSortDescriptor *desc = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
[array sortUsingDescriptors:[NSArray arrayWithObject:desc]];
[desc release];
[array insertObject:[NSDictionary dictionaryWithObjectsAndKeys:kQSAllActionsCategory, @"group", @"All Plugins", @"name", [QSResourceManager imageNamed:@"Quicksilver"] , @"icon", nil] atIndex:0];
break;
}
default:
break;
}
[self setGroups:array];
}
- (NSDragOperation)tableView:(NSTableView *)view validateDrop:(id <NSDraggingInfo>)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)operation {
NSArray *data = [[info draggingPasteboard] propertyListForType:QSTableRowsType];
NSIndexSet *indexes = [NSIndexSet indexSetFromArray:data];
if ([indexes containsIndex:row] || [indexes containsIndex:row-1])
return NSDragOperationNone;
else
return operation == NSTableViewDropAbove ? NSDragOperationMove : NSDragOperationNone;
}
- (void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
if ([[tableColumn identifier] isEqualToString:@"enabled"] && mOptionKeyIsDown)
[[actionController arrangedObjects] setValue:object forKey:@"enabled"];
if ([[tableColumn identifier] isEqualToString:@"rank"]) {
NSArray *currentActions = [actionController arrangedObjects];
NSInteger newRow = [object integerValue] -1;
if (row != newRow && row >= 0 && row < (NSInteger)[currentActions count] && newRow >= 0 && (NSUInteger)newRow<[currentActions count]) {
[QSExec orderActions:[NSArray arrayWithObject:[currentActions objectAtIndex:row]] aboveActions:[NSArray arrayWithObject:[currentActions objectAtIndex:newRow]]];
}
[actionController rearrangeObjects];
}
}
- (BOOL)tableView:(NSTableView *)view acceptDrop:(id <NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation {
[view registerForDraggedTypes:nil];
NSArray *data = [[info draggingPasteboard] propertyListForType:QSTableRowsType];
NSIndexSet *indexes = [NSIndexSet indexSetFromArray:data];
NSArray *currentActions = [actionController arrangedObjects];
NSArray *draggedActions = [[actionController arrangedObjects] objectsAtIndexes:indexes];
BOOL ascending = [[[view sortDescriptors] objectAtIndex:0] ascending];
if ((ascending ? [indexes lastIndex] > (NSUInteger)row : [indexes lastIndex] < (NSUInteger)row))
// An upward or mixed drag (promotion for the most part)
[QSExec orderActions:draggedActions aboveActions:[NSArray arrayWithObject:[currentActions objectAtIndex:ascending?row:row-1]]];
else // A downward drag (demotion)
[QSExec orderActions:draggedActions belowActions:[NSArray arrayWithObject:[currentActions objectAtIndex:ascending?row-1:row]]];
[actionController setSelectedObjects:draggedActions];
[actionController rearrangeObjects];
return YES;
}
- (BOOL)tableView:(NSTableView *)tv writeRows:(NSArray*)rows toPasteboard:(NSPasteboard*)pboard {
if (![[[[tv sortDescriptors] objectAtIndex:0] key] isEqualToString:@"userRank"])
return NO;
[tv registerForDraggedTypes:[NSArray arrayWithObject:QSTableRowsType]];
[pboard declareTypes:[NSArray arrayWithObject:QSTableRowsType] owner:self];
[pboard setPropertyList:rows forType:QSTableRowsType];
return YES;
}
- (IBAction)setFilterText:(id)sender {
NSString *string = [sender stringValue];
[actionController setFilterPredicate:([string length])?[NSPredicate predicateWithFormat:@"name contains[cd] %@", string]:nil];
}
- (void)dealloc {
[actions release];
[groups release];
[super dealloc];
}
@end