diff --git a/Frameworks/DocumentWindow/src/DocumentController.h b/Frameworks/DocumentWindow/src/DocumentController.h index 4e86817f..72392624 100644 --- a/Frameworks/DocumentWindow/src/DocumentController.h +++ b/Frameworks/DocumentWindow/src/DocumentController.h @@ -77,6 +77,7 @@ namespace bundles { struct item_t; typedef std::tr1::shared_ptr item_ptr @property (nonatomic, readonly) NSString* untitledSavePath; + (DocumentController*)controllerForDocument:(document::document_ptr const&)aDocument; ++ (DocumentController*)controllerForPath:(std::string const&)aPath; + (DocumentController*)controllerForUUID:(oak::uuid_t const&)aUUID; - (id)init; diff --git a/Frameworks/DocumentWindow/src/DocumentController.mm b/Frameworks/DocumentWindow/src/DocumentController.mm index 3104aa57..f3c46678 100644 --- a/Frameworks/DocumentWindow/src/DocumentController.mm +++ b/Frameworks/DocumentWindow/src/DocumentController.mm @@ -216,10 +216,16 @@ NSString* const kUserDefaultsFileBrowserPlacementKey = @"fileBrowserPlacement"; bring_to_front([[DocumentController alloc] initWithDocuments:documents]); } } + else if(DocumentController* delegate = [DocumentController controllerForPath:browserPath]) + { + if(!documents.empty()) + [delegate addDocuments:documents andSelect:kSelectDocumentFirst closeOther:NO pruneTabBar:YES]; + bring_to_front(delegate); + } else // if(browserPath != NULL_STR) { close_scratch_project(); - DocumentController* delegate = documents.empty() ? [[DocumentController alloc] init] : [[DocumentController alloc] initWithDocuments:documents]; + delegate = documents.empty() ? [[DocumentController alloc] init] : [[DocumentController alloc] initWithDocuments:documents]; [delegate window]; delegate.fileBrowserHidden = NO; [delegate->fileBrowser showURL:[NSURL fileURLWithPath:[NSString stringWithCxxString:path::resolve(browserPath)]]]; @@ -422,6 +428,22 @@ NSString* const kUserDefaultsFileBrowserPlacementKey = @"fileBrowserPlacement"; return nil; } ++ (DocumentController*)controllerForPath:(std::string const&)aPath +{ + NSURL* url = [NSURL fileURLWithPath:[NSString stringWithCxxString:path::resolve(aPath)]]; + NSString* path = [url isFileURL] ? [url path] : nil; + for(NSWindow* window in [NSApp orderedWindows]) + { + DocumentController* delegate = (DocumentController*)[window delegate]; + if([delegate isKindOfClass:self]) + { + if(!delegate.fileBrowserHidden && [path isEqualToString:delegate.fileBrowserPath]) + return delegate; + } + } + return nil; +} + + (DocumentController*)controllerForUUID:(oak::uuid_t const&)aUUID { for(NSWindow* window in [NSApp orderedWindows])