Skip to content

Commit

Permalink
show button only if file is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
jcavar committed Dec 16, 2014
1 parent 0a1ea11 commit dacf556
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions SpotlightFinder/SPOTFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@

@interface SPOTFinder : NSObject

@property (strong, nonatomic) NSButton *buttonShowInFinder;

@end
26 changes: 26 additions & 0 deletions SpotlightFinder/SPOTFinder.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ + (void)load {
[button setTarget:[self sharedInstance]];
[button setAction:@selector(buttonShowInFinderOnClick)];
[view addSubview:button];

[SPOTFinder sharedInstance].buttonShowInFinder = button;

Class workspaceTabController = NSClassFromString(@"SPAppDelegate");
Method buildMethod = class_getInstanceMethod(workspaceTabController, NSSelectorFromString(@"didShowPreviewItem:"));
Method buildReplaceMethod = class_getInstanceMethod(workspaceTabController, NSSelectorFromString(@"didShowPreviewItemReplace:"));
method_exchangeImplementations(buildMethod, buildReplaceMethod);
}
}

Expand All @@ -53,3 +60,22 @@ - (void)buttonShowInFinderOnClick {
}

@end

@implementation NSObject (SPOTAdditions)

- (void)didShowPreviewItemReplace:(id)arg {

NSLog(@"SPOTFinder called show preview");
[SPOTFinder sharedInstance].buttonShowInFinder.hidden = YES;
SPAppDelegate *appDelegate = [NSApp delegate];
if ([[appDelegate selectedResult] respondsToSelector:@selector(filePath)]) {
id result = [[appDelegate selectedResult] filePath];
if ([result isKindOfClass:NSString.class]) {
NSLog(@"SPOTFinder selected path %@", result);
[SPOTFinder sharedInstance].buttonShowInFinder.hidden = NO;
}
}
[self didShowPreviewItemReplace:arg];
}

@end

0 comments on commit dacf556

Please sign in to comment.