From 5a26675cdc8f6f93162d6753f03508a57ff3112f Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 22 Nov 2010 19:41:01 +0000 Subject: =?UTF-8?q?=E2=80=A2=20Bundle=20Editor=20-=20added=20output=20acti?= =?UTF-8?q?on=20"Show=20as=20HTML"=20=E2=80=A2=20Bundle=20HTML=20output=20?= =?UTF-8?q?-=20finished=20implementation=20-=20added=20print=20support=20(?= =?UTF-8?q?eg=20for=20printing=20reports)=20-=20added=20text=20size=20resi?= =?UTF-8?q?zing=20-=20added=20link=20support=20-=20added=20new=20window=20?= =?UTF-8?q?support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPBundleHTMLOutputController.m | 186 ++++++++++++++++++++++++++++++++-- 1 file changed, 177 insertions(+), 9 deletions(-) (limited to 'Source/SPBundleHTMLOutputController.m') diff --git a/Source/SPBundleHTMLOutputController.m b/Source/SPBundleHTMLOutputController.m index 3b10380d..0501dba9 100644 --- a/Source/SPBundleHTMLOutputController.m +++ b/Source/SPBundleHTMLOutputController.m @@ -26,15 +26,19 @@ #import "SPBundleHTMLOutputController.h" + @implementation SPBundleHTMLOutputController +@synthesize docTitle; +@synthesize initHTMLSourceString; + /** * Initialisation */ - (id)init { - if ((self = [super initWithWindowNibName:@"BundleHTMLOutput"])) { + if (self = [super initWithWindowNibName:@"BundleHTMLOutput"]) { ; @@ -44,28 +48,192 @@ } +- (NSString *)windowNibName +{ + return @"BundleHTMLOutput"; +} + +- (void)windowControllerDidLoadNib:(NSWindowController *) aController +{ + [super windowControllerDidLoadNib:aController]; + + [webView setContinuousSpellCheckingEnabled:NO]; + [webView setGroupName:@"SequelProBundleHTMLOutput"]; + [webView setDrawsBackground:YES]; + [webView setEditable:NO]; + [webView setShouldCloseWithWindow:YES]; + [webView setShouldUpdateWhileOffscreen:YES]; + +} + - (void)displayHTMLContent:(NSString *)content withOptions:(NSDictionary *)displayOptions { + + [[self window] makeKeyAndOrderFront:nil]; + NSString *fullContent = @"%@"; fullContent = [NSString stringWithFormat:fullContent, content]; + + [self setInitHTMLSourceString:fullContent]; [[webView mainFrame] loadHTMLString:fullContent baseURL:nil]; + +} + +- (void)displayURLString:(NSString *)url withOptions:(NSDictionary *)displayOptions +{ + [[self window] makeKeyAndOrderFront:nil]; + [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]]; } -// - (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id)listener -// { -// } -// -// - (void)webView:(WebView*)sender didFinishLoadForFrame:(WebFrame*)frame; -// { -// } +- (id)webView +{ + return webView; +} + +- (void)updateWindow +{ + if (docTitle != nil) + [[webView window] setTitle:docTitle]; + else + [[webView window] setTitle:@""]; +} + +- (BOOL)canMakeTextLarger +{ + return YES; +} + +- (BOOL)canMakeTextSmaller +{ + return YES; +} - (void)dealloc { - [webView release]; + if(webView) [webView release]; if(webPreferences) [webPreferences release]; [super dealloc]; } +- (void) keyDown:(NSEvent *)theEvent +{ + long allFlags = (NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask|NSCommandKeyMask); + + NSString *characters = [theEvent characters]; + NSString *charactersIgnMod = [theEvent charactersIgnoringModifiers]; + unichar insertedCharacter = [characters characterAtIndex:0]; + long curFlags = ([theEvent modifierFlags] & allFlags); + + if(curFlags & NSCommandKeyMask) { + if([charactersIgnMod isEqualToString:@"+"] || [charactersIgnMod isEqualToString:@"="]) // increase text size by 1; ⌘+, ⌘=, and ⌘ numpad + + { + [webView makeTextLarger:nil]; + return; + } + if([charactersIgnMod isEqualToString:@"-"]) // decrease text size by 1; ⌘- and numpad - + { + [webView makeTextSmaller:nil]; + return; + } + if([theEvent keyCode] == 123) // goBack + { + if([webView canGoBack]) + [webView goBack:nil]; + else + [[webView mainFrame] loadHTMLString:[self initHTMLSourceString] baseURL:nil]; + return; + } + if([theEvent keyCode] == 124) // goForward + { + [webView goForward:nil]; + return; + } + } + + [super keyDown: theEvent]; + +} + +- (IBAction)printDocument:(id)sender +{ + [[[[webView mainFrame] frameView] documentView] print:sender]; +} + +#pragma mark - + +- (void)windowShouldClose:(NSNotification *)notification +{ + [webView close]; +} + +#pragma mark - + +- (WebView *)webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request +{ + if(request != nil) { + SPBundleHTMLOutputController *c = [[SPBundleHTMLOutputController alloc] init]; + [c displayURLString:[[request URL] absoluteString] withOptions:nil]; + return [c webView]; + } + return nil; +} + +- (void)webViewShow:(WebView *)sender +{ + id newWebView = [[NSDocumentController sharedDocumentController] documentForWindow:[sender window]]; + [newWebView showWindows]; +} + +- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id)listener +{ + NSInteger navigationType = [[actionInformation objectForKey:WebActionNavigationTypeKey] integerValue]; + + switch(navigationType) { + case WebNavigationTypeLinkClicked: + [[webView mainFrame] loadRequest:request]; + [listener use]; + break; + case WebNavigationTypeReload: + [[webView mainFrame] loadHTMLString:[self initHTMLSourceString] baseURL:nil]; + break; + default: + [listener use]; + } +} + +- (void)webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame +{ + // Only report feedback for the main frame. + if (frame == [sender mainFrame]) { + [self setDocTitle:title]; + [self updateWindow]; + } +} + +- (void)webView:(WebView*)sender didFinishLoadForFrame:(WebFrame*)frame; +{ + // Only report feedback for the main frame. + if (frame == [sender mainFrame]) { + [self updateWindow]; + } +} + +#pragma mark - +#pragma mark multi-touch trackpad support + +/** + * Trackpad two-finger zooming gesture for in/decreasing the font size + */ +- (void)magnifyWithEvent:(NSEvent *)anEvent +{ + + if([anEvent deltaZ]>2.0) + [webView makeTextLarger:nil]; + else if([anEvent deltaZ]<-2.0) + [webView makeTextSmaller:nil]; + +} + @end -- cgit v1.2.3