|
9 | 9 | #import "Finder.h"
|
10 | 10 | #import "PathFinder.h"
|
11 | 11 | #import "RTFWindowController.h"
|
| 12 | +#import "SystemEvents.h" |
12 | 13 |
|
13 | 14 | NSString* const DTResultsToKeepKey = @"DTResultsToKeep";
|
14 | 15 | NSString* const DTHotkeyAlsoDeactivatesKey = @"DTHotkeyAlsoDeactivates";
|
@@ -486,11 +487,75 @@ - (void)hotkeyPressed {
|
486 | 487 | @catch (NSException* e) {
|
487 | 488 | // Fall through to the default attempts to set WD from selection
|
488 | 489 | }
|
489 |
| - |
| 490 | + |
| 491 | + } |
| 492 | + |
| 493 | + // Also use ScriptingBridge special case for Eclipse IDE |
| 494 | + else if([frontmostAppBundleID isEqualToString:@"org.eclipse.platform.ide"]) { |
| 495 | + |
| 496 | + SystemEventsApplication * SBSysEvents = (SystemEventsApplication *)[SBApplication applicationWithBundleIdentifier:@"com.apple.systemevents"]; |
| 497 | + SystemEventsProcess * process = [[SBSysEvents applicationProcesses] objectWithName:@"Eclipse"]; |
| 498 | + |
| 499 | + NSString * windowTitle = @""; |
| 500 | + for (SystemEventsWindow * win in [process windows]) { |
| 501 | + NSNumber * isMain = [(SBObject *)[(SystemEventsAttribute *)[[win attributes] objectWithName:@"AXMain"] value] get]; |
| 502 | + if (![isMain boolValue]) { |
| 503 | + continue; |
| 504 | + } |
| 505 | + windowTitle = [(SBObject *)[(SystemEventsAttribute *)[[win attributes] objectWithName:@"AXTitle"] value] get]; |
| 506 | + NSArray * windowPos = [(SBObject *)[(SystemEventsAttribute *)[[win attributes] objectWithName:@"AXPosition"] value] get]; |
| 507 | + NSArray * windowSize = [(SBObject *)[(SystemEventsAttribute *)[[win attributes] objectWithName:@"AXSize"] value] get]; |
| 508 | + NSRect windowBounds = NSMakeRect( |
| 509 | + [[windowPos objectAtIndex:0] floatValue], |
| 510 | + [[windowPos objectAtIndex:1] floatValue], |
| 511 | + [[windowSize objectAtIndex:0] floatValue], |
| 512 | + [[windowSize objectAtIndex:1] floatValue] |
| 513 | + ); |
| 514 | + //NSLog(@"Eclipse window bounds: %@", NSStringFromRect(windowBounds)); |
| 515 | + CGFloat screenHeight = [[[NSScreen screens] firstObject] frame].size.height; |
| 516 | + windowBounds.origin.y = screenHeight - windowBounds.origin.y - windowBounds.size.height; |
| 517 | + //NSLog(@"Eclipse window bounds: %@", NSStringFromRect(windowBounds)); |
| 518 | + frontWindowBounds = windowBounds; |
| 519 | + } |
| 520 | + if ([windowTitle length] == 0) { |
| 521 | + NSLog(@"Could not find Eclipse window title"); |
| 522 | + goto done; |
| 523 | + } |
| 524 | + //NSLog(@"Ecliplse Title: %@", windowTitle); |
| 525 | + |
| 526 | + NSArray * parts = [windowTitle componentsSeparatedByString:@" - "]; |
| 527 | + NSString * workspacePath = [parts lastObject]; |
| 528 | + NSString * filepathWithPackage = [parts objectAtIndex:([parts count] - 3)]; |
| 529 | + NSRange firstSlash = [filepathWithPackage rangeOfString:@"/"]; |
| 530 | + NSString * package = [filepathWithPackage substringToIndex:firstSlash.location]; |
| 531 | + NSString * filepathWithinPackage = [filepathWithPackage substringFromIndex:firstSlash.location+1]; |
| 532 | + |
| 533 | + |
| 534 | + //NSLog(@"WORKSPACE: %@", workspacePath); |
| 535 | + //NSLog(@"PACKAGE: %@", package); |
| 536 | + //NSLog(@"FILEPATH_WITHIN_PACKAGE: %@", filepathWithinPackage); |
| 537 | + |
| 538 | + NSString *findPackagePathCmd = [NSString stringWithFormat:@"find \"%@\" -type f -name .project | xargs -n10 grep \"<name>%@</name>\" | awk 'BEGIN{FS=\"/.project:\"}{print $1}'", workspacePath, package]; |
| 539 | + NSString *packagePath = [[self outputStringFromCommand:@"/bin/sh" withArguments:@[@"-c",findPackagePathCmd]] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; |
| 540 | + if ([packagePath length] == 0) { |
| 541 | + NSLog(@"Empty Package path"); |
| 542 | + goto done; |
| 543 | + } |
| 544 | + //NSLog(@"PACKAGE_PATH: %@", packagePath); |
| 545 | + |
| 546 | + |
| 547 | + NSString *findFullFilepathCmd = [NSString stringWithFormat:@"find \"%@\" -type f -path '*%@'", packagePath, filepathWithinPackage]; |
| 548 | + NSString *fullFilepath = [[self outputStringFromCommand:@"/bin/sh" withArguments:@[@"-c",findFullFilepathCmd]] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];; |
| 549 | + //NSLog(@"FULL_FILEPATH: %@", fullFilepath); |
| 550 | + //NSLog(@"FULL_FILEPATH (URL): %@", [[NSURL fileURLWithPath:fullFilepath] absoluteString]); |
| 551 | + |
| 552 | + workingDirectory = packagePath; |
| 553 | + selectionURLStrings = @[[[NSURL fileURLWithPath:fullFilepath] absoluteString]]; |
| 554 | + goto done; |
490 | 555 | }
|
491 | 556 |
|
492 | 557 | // Otherwise, try to talk to the frontmost app with the Accessibility APIs
|
493 |
| - else if([self isAXTrustedPromptIfNot:NO]) { |
| 558 | + else if([self isAXTrustedPromptIfNot:NO]) { |
494 | 559 | // Use Accessibility API
|
495 | 560 | AXError axErr = kAXErrorSuccess;
|
496 | 561 |
|
@@ -631,4 +696,33 @@ - (void)changeFont:(id) __unused sender{
|
631 | 696 | [currentPrefsValues setValue:fontSize forKey:DTFontSizeKey];
|
632 | 697 | }
|
633 | 698 |
|
| 699 | +#pragma mark util |
| 700 | + |
| 701 | +-(NSString *)outputStringFromCommand:(NSString *)command |
| 702 | + withArguments:(NSArray *)arguments { |
| 703 | + NSTask *task; |
| 704 | + task = [[NSTask alloc] init]; |
| 705 | + [task setLaunchPath: command]; |
| 706 | + |
| 707 | + NSLog(@"run task: %@",task); |
| 708 | + [task setArguments: arguments]; |
| 709 | + |
| 710 | + NSPipe *pipe; |
| 711 | + pipe = [NSPipe pipe]; |
| 712 | + [task setStandardOutput: pipe]; |
| 713 | + |
| 714 | + NSFileHandle *file; |
| 715 | + file = [pipe fileHandleForReading]; |
| 716 | + |
| 717 | + [task launch]; |
| 718 | + |
| 719 | + NSData *data; |
| 720 | + data = [file readDataToEndOfFile]; |
| 721 | + |
| 722 | + NSString *output; |
| 723 | + output = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding]; |
| 724 | + NSLog(@"output: %@", output); |
| 725 | + return output; |
| 726 | +} |
| 727 | + |
634 | 728 | @end
|
0 commit comments