Skip to content

Commit

Permalink
Create a PolicyDelegate for NavigationAction
Browse files Browse the repository at this point in the history
Have links clicked by the user be opened in the user's default
browser.
  • Loading branch information
sc68cal committed Dec 31, 2012
1 parent bc13d12 commit 366b2ab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ViewDown/Document.h
Expand Up @@ -52,6 +52,8 @@
-(void)webView:(WebView *)webView willPerformDragDestinationAction:(WebDragDestinationAction)action forDraggingInfo:(id <NSDraggingInfo>)draggingInfo;

-(void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame;

-(void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener;
/////////////////////////////////////////////////

@end
15 changes: 15 additions & 0 deletions ViewDown/Document.m
Expand Up @@ -121,6 +121,8 @@ -(void)awakeFromNib
[self setCurrent:NULL];
}

[web setPolicyDelegate:self];

}


Expand Down Expand Up @@ -573,6 +575,19 @@ -(NSPrintOperation *)printOperationWithSettings:(NSDictionary *)printSettings er

}

- (void)webView:(WebView *)sender decidePolicyForNavigationAction:(NSDictionary *)actionInformation
request:(NSURLRequest *)request frame:(WebFrame *)frame
decisionListener:(id <WebPolicyDecisionListener>)listener
{
NSURL *url = [request URL];
if(url.isFileURL)
[listener use];
else{
[listener ignore];
[[NSWorkspace sharedWorkspace] openURL:url];
}
}

+ (BOOL)autosavesInPlace
{
return YES;
Expand Down

0 comments on commit 366b2ab

Please sign in to comment.