@implementation AppDelegate
+- (void)applicationDidFinishLaunching:(NSNotification *)notification
+{
+ //エディタフォント設定
+ [sourceEditor setFont:[NSFont fontWithName:@"Source Code Pro" size:14]];
+ //自動改行無効
+ [[sourceEditor textContainer] setContainerSize:NSMakeSize(FLT_MAX, FLT_MAX)];
+ [[sourceEditor textContainer] setWidthTracksTextView:NO];
+ [sourceEditor setHorizontallyResizable:YES];
+}
+
- (IBAction)addressBarURIChanged:(id)sender {
mainWebView.mainFrameURL = addressBar.stringValue;
}
- (IBAction)openCurrentURIForEdit:(id)sender {
if([sourceEditor.string isEqualToString:@""]){
- editingFileURILabel.stringValue = mainWebView.mainFrameURL;
- sourceEditor.string = [mainWebView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('html')[0].innerHTML"];
+ [self openCurrentURIForEdit_ReadURI];
} else{
NSBeginAlertSheet(@"SimpleHTMLEditor", @"No", @"Yes", nil, mainWindow, self.self, @selector(openCurrentURIForEdit_sheetClosed:returnCode:contextInfo:), nil, nil, @"Do you want to discard changes?");
}
break;
case NSAlertAlternateReturn:
- editingFileURILabel.stringValue = mainWebView.mainFrameURL;
- sourceEditor.string = [mainWebView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('html')[0].innerHTML"];
+ [self openCurrentURIForEdit_ReadURI];
break;
}
}
+- (void)openCurrentURIForEdit_ReadURI
+{
+ editingFileURILabel.stringValue = mainWebView.mainFrameURL;
+
+ //sourceEditor.string = [mainWebView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('html')[0].innerHTML"];
+ sourceEditor.string = [NSString stringWithContentsOfURL:[NSURL URLWithString:mainWebView.mainFrameURL] encoding:NSUTF8StringEncoding error:nil];
+}
- (void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame
{
}
}
+- (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
+{
+ NSRunAlertPanel(@"alert", message, @"OK", nil, nil);
+}
+
+- (BOOL)webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
+{
+ NSInteger result = NSRunAlertPanel(@"confirm", message, @"OK", @"Cancel", nil);
+ if (result == NSAlertDefaultReturn) {
+ return YES;
+ }
+ return NO;
+}
+
+- (void) webView:(WebView*)webView addMessageToConsole:(NSDictionary*)message
+{
+ NSLog(@"%@", message);
+ logViewer.string = [logViewer.string stringByAppendingFormat:@"%@\n", message];
+}
+
+- (void) clearLogView:(id)sender
+{
+ logViewer.string = @"";
+}
+
@end