aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPBundleHTMLOutputController.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-12-08 22:51:45 +0000
committerBibiko <bibiko@eva.mpg.de>2010-12-08 22:51:45 +0000
commit34eac092acd118620c2653731e283ca8aa7fc383 (patch)
tree0432f331437102e4d2d08af587237904804f100f /Source/SPBundleHTMLOutputController.m
parenteb5fa28ec49e2aaecb5fd38c86f42a530498267b (diff)
downloadsequelpro-34eac092acd118620c2653731e283ca8aa7fc383.tar.gz
sequelpro-34eac092acd118620c2653731e283ca8aa7fc383.tar.bz2
sequelpro-34eac092acd118620c2653731e283ca8aa7fc383.zip
• added Save Page As and View Source to HTML output window's context menu
Diffstat (limited to 'Source/SPBundleHTMLOutputController.m')
-rw-r--r--Source/SPBundleHTMLOutputController.m81
1 files changed, 79 insertions, 2 deletions
diff --git a/Source/SPBundleHTMLOutputController.m b/Source/SPBundleHTMLOutputController.m
index b89606f9..a630eb06 100644
--- a/Source/SPBundleHTMLOutputController.m
+++ b/Source/SPBundleHTMLOutputController.m
@@ -24,6 +24,7 @@
#import "SPBundleHTMLOutputController.h"
+#import "SPAlertSheets.h"
@@ -121,7 +122,6 @@
- (void)keyDown:(NSEvent *)theEvent
{
long allFlags = (NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask|NSCommandKeyMask);
-
NSString *characters = [theEvent characters];
NSString *charactersIgnMod = [theEvent charactersIgnoringModifiers];
unichar insertedCharacter = [characters characterAtIndex:0];
@@ -157,11 +157,63 @@
}
+/**
+ * Sheet did end method
+ */
+- (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo
+{
+
+ // Order out current sheet to suppress overlapping of sheets
+ if ([sheet respondsToSelector:@selector(orderOut:)])
+ [sheet orderOut:nil];
+ else if ([sheet respondsToSelector:@selector(window)])
+ [[sheet window] orderOut:nil];
+
+ if([contextInfo isEqualToString:@"saveDocument"]) {
+ if (returnCode == NSOKButton) {
+ NSString *sourceCode = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('html')[0].outerHTML"];
+ NSError *err = nil;
+ [sourceCode writeToFile:[sheet filename]
+ atomically:YES
+ encoding:NSUTF8StringEncoding
+ error:&err];
+ if(err != nil) {
+ SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil,
+ [NSString stringWithFormat:@"%@", [err localizedDescription]]);
+ }
+
+ }
+ }
+}
+
- (IBAction)printDocument:(id)sender
{
[[[[webView mainFrame] frameView] documentView] print:sender];
}
+- (void)showSourceCode
+{
+ NSString *sourceCode = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('html')[0].outerHTML"];
+ SPBundleHTMLOutputController *c = [[SPBundleHTMLOutputController alloc] init];
+ [c displayHTMLContent:[NSString stringWithFormat:@"<pre>%@</pre>", [sourceCode HTMLEscapeString]] withOptions:nil];
+ [[NSApp delegate] addHTMLOutputController:c];
+}
+
+- (void)saveDocument
+{
+ NSSavePanel *panel = [NSSavePanel savePanel];
+
+ [panel setRequiredFileType:@"html"];
+
+ [panel setExtensionHidden:NO];
+ [panel setAllowsOtherFileTypes:YES];
+ [panel setCanSelectHiddenExtension:YES];
+ [panel setCanCreateDirectories:YES];
+
+ [panel beginSheetForDirectory:nil file:@"output" modalForWindow:[self window] modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:@"saveDocument"];
+}
+
+
#pragma mark -
- (void)windowWillClose:(NSNotification *)notification
@@ -170,11 +222,36 @@
[webView close];
[self setInitHTMLSourceString:@""];
windowUUID = @"";
- // [[notification object] release];
}
#pragma mark -
+- (NSArray *)webView:(WebView *)sender contextMenuItemsForElement:(NSDictionary *)element defaultMenuItems:(NSArray *)defaultMenuItems
+{
+ NSMutableArray *webViewMenuItems = [[defaultMenuItems mutableCopy] autorelease];
+
+ [webViewMenuItems addObject:[NSMenuItem separatorItem]];
+
+ NSMenuItem *anItem;
+ anItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"View Source", @"view html source code menu item title") action:@selector(showSourceCode) keyEquivalent:@""];
+ [anItem setEnabled:YES];
+ [anItem setTarget:self];
+ [webViewMenuItems addObject:anItem];
+ [anItem release];
+ anItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Save Page As…", @"save page as menu item title") action:@selector(saveDocument) keyEquivalent:@""];
+ [anItem setEnabled:YES];
+ [anItem setTarget:self];
+ [webViewMenuItems addObject:anItem];
+ [anItem release];
+ anItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Print Page…", @"print page menu item title") action:@selector(printDocument:) keyEquivalent:@""];
+ [anItem setEnabled:YES];
+ [anItem setTarget:self];
+ [webViewMenuItems addObject:anItem];
+ [anItem release];
+
+ return webViewMenuItems;
+}
+
- (WebView *)webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request
{
if(request != nil) {