diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPBundleEditorController.m | 9 | ||||
-rw-r--r-- | Source/SPBundleHTMLOutputController.h | 10 | ||||
-rw-r--r-- | Source/SPBundleHTMLOutputController.m | 186 | ||||
-rw-r--r-- | Source/SPConstants.h | 1 | ||||
-rw-r--r-- | Source/SPConstants.m | 1 | ||||
-rw-r--r-- | Source/SPCopyTable.m | 6 | ||||
-rw-r--r-- | Source/SPTextView.m | 6 | ||||
-rw-r--r-- | Source/SPTextViewAdditions.m | 6 | ||||
-rw-r--r-- | Source/SPWindowAdditions.m | 19 |
9 files changed, 212 insertions, 32 deletions
diff --git a/Source/SPBundleEditorController.m b/Source/SPBundleEditorController.m index 8587082b..1f9a9732 100644 --- a/Source/SPBundleEditorController.m +++ b/Source/SPBundleEditorController.m @@ -99,9 +99,9 @@ inputEditorScopeArray = [[NSArray arrayWithObjects:SPBundleInputSourceNone, SPBundleInputSourceSelectedText, SPBundleInputSourceEntireContent, nil] retain]; inputInputFieldScopeArray = [[NSArray arrayWithObjects:SPBundleInputSourceNone, SPBundleInputSourceSelectedText, SPBundleInputSourceEntireContent, nil] retain]; inputDataTableScopeArray = [[NSArray arrayWithObjects:SPBundleInputSourceNone, SPBundleInputSourceSelectedTableRowsAsTab, SPBundleInputSourceSelectedTableRowsAsCsv, SPBundleInputSourceSelectedTableRowsAsSqlInsert, SPBundleInputSourceTableRowsAsTab, SPBundleInputSourceTableRowsAsCsv, SPBundleInputSourceTableRowsAsSqlInsert, nil] retain]; - outputEditorScopeArray = [[NSArray arrayWithObjects:SPBundleOutputActionNone, SPBundleOutputActionInsertAsText, SPBundleOutputActionInsertAsSnippet, SPBundleOutputActionReplaceSelection, SPBundleOutputActionReplaceContent, SPBundleOutputActionShowAsTextTooltip, SPBundleOutputActionShowAsHTMLTooltip, nil] retain]; - outputInputFieldScopeArray = [[NSArray arrayWithObjects:SPBundleOutputActionNone, SPBundleOutputActionInsertAsText, SPBundleOutputActionReplaceSelection, SPBundleOutputActionReplaceContent, SPBundleOutputActionShowAsTextTooltip, SPBundleOutputActionShowAsHTMLTooltip, nil] retain]; - outputDataTableScopeArray = [[NSArray arrayWithObjects:SPBundleOutputActionNone, SPBundleOutputActionShowAsTextTooltip, SPBundleOutputActionShowAsHTMLTooltip, nil] retain]; + outputEditorScopeArray = [[NSArray arrayWithObjects:SPBundleOutputActionNone, SPBundleOutputActionInsertAsText, SPBundleOutputActionInsertAsSnippet, SPBundleOutputActionReplaceSelection, SPBundleOutputActionReplaceContent, SPBundleOutputActionShowAsTextTooltip, SPBundleOutputActionShowAsHTMLTooltip, SPBundleOutputActionShowAsHTML, nil] retain]; + outputInputFieldScopeArray = [[NSArray arrayWithObjects:SPBundleOutputActionNone, SPBundleOutputActionInsertAsText, SPBundleOutputActionReplaceSelection, SPBundleOutputActionReplaceContent, SPBundleOutputActionShowAsTextTooltip, SPBundleOutputActionShowAsHTMLTooltip, SPBundleOutputActionShowAsHTML, nil] retain]; + outputDataTableScopeArray = [[NSArray arrayWithObjects:SPBundleOutputActionNone, SPBundleOutputActionShowAsTextTooltip, SPBundleOutputActionShowAsHTMLTooltip, SPBundleOutputActionShowAsHTML, nil] retain]; inputFallbackEditorScopeArray = [[NSArray arrayWithObjects:SPBundleInputSourceNone, SPBundleInputSourceCurrentWord, SPBundleInputSourceCurrentLine, SPBundleInputSourceCurrentQuery, SPBundleInputSourceEntireContent, nil] retain]; inputFallbackInputFieldScopeArray = [[NSArray arrayWithObjects:SPBundleInputSourceNone, SPBundleInputSourceCurrentWord, SPBundleInputSourceCurrentLine, SPBundleInputSourceEntireContent, nil] retain]; @@ -137,15 +137,18 @@ NSLocalizedString(@"Replace Entire Content", @"replace entire content item label"), NSLocalizedString(@"Show as Text Tooltip", @"show as text tooltip item label"), NSLocalizedString(@"Show as HTML Tooltip", @"show as html tooltip item label"), + NSLocalizedString(@"Show as HTML", @"show as html item label"), NSLocalizedString(@"None", @"none menu item label"), NSLocalizedString(@"Insert as Text", @"insert as text item label"), NSLocalizedString(@"Replace Selection", @"replace selection item label"), NSLocalizedString(@"Replace Entire Content", @"replace entire content item label"), NSLocalizedString(@"Show as Text Tooltip", @"show as text tooltip item label"), NSLocalizedString(@"Show as HTML Tooltip", @"show as html tooltip item label"), + NSLocalizedString(@"Show as HTML", @"show as html item label"), NSLocalizedString(@"None", @"none menu item label"), NSLocalizedString(@"Show as Text Tooltip", @"show as text tooltip item label"), NSLocalizedString(@"Show as HTML Tooltip", @"show as html tooltip item label"), + NSLocalizedString(@"Show as HTML", @"show as html item label"), NSLocalizedString(@"None", @"none menu item label"), NSLocalizedString(@"Current Word", @"current word item label"), NSLocalizedString(@"Current Line", @"current line item label"), diff --git a/Source/SPBundleHTMLOutputController.h b/Source/SPBundleHTMLOutputController.h index 9965aec9..1ac550a7 100644 --- a/Source/SPBundleHTMLOutputController.h +++ b/Source/SPBundleHTMLOutputController.h @@ -29,10 +29,18 @@ IBOutlet WebView *webView; - WebPreferences *webPreferences; + NSString *docTitle; + NSString *initHTMLSourceString; + WebPreferences *webPreferences; } +@property(readwrite,retain) NSString *docTitle; +@property(readwrite,retain) NSString *initHTMLSourceString; + +- (IBAction)printDocument:(id)sender; + - (void)displayHTMLContent:(NSString *)content withOptions:(NSDictionary *)displayOptions; +- (void)displayURLString:(NSString *)url withOptions:(NSDictionary *)displayOptions; @end 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<WebPolicyDecisionListener>)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<WebPolicyDecisionListener>)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 diff --git a/Source/SPConstants.h b/Source/SPConstants.h index d6544549..8f164749 100644 --- a/Source/SPConstants.h +++ b/Source/SPConstants.h @@ -447,6 +447,7 @@ extern NSString *SPBundleOutputActionReplaceSelection; extern NSString *SPBundleOutputActionReplaceContent; extern NSString *SPBundleOutputActionShowAsTextTooltip; extern NSString *SPBundleOutputActionShowAsHTMLTooltip; +extern NSString *SPBundleOutputActionShowAsHTML; extern NSString *SPBundleFileCommandKey; extern NSString *SPBundleFileScopeKey; extern NSString *SPBundleFileNameKey; diff --git a/Source/SPConstants.m b/Source/SPConstants.m index 212f3add..2c99a531 100644 --- a/Source/SPConstants.m +++ b/Source/SPConstants.m @@ -266,6 +266,7 @@ NSString *SPBundleOutputActionReplaceSelection = @"replaceselection NSString *SPBundleOutputActionReplaceContent = @"replacecontent"; NSString *SPBundleOutputActionShowAsTextTooltip = @"showastexttooltip"; NSString *SPBundleOutputActionShowAsHTMLTooltip = @"showashtmltooltip"; +NSString *SPBundleOutputActionShowAsHTML = @"showashtml"; NSString *SPBundleFileCommandKey = @"command"; NSString *SPBundleFileScopeKey = @"scope"; NSString *SPBundleFileNameKey = @"name"; diff --git a/Source/SPCopyTable.m b/Source/SPCopyTable.m index 1bfc2277..77dd14f6 100644 --- a/Source/SPCopyTable.m +++ b/Source/SPCopyTable.m @@ -33,6 +33,7 @@ #import "SPTextAndLinkCell.h" #import "SPTooltip.h" #import "SPAlertSheets.h" +#import "SPBundleHTMLOutputController.h" NSInteger MENU_EDIT_COPY = 2001; NSInteger MENU_EDIT_COPY_WITH_COLUMN = 2002; @@ -909,6 +910,11 @@ NSInteger MENU_EDIT_COPY_AS_SQL = 2003; else if([action isEqualToString:SPBundleOutputActionShowAsHTMLTooltip]) { [SPTooltip showWithObject:output atLocation:pos ofType:@"html"]; } + + else if([action isEqualToString:SPBundleOutputActionShowAsHTML]) { + SPBundleHTMLOutputController *c = [[SPBundleHTMLOutputController alloc] init]; + [c displayHTMLContent:output withOptions:nil]; + } } } else { NSString *errorMessage = [err localizedDescription]; diff --git a/Source/SPTextView.m b/Source/SPTextView.m index b7e39a39..ef581a8f 100644 --- a/Source/SPTextView.m +++ b/Source/SPTextView.m @@ -32,6 +32,7 @@ #import "SPNavigatorController.h" #import "SPAlertSheets.h" #import "RegexKitLite.h" +#import "SPBundleHTMLOutputController.h" #pragma mark - #pragma mark lex init @@ -3559,6 +3560,11 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) else if([action isEqualToString:SPBundleOutputActionShowAsHTMLTooltip]) { [SPTooltip showWithObject:output ofType:@"html"]; } + + else if([action isEqualToString:SPBundleOutputActionShowAsHTML]) { + SPBundleHTMLOutputController *c = [[SPBundleHTMLOutputController alloc] init]; + [c displayHTMLContent:output withOptions:nil]; + } } } else { NSString *errorMessage = [err localizedDescription]; diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m index ae07d289..a33d80e4 100644 --- a/Source/SPTextViewAdditions.m +++ b/Source/SPTextViewAdditions.m @@ -24,6 +24,7 @@ #import "SPAlertSheets.h" #import "SPTooltip.h" +#import "SPBundleHTMLOutputController.h" @implementation NSTextView (SPTextViewAdditions) @@ -621,6 +622,11 @@ else if([action isEqualToString:SPBundleOutputActionShowAsHTMLTooltip]) { [SPTooltip showWithObject:output ofType:@"html"]; } + + else if([action isEqualToString:SPBundleOutputActionShowAsHTML]) { + SPBundleHTMLOutputController *c = [[SPBundleHTMLOutputController alloc] init]; + [c displayHTMLContent:output withOptions:nil]; + } } } else { NSString *errorMessage = [err localizedDescription]; diff --git a/Source/SPWindowAdditions.m b/Source/SPWindowAdditions.m index 7fd7a780..4514ac48 100644 --- a/Source/SPWindowAdditions.m +++ b/Source/SPWindowAdditions.m @@ -69,23 +69,4 @@ [self setFrame:frame display:YES animate:YES]; } -/** - * Three finger multi-touch right/left swipe event to go back/forward in table history. - */ -- (void)swipeWithEvent:(NSEvent *)anEvent -{ - - if(![[self delegate] isKindOfClass:[SPWindowController class]] || ![[[self delegate] documents] count]) return; - - id frontDoc = [[self delegate] selectedTableDocument]; - - if( frontDoc && [frontDoc isKindOfClass:[SPDatabaseDocument class]] - && [frontDoc valueForKeyPath:@"spHistoryControllerInstance"] - && ![frontDoc isWorking]) - if([anEvent deltaX] == -1.0f) - [[frontDoc valueForKeyPath:@"spHistoryControllerInstance"] valueForKey:@"goForwardInHistory"]; - else if([anEvent deltaX] == 1.0f) - [[frontDoc valueForKeyPath:@"spHistoryControllerInstance"] valueForKey:@"goBackInHistory"]; -} - @end |