Skip to content

Commit

Permalink
If opening an already open folder, bring window to front
Browse files Browse the repository at this point in the history
This is mainly for calling ‘mate «directory»’. Reference http://lists.macromates.com/textmate/2012-August/035164.html
  • Loading branch information
nanoant authored and sorbits committed Aug 10, 2012
1 parent 2beac70 commit db294ba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions Frameworks/DocumentWindow/src/DocumentController.h
Expand Up @@ -77,6 +77,7 @@ namespace bundles { struct item_t; typedef std::tr1::shared_ptr<item_t> 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;
Expand Down
24 changes: 23 additions & 1 deletion Frameworks/DocumentWindow/src/DocumentController.mm
Expand Up @@ -216,10 +216,16 @@ void show_documents (std::vector<document::document_ptr> const& documents, std::
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)]]];
Expand Down Expand Up @@ -422,6 +428,22 @@ + (DocumentController*)controllerForDocument:(document::document_ptr const&)aDoc
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])
Expand Down

0 comments on commit db294ba

Please sign in to comment.