From c1561b572cb258a8ff1b8290c56cc22604d4aadd Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 10 Dec 2010 14:38:31 +0000 Subject: =?UTF-8?q?=E2=80=A2=20Bundle=20HTML=20output=20-=20fixed=20init?= =?UTF-8?q?=20and=20release=20issue=20-=20started=20to=20allow=20JavaScrip?= =?UTF-8?q?t=20(from=20inside=20the=20HTML=20output=20window=20via=20js-ob?= =?UTF-8?q?ject=20window.system)=20to=20communicate=20with=20SequelPro?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPBundleHTMLOutputController.m | 73 +++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 11 deletions(-) (limited to 'Source/SPBundleHTMLOutputController.m') diff --git a/Source/SPBundleHTMLOutputController.m b/Source/SPBundleHTMLOutputController.m index a630eb06..8ae91400 100644 --- a/Source/SPBundleHTMLOutputController.m +++ b/Source/SPBundleHTMLOutputController.m @@ -26,8 +26,6 @@ #import "SPBundleHTMLOutputController.h" #import "SPAlertSheets.h" - - @implementation SPBundleHTMLOutputController @synthesize docTitle; @@ -44,6 +42,13 @@ [[self window] setReleasedWhenClosed:YES]; + [webView setContinuousSpellCheckingEnabled:NO]; + [webView setGroupName:@"SequelProBundleHTMLOutput"]; + [webView setDrawsBackground:YES]; + [webView setEditable:NO]; + [webView setShouldCloseWithWindow:YES]; + [webView setShouldUpdateWhileOffscreen:NO]; + } return self; @@ -59,13 +64,6 @@ { [super windowControllerDidLoadNib:aController]; - [webView setContinuousSpellCheckingEnabled:NO]; - [webView setGroupName:@"SequelProBundleHTMLOutput"]; - [webView setDrawsBackground:YES]; - [webView setEditable:NO]; - [webView setShouldCloseWithWindow:YES]; - [webView setShouldUpdateWhileOffscreen:NO]; - } - (void)displayHTMLContent:(NSString *)content withOptions:(NSDictionary *)displayOptions @@ -114,9 +112,7 @@ - (void)dealloc { - if(webView) [webView release]; if(webPreferences) [webPreferences release]; - // [super dealloc]; } - (void)keyDown:(NSEvent *)theEvent @@ -222,6 +218,7 @@ [webView close]; [self setInitHTMLSourceString:@""]; windowUUID = @""; + [self release]; } #pragma mark - @@ -312,6 +309,60 @@ } } +#pragma mark - +#pragma mark JS support + +- (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame +{ + NSLog(@"alert %@", message); +} + +- (BOOL)webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame +{ + NSLog(@"confirm"); + return NO; +} + +- (NSString *)webView:(WebView *)sender runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText initiatedByFrame:(WebFrame *)frame +{ + return @"be patient"; +} + +- (void)webView:(WebView *)sender windowScriptObjectAvailable: (WebScriptObject *)windowScriptObject +{ + [windowScriptObject setValue:self forKey:@"system"]; +} + ++ (NSString *)webScriptNameForSelector:(SEL)aSelector +{ + if (aSelector == @selector(run:)) + return @"run"; + return @""; +} + ++ (BOOL)isSelectorExcludedFromWebScript:(SEL)selector { + if (selector == @selector(run:)) { + return NO; + } + return YES; +} + ++ (BOOL)isKeyExcludedFromWebScript:(const char *)property { + if (strcmp(property, "run") == 0) { + return NO; + } + return YES; +} + +- (void) windowScriptObjectAvailable:(WebScriptObject*)webScriptObject { + [webScriptObject setValue:self forKey:@"system"]; +} + +- (NSString *)run:(NSString*)command +{ + return [NSString stringWithFormat:@"Hallo-%@", [command description]]; +} + #pragma mark - #pragma mark multi-touch trackpad support -- cgit v1.2.3