Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding an alert when not finding the Test class #4

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions Aviator/Aviator.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,27 @@ + (void)pluginDidLoad:(NSBundle *)plugin {

- (id)init {
if (self = [super init]) {
[self removeConflictingKeyBinding];
[self addJumpItem];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidFinishLaunchingNotification:)
name:NSApplicationDidFinishLaunchingNotification
object:nil];
}
return self;
}

#pragma mark -
- (void)applicationDidFinishLaunchingNotification:(NSNotification *)notification {
[self removeConflictingKeyBinding];
[self addJumpItem];
}

#pragma mark -

- (void)removeConflictingKeyBinding {
@try{
NSMenuItem *fileItem = [[NSApp mainMenu] itemWithTitle:@"File"];
NSMenuItem *newWindowItem = [[[[[fileItem submenu] itemArray] firstObject] submenu] itemArray][1];
[newWindowItem setKeyEquivalentModifierMask:NSShiftKeyMask | NSAlternateKeyMask | NSCommandKeyMask];
} @catch(NSException *) {}
} @catch(NSException *e) { NSLog(@"prevented plugin crash from removeConflictingKeyBinding : %@", e); }
}

// TODO: Investigate why "Navigate" doesn't work
Expand Down
21 changes: 18 additions & 3 deletions Aviator/TFFFileSwitcher.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#import "TFFXcodeDocumentNavigator.h"
#import "TFFFileProvider.h"

@interface TFFFileSwitcher ()
@interface TFFFileSwitcher () <NSAlertDelegate>
@property (nonatomic, readonly) TFFFileProvider *fileProvider;
@end

Expand All @@ -22,11 +22,26 @@ - (void)switchBetweenReferenceCollectionFilesForCurrentSourceDocument:(IDESource

NSString *fileName = [[[sourceCodeDocument filePath] fileURL] lastPathComponent];
if ([referenceCollection.headerFile.name isEqualToString:fileName] || [referenceCollection.sourceFile.name isEqualToString:fileName]) {
[[self XcodeNavigatorClassSeam] jumpToFileURL:[NSURL fileURLWithPath:referenceCollection.testFile.absolutePath]];
if( referenceCollection.testFile == nil ) {
NSString *testFilename = [[fileName stringByDeletingPathExtension] stringByAppendingString:@"Tests"];
NSAlert *alert = [[NSAlert alloc]init];
[alert setDelegate:self];
[alert addButtonWithTitle:@"Copy test class name"];
[alert addButtonWithTitle:@"Cancel"];
[alert setMessageText:[NSString stringWithFormat:@"Can't find %@ in project, maybe you want to create it ?", testFilename]];
long rCode = [alert runModal];
if( rCode == NSAlertFirstButtonReturn ) {
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
[pasteboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
[pasteboard setString:testFilename forType:NSStringPboardType];
}
} else {
[[self XcodeNavigatorClassSeam] jumpToFileURL:[NSURL fileURLWithPath:referenceCollection.testFile.absolutePath]];
}
} else if ([referenceCollection.testFile.name isEqualToString:fileName]) {
[[self XcodeNavigatorClassSeam] jumpToFileURL:[NSURL fileURLWithPath:referenceCollection.sourceFile.absolutePath]];
}
} @catch (NSException *) {}
} @catch (NSException *e) { NSLog(@"prevented plugin crash from switchBetweenReferenceCollectionFilesForCurrentSourceDocument : %@", e); }
}

- (Class)XcodeNavigatorClassSeam {
Expand Down