/
QSInterfaceController.m
767 lines (654 loc) · 23.9 KB
/
QSInterfaceController.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
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
#import "QSPreferenceKeys.h"
#import "QSInterfaceController.h"
#import "QSHistoryController.h"
#import <Carbon/Carbon.h>
#import "QSObject.h"
#import "QSActionProvider.h"
#import "QSTypes.h"
#import "QSTaskController.h"
#import "QSNotifications.h"
#import "QSObjectCell.h"
#import "QSCommand.h"
#import "QSInterfaceController.h"
#import "QSObject_FileHandling.h"
#import "QSTaskViewer.h"
#import "QSNullObject.h"
#import "QSTaskController.h"
#import "QSController.h"
#import "QSInterfaceController.h"
#import "QSAction.h"
#import "QSWindow.h"
#import "QSSearchObjectView.h"
#import "QSMnemonics.h"
#import "QSLibrarian.h"
#import <QSCore/QSExecutor.h>
#import <IOKit/IOCFBundle.h>
#import <ApplicationServices/ApplicationServices.h>
#import "QSTextProxy.h"
#import "QSMenuButton.h"
#define KeyShift 0x38
#define KeyControl 0x3b
#define KeyOption 0x3A
#define KeyCommand 0x37
#define KeyCapsLock 0x39
#define KeySpace 0x31
#define KeyTabs 0x30
#import "CGSPrivate.h"
@implementation QSInterfaceController
+ (void)initialize {
static BOOL initialized = NO;
if (!initialized) {
[NSApp registerServicesMenuSendTypes:[NSArray arrayWithObjects:NSStringPboardType, NSRTFPboardType, nil]
returnTypes:[NSArray arrayWithObjects:NSStringPboardType, NSRTFPboardType, nil]];
}
}
+ (NSString *)name { return @"DefaultInterface"; }
- (id)init {
if (self = [super init]) {
[self loadWindow];
}
return self;
}
- (id)initWithWindow:(NSWindow *)window {
self = [super initWithWindow:window];
if (!self) {
[super release];
return nil;
}
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:self];
[nc addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:self];
[nc addObserver:self selector:@selector(objectModified:) name:QSObjectModified object:nil];
[nc addObserver:self selector:@selector(objectIconModified:) name:QSObjectIconModified object:nil];
[nc addObserver:self selector:@selector(searchObjectChanged:) name:@"SearchObjectChanged" object:nil];
[nc addObserver:self selector:@selector(appChanged:) name:QSActiveApplicationChanged object:nil];
[QSHistoryController sharedInstance];
return self;
}
- (void)dealloc {
if([actionsUpdateTimer isValid])
[actionsUpdateTimer invalidate];
if([hideTimer isValid])
[hideTimer invalidate];
[actionsUpdateTimer release];
[hideTimer release];
//[progressIndicator release];
//[iSelector release];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc removeObserver:progressIndicator];
[nc removeObserver:self];
[super dealloc];
}
- (void)windowDidLoad {
//if (![[self window] setFrameUsingName:[self window] Key]) [[self window] center];
[progressIndicator stopAnimation:self];
[progressIndicator setDisplayedWhenStopped:NO];
[aSelector setEnabled:NO];
[aSelector setAllowText:NO];
// [aSelector setInitiatesDrags:NO];
[aSelector setDropMode:QSRejectDropMode];
[aSelector setSearchMode:SearchFilter];
[aSelector setAllowNonActions:NO];
[iSelector retain];
[self hideIndirectSelector:nil];
[[self window] setHidesOnDeactivate:NO];
[[self menuButton] setMenu:[(QSController *)[NSApp delegate] statusMenuWithQuit]];
#if 0
QSObjectCell *attachmentCell = [[QSObjectCell alloc] initTextCell:@""];
[attachmentCell setRepresentedObject:[QSObject fileObjectWithPath:@"/Volumes/Lore/"]];
[[attachmentCell representedObject] loadIcon];
NSTextAttachment *attachment = [[[NSTextAttachment alloc] init] autorelease];
[attachment setAttachmentCell: attachmentCell];
#endif
// NSAttributedString *attributedString = [NSAttributedString attributedStringWithAttachment: attachment];
//[[commandView textStorage] appendAttributedString:attributedString];
[self searchObjectChanged:nil];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:progressIndicator selector:@selector(startAnimation:) name:QSTasksStartedNotification object:nil];
[nc addObserver:progressIndicator selector:@selector(stopAnimation:) name:QSTasksEndedNotification object:nil];
}
- (QSCommand *)currentCommand {
return [QSCommand commandWithDirectObject:[dSelector objectValue] actionObject:[aSelector objectValue] indirectObject:[iSelector objectValue]];
}
- (void)setCommand:(QSCommand *)command {
[self window];
[dSelector setObjectValue:[command dObject]];
[aSelector setObjectValue:[command aObject]];
[iSelector setObjectValue:[command iObject]];
}
- (void)setCommandWithArray:(NSArray *)array {
[dSelector setObjectValue:[array objectAtIndex:0]];
[actionsUpdateTimer invalidate];
[aSelector setObjectValue:[array objectAtIndex:1]];
if ([array count] > 2)
[iSelector setObjectValue:[array objectAtIndex:2]];
else
[iSelector setObjectValue:nil];
}
- (void)selectObject:(QSBasicObject *)object {
[dSelector setObjectValue:object];
}
- (QSBasicObject *)selection {
return [dSelector objectValue];
}
- (void)showMainWindow:(id)sender {
[[self window] makeKeyAndOrderFront:sender];
if ([[NSUserDefaults standardUserDefaults] boolForKey:kSuppressHotKeysInCommand]) {
CGSConnection conn = _CGSDefaultConnection();
CGSSetGlobalHotKeyOperatingMode(conn, CGSGlobalHotKeyDisable);
}
}
- (void)willHideMainWindow:(id)sender {
if ([[NSUserDefaults standardUserDefaults] boolForKey:kSuppressHotKeysInCommand]) {
CGSConnection conn = _CGSDefaultConnection();
CGSSetGlobalHotKeyOperatingMode(conn, CGSGlobalHotKeyEnable);
}
if ([[self window] isVisible] && ![[self window] attachedSheet]) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"InterfaceDeactivated" object:self];
[[self window] makeFirstResponder:nil];
}
// Close the Quicklook panel if the QS window closes
if([QLPreviewPanel sharedPreviewPanelExists] && [[QLPreviewPanel sharedPreviewPanel] isVisible]) {
[(QSSearchObjectView *)[[QLPreviewPanel sharedPreviewPanel] delegate] closePreviewPanel];
}
}
- (void)hideMainWindowWithEffect:(id)effect {
[self willHideMainWindow:nil];
[self setHiding:YES];
if (effect && [[NSUserDefaults standardUserDefaults] boolForKey:kUseEffects])
[(QSWindow *)[self window] hideWithEffect:effect];
else {
if ([self isKindOfClass:[QSCommandBuilder class]]) {
[self hideWindows:nil];
}
else {
[[self window] orderOut:nil];
}
}
[self setHiding:NO];
[[NSNotificationCenter defaultCenter] postNotificationName:QSReleaseOldCachesNotification object:self];
}
- (void)hideMainWindow:(id)sender {
[self hideMainWindowWithEffect:nil];
}
- (void)hideMainWindowFromExecution:(id)sender {
[self hideMainWindowWithEffect:
[[self window] windowPropertyForKey:kQSWindowExecEffect]];
}
- (void)hideMainWindowFromCancel:(id)sender {
[self hideMainWindowWithEffect:
[[self window] windowPropertyForKey:kQSWindowCancelEffect]];
}
- (void)hideMainWindowFromFade:(id)sender {
if ([[self window] respondsToSelector:@selector(windowPropertyForKey:)])
[self hideMainWindowWithEffect:
[[self window] windowPropertyForKey:kQSWindowFadeEffect]];
}
- (void)showIndirectSelector:(id)sender {
[[[self window] contentView] addSubview:iSelector];
[aSelector setNextKeyView:iSelector];
}
- (void)hideIndirectSelector:(id)sender {
[iSelector removeFromSuperview];
}
- (void)clearObjectView:(QSSearchObjectView *)view {
[view setResultArray:nil];
[view setSourceArray:nil];
[view setMatchedString:nil];
[view setSearchString:nil];
[view clearObjectValue];
}
- (void)updateControl:(QSSearchObjectView *)control withArray:(NSArray *)array {
id defaultSelection = nil;
if ([array count]) {
if ([[array lastObject] isKindOfClass:[NSArray class]]) {
defaultSelection = [array objectAtIndex:0];
if ([defaultSelection isKindOfClass:[NSNull class]])
defaultSelection = nil;
array = [array lastObject];
} else {
defaultSelection = [array objectAtIndex:0];
}
} else {
[control clearObjectValue];
}
[control clearSearch];
[control setSourceArray:(NSMutableArray *)array];
[control setResultArray:(NSMutableArray *)array];
[control selectObject:defaultSelection];
}
- (void)setActionUpdateTimer {
if ([actionsUpdateTimer isValid]) {
// *** this was causing actions not to update for the search contents action
[actionsUpdateTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:0.10]];
//[actionsUpdateTimer fire];
// NSLog(@"action %@", [actionsUpdateTimer fireDate]);
} else {
[actionsUpdateTimer invalidate];
[actionsUpdateTimer release];
actionsUpdateTimer = [[NSTimer scheduledTimerWithTimeInterval:0.10 target:self selector:@selector(updateActionsNow) userInfo:nil repeats:NO] retain];
}
}
- (void)fireActionUpdateTimer {
[actionsUpdateTimer fire];
}
- (NSArray *)rankedActions {
id dObject = [dSelector objectValue];
id iObject = [iSelector objectValue];
if([dObject isKindOfClass:[QSRankedObject class]])
dObject = [dObject object];
if([iObject isKindOfClass:[QSRankedObject class]])
iObject = [iObject object];
return [QSExec rankedActionsForDirectObject:dObject indirectObject:iObject];
}
- (void)updateActions {
// update the actions after a delay (see setActionUpdateTimer for the delay length)
[self performSelectorOnMainThread:@selector(setActionUpdateTimer) withObject:nil waitUntilDone:YES];
}
- (void)updateActionsNow {
NSArray *actions = [self rankedActions];
// Don't reload the 2nd pane if the actions are identical
if ([actions isEqualToArray:[aSelector resultArray]]) {
return;
}
// Clear the current results in the aSelector ready for the new results
[aSelector setResultArray:nil];
[aSelector clearObjectValue];
[actionsUpdateTimer invalidate];
[aSelector setEnabled:YES];
[self updateControl:aSelector withArray:actions];
NSString *type = [NSString stringWithFormat:@"QSActionMnemonic:%@", [[dSelector objectValue] primaryType]];
[aSelector setMatchedString:type];
[aSelector setSearchString:nil];
}
- (void)updateIndirectObjects {
NSArray *indirects = [[[aSelector objectValue] provider] validIndirectObjectsForAction:[[aSelector objectValue] identifier] directObject:[dSelector objectValue]];
[self updateControl:iSelector withArray:indirects];
[iSelector setSearchMode:(indirects?SearchFilter:SearchFilterAll)];
}
- (void)updateViewLocations {
QSAction *obj = [aSelector objectValue];
if (([obj respondsToSelector:@selector(argumentCount)]) && ([obj argumentCount] == 2))
[self showIndirectSelector:nil];
else
[self hideIndirectSelector:nil];
}
- (void)performService:(NSPasteboard *)pboard userData:(NSString *)userData error:(NSString **)error {
QSObject *entry;
entry = [[QSObject alloc] initWithPasteboard:pboard];
[dSelector setObjectValue:entry];
[entry release];
[self activate:self];
}
- (void)searchArray:(NSArray *)array {
// show the results list with the first pane empty
[self showArray:array withDirectObject:nil];
}
- (void)showArray:(NSArray *)array {
// display the results list with these items
if (array && [array count] > 0) {
// put the first item from the array into the first pane
[self showArray:array withDirectObject:[array objectAtIndex:0]];
} else {
// nothing to display - present a blank interface
[self showArray:array withDirectObject:nil];
}
[dSelector showResultView:self];
}
- (void)showArray:(NSArray *)array withDirectObject:(QSObject *)dObject {
[actionsUpdateTimer invalidate];
[self clearObjectView:dSelector];
NSMutableArray *mutArray = [[array mutableCopy] autorelease];
[dSelector setSourceArray:mutArray];
[dSelector setResultArray:mutArray];
[dSelector setSearchMode:SearchFilter];
if (dObject) {
// show an item from this array if set
[dSelector selectObjectValue:dObject];
}
[self updateViewLocations];
[self updateActionsNow];
[self showMainWindow:self];
[[self window] makeFirstResponder:dSelector];
}
#pragma mark -
#pragma mark Notifications
- (void)objectModified:(NSNotification*)notif {
if ([[dSelector objectValue] isEqual:[notif object]]) {
#ifdef DEBUG
if (VERBOSE) NSLog(@"Reloading actions for: %@", [notif object]);
#endif
[self updateActions];
}
}
- (void)objectIconModified:(NSNotification *)notif {
QSObject *object = [notif object];
if ([[dSelector objectValue] isEqual:object]) {
// redraw dObject icon
[dSelector updateObject:object];
}
if ([[iSelector objectValue] isEqual:object]) {
// redraw iObject icon
[iSelector updateObject:object];
}
}
- (void)searchObjectChanged:(NSNotification*)notif {
[[self window] disableFlushWindow];
if ([notif object] == dSelector) {
[iSelector setObjectValue:nil];
[self updateActions];
[self updateViewLocations];
} else if ([notif object] == aSelector) {
QSAction *obj = [aSelector objectValue];
if ([obj isKindOfClass:[QSRankedObject class]])
obj = [(QSRankedObject*)obj object];
if ([obj isKindOfClass:[QSAction class]]) {
int argumentCount = [obj argumentCount];
if (argumentCount == 2)
[self updateIndirectObjects];
[self updateViewLocations];
}
} else if ([notif object] == iSelector) {
[self updateViewLocations];
}
[[self window] enableFlushWindow];
}
- (void)appChanged:(NSNotification *)aNotification {
NSString *currentApp = [[[NSWorkspace sharedWorkspace] activeApplication] objectForKey:@"NSApplicationBundleIdentifier"];
if (![currentApp isEqualToString:@"com.blacktree.Quicksilver"])
[self hideWindows:self];
}
- (void)invalidateHide {
[hideTimer invalidate];
}
- (void)timerHide:(NSTimer *)timer {
if (preview) return;
bool stayOpen = StillDown();
if (!stayOpen) {
// NSLog(@"Window Closing");
if ([[NSApp keyWindow] level] <= [[self window] level])
// ***warning * this needs to be better
[self hideMainWindowFromFade:self];
[hideTimer invalidate];
} else {
// NSLog(@"Window Staying Open");
}
}
- (void)clear:(NSTimer *)timer {
[dSelector clearObjectValue];
[self updateActionsNow];
}
#pragma mark -
#pragma mark NSWindow
#pragma mark Delegate
- (BOOL)windowShouldClose:(id)sender {
[self hideMainWindowFromCancel:self];
return NO;
}
#pragma mark Notifications
- (void)windowDidResignMain:(NSNotification *)aNotification {}
- (void)windowDidResignKey:(NSNotification *)aNotification {
// Close the Quicklook panel if the QS window closes
if([QLPreviewPanel sharedPreviewPanelExists] && [[QLPreviewPanel sharedPreviewPanel] isVisible]) {
return;
}
if ([aNotification object] == [self window]) {
if (hidingWindow) return;
if ([hideTimer isValid]) {
[hideTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
} else {
[hideTimer release];
hideTimer = [[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timerHide:) userInfo:nil repeats:YES] retain];
[hideTimer fire];
}
} else if (![NSApp keyWindow]) {
[self hideMainWindowFromFade:self];
}
}
- (void)windowDidBecomeKey:(NSNotification *)notification {
NSWindow *window = [notification object];
if ([[self window] attachedSheet] == window)
return;
if (window == [self window]) {
[hideTimer invalidate];
} else if ([[notification object] level] <= [[self window] level]) {
//NSLog(@"hide! %@", window);
// ***warning * this needs to be better
[self hideWindows:self];
}
}
#pragma mark -
#pragma mark Command Execution
- (void)executeCommandThreaded {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
#ifdef DEBUG
NSDate *startDate = [NSDate date];
#endif
QSAction *action = [[aSelector objectValue] retain];
if ([[NSApp currentEvent] modifierFlags] & NSCommandKeyMask && !([[NSApp currentEvent] modifierFlags] & NSShiftKeyMask) ) {
QSAction* alternate = [action alternate];
if (alternate != action) {
[alternate retain];
[action release];
action = alternate;
}
#ifdef DEBUG
if (VERBOSE) NSLog(@"Using Alternate Action: %@", action);
#endif
}
QSObject *dObject = [dSelector objectValue];
QSObject *iObject = [iSelector objectValue];
if( [dObject isKindOfClass:[QSRankedObject class]] )
dObject = [(QSRankedObject*)dObject object];
if( [iObject isKindOfClass:[QSRankedObject class]] )
iObject = [(QSRankedObject*)iObject object];
QSCommand *command = [QSCommand commandWithDirectObject:dObject actionObject:action indirectObject:iObject];
[command execute];
#ifdef DEBUG
if (VERBOSE) NSLog(@"Command executed (%dms) ", (int)(-[startDate timeIntervalSinceNow] *1000));
#endif
[action release];
[pool release];
}
- (void)executePartialCommand:(NSArray *)array {
// remove objects previously selected by the comma trick
[self clearObjectView:dSelector];
[dSelector setObjectValue:[array objectAtIndex:0]];
if ([array count] == 1) {
[self updateActionsNow];
[[self window] makeFirstResponder:aSelector];
} else {
[actionsUpdateTimer invalidate];
[aSelector setObjectValue:[array objectAtIndex:1]];
if ([array count] > 2) {
[iSelector setObjectValue:[array objectAtIndex:2]];
}
[[self window] makeFirstResponder:iSelector];
}
[self updateViewLocations];
[self showInterface:self];
}
- (void)executeCommand:(id)sender cont:(BOOL)cont encapsulate:(BOOL)encapsulate {
if ([actionsUpdateTimer isValid]) {
[actionsUpdateTimer fire];
}
if (![aSelector objectValue]) {
NSBeep();
return;
}
// add the object being executed to the history
[dSelector updateHistory];
int argumentCount = [(QSAction *)[aSelector objectValue] argumentCount];
if (argumentCount == 2) {
BOOL indirectIsRequired = ![[aSelector objectValue] indirectOptional];
BOOL indirectIsInvalid = ![iSelector objectValue];
BOOL indirectIsTextProxy = [[[iSelector objectValue] primaryType] isEqual:QSTextProxyType];
if (indirectIsRequired && (indirectIsInvalid || indirectIsTextProxy) ) {
if (indirectIsInvalid) NSBeep();
[[self window] makeFirstResponder:iSelector];
return;
}
[QSExec noteIndirect:[iSelector objectValue] forAction:[aSelector objectValue]];
}
if (encapsulate) {
[self encapsulateCommand];
return;
}
if (!cont) {
[self hideMainWindowFromExecution:self]; // *** this should only hide if no result comes in like 2 seconds
}
if ([[NSUserDefaults standardUserDefaults] boolForKey:kExecuteInThread] && [[aSelector objectValue] canThread])
[NSThread detachNewThreadSelector:@selector(executeCommandThreaded) toTarget:self withObject:nil];
else
[self executeCommandThreaded];
[QSHist addCommand:[self currentCommand]];
[dSelector saveMnemonic];
[aSelector saveMnemonic];
if (argumentCount == 2) {
[iSelector saveMnemonic];
}
if (cont) {
[[self window] makeFirstResponder:aSelector];
}
}
- (void)encapsulateCommand {
#ifdef DEBUG
if (VERBOSE) NSLog(@"Encapsulating Command");
#endif
QSCommand *commandObject = [self currentCommand];
[self selectObject:commandObject];
[self actionActivate:commandObject];
}
#pragma mark -
#pragma mark IBActions
- (IBAction)showInterface:(id)sender {
[[NSNotificationCenter defaultCenter] postNotificationName:@"InterfaceActivated" object:self];
[self showMainWindow:self];
}
- (IBAction)activate:(id)sender {
if ([[self window] isVisible]) {
[self hideMainWindowFromCancel:sender];
return;
}
// This will be called on line 575 [self showInterface:self], there's no point calling it twice
// Only thing that uses this notification is triggers at the moment (p_j_r change 24/04/2011)
// [[NSNotificationCenter defaultCenter] postNotificationName:@"InterfaceActivated" object:self];
[hideTimer invalidate];
[dSelector reset:self];
[self updateActions];
[iSelector reset:self];
[[dSelector objectValue] loadIcon];
[self setPreview:NO];
[self showInterface:self];
[[self window] makeFirstResponder:dSelector];
[dSelector setSearchMode:SearchFilterAll];
NSEvent *theEvent = [NSApp nextEventMatchingMask:NSKeyDownMask untilDate:[NSDate dateWithTimeIntervalSinceNow:0.075] inMode:NSDefaultRunLoopMode dequeue:YES];
#warning dont do this unless the character is alphabetic
if (theEvent) {
theEvent = [NSEvent keyEventWithType:[theEvent type]
location:[theEvent locationInWindow]
modifierFlags:0
timestamp:[theEvent timestamp]
windowNumber:[theEvent windowNumber]
context:[theEvent context]
characters:[theEvent charactersIgnoringModifiers]
charactersIgnoringModifiers:[theEvent charactersIgnoringModifiers]
isARepeat:[theEvent isARepeat]
keyCode:[theEvent keyCode]];
#ifdef DEBUG
if (VERBOSE) NSLog(@"Ignoring Modifiers for characters: %@", [theEvent characters]);
#endif
[NSApp postEvent:theEvent atStart:YES];
//NSLog(@"time2 %f", [theEvent timestamp]);
}
}
- (IBAction)activateInTextMode:(id)sender {
[dSelector transmogrify:sender];
[iSelector reset:self];
[self showInterface:self];
}
// Method that detects which pane should be focused on re-activating of Quicksilver interface
- (IBAction)actionActivate:(id)sender {
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"QSJumpToActionOnResult"]) {
[self updateActionsNow];
[iSelector reset:self];
[[self window] makeFirstResponder:aSelector];
}
[self showInterface:self];
}
- (IBAction)executeCommand:(id)sender {
// run the action and set focus to the 1st pane
[self executeCommand:sender cont:NO encapsulate:NO];
}
- (IBAction)executeCommandAndContinue:(id)sender {
// run the action and set focus to the 2nd pane
[self executeCommand:sender cont:YES encapsulate:NO];
}
- (IBAction)shortCircuit:(id)sender {
//NSLog(@"scirr");
[self fireActionUpdateTimer];
NSArray *array = [aSelector resultArray];
int argumentCount = [(QSAction *)[aSelector objectValue] argumentCount];
if (sender == iSelector) {
int index = [array indexOfObject:[aSelector objectValue]];
int count = [array count];
if (index != count-1)
array = [[array subarrayWithRange:NSMakeRange(index+1, count-index-1)] arrayByAddingObjectsFromArray:
[array subarrayWithRange:NSMakeRange(0, index+1)]];
argumentCount = 0;
[[self window] makeFirstResponder:nil];
}
if (argumentCount != 2) {
QSAction *action = nil;
QSAction *bestAction = nil;
for(action in array) {
if ([action argumentCount] == 2) {
bestAction = action;
[aSelector selectObject:action];
[self updateIndirectObjects];
break;
}
}
if (!bestAction) {
NSBeep();
return;
}
}
[[self window] makeFirstResponder:iSelector];
}
- (IBAction)encapsulateCommand:(id)sender {
[self executeCommand:sender cont:NO encapsulate:YES];
}
- (IBAction)hideWindows:(id)sender {
[self hideMainWindow:self];
}
- (IBAction)showTasks:(id)sender {
[[NSClassFromString(@"QSTaskViewer") sharedInstance] showWindow:self];
}
- (IBAction)showAbout:(id)sender {
[[NSApp delegate] showAbout:sender];
}
#pragma mark -
#pragma mark NSResponder overrides
- (BOOL)performKeyEquivalent:(NSEvent *)theEvent {
if (([theEvent modifierFlags] & NSCommandKeyMask) &&
([theEvent modifierFlags] & NSShiftKeyMask) &&
([[theEvent characters] length]) &&
([[NSCharacterSet letterCharacterSet] characterIsMember:[[theEvent characters] characterAtIndex:0]])) {
return [[self aSelector] executeText:(NSEvent *)theEvent];
}
return NO;
}
#pragma mark -
#pragma mark Accessors
- (QSSearchObjectView *)dSelector { return dSelector; }
- (QSSearchObjectView *)aSelector { return aSelector; }
- (QSSearchObjectView *)iSelector { return iSelector; }
- (QSMenuButton *)menuButton { return menuButton; }
- (NSProgressIndicator *)progressIndicator { return progressIndicator; }
- (NSSize) maxIconSize { return NSMakeSize(128, 128); }
- (BOOL)preview { return preview; }
- (void)setPreview: (BOOL)flag { preview = flag; }
- (BOOL)hiding { return hidingWindow; }
- (void)setHiding:(BOOL)flag { hidingWindow = flag; }
@end