5 // Created by 西田 耀 on 13/04/13.
6 // Copyright (c) 2013年 CHNOSProject. All rights reserved.
9 #import "AppDelegate.h"
11 @implementation AppDelegate
13 - (IBAction)addressBarURIChanged:(id)sender {
14 mainWebView.mainFrameURL = addressBar.stringValue;
17 - (IBAction)openCurrentURIForEdit:(id)sender {
18 if([sourceEditor.string isEqualToString:@""]){
19 editingFileURILabel.stringValue = mainWebView.mainFrameURL;
20 sourceEditor.string = [mainWebView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('html')[0].innerHTML"];
22 NSBeginAlertSheet(@"SimpleHTMLEditor", @"No", @"Yes", nil, mainWindow, self.self, @selector(openCurrentURIForEdit_sheetClosed:returnCode:contextInfo:), nil, nil, @"Do you want to discard changes?");
26 - (void)openCurrentURIForEdit_sheetClosed:(id)sheet returnCode:(int)returnCode contextInfo:(id)contextInfo
29 case NSAlertDefaultReturn:
33 case NSAlertAlternateReturn:
34 editingFileURILabel.stringValue = mainWebView.mainFrameURL;
35 sourceEditor.string = [mainWebView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('html')[0].innerHTML"];
41 - (void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame
43 if(frame == sender.mainFrame){
44 addressBar.stringValue = sender.mainFrameURL;
48 - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
53 - (void)saveEditingDocumentForFile:(id)sender
55 NSSavePanel *savePanel;
56 NSArray *allowedFileType;
57 NSInteger pressedButton;
61 if([[editingFileURILabel stringValue] isEqualToString:@""] || sender == MenuItem_SaveAs){
63 savePanel = [NSSavePanel savePanel];
64 allowedFileType = [NSArray arrayWithObjects:@"htm", @"html", nil];
65 [savePanel setAllowedFileTypes:allowedFileType];
67 pressedButton = [savePanel runModal];
69 switch(pressedButton){
71 path = [savePanel URL];
73 [[sourceEditor string] writeToURL:path atomically:YES encoding:NSUTF8StringEncoding error:&error];
75 NSRunAlertPanel(@"SimpleHTMLEditor-Error-", [error localizedDescription], @"OK", nil, nil);
77 [editingFileURILabel setStringValue:[path path]];
87 path = [NSURL fileURLWithPath:[[editingFileURILabel stringValue] stringByReplacingOccurrencesOfString:@"file://" withString:@""]];
90 [[sourceEditor string] writeToURL:path atomically:YES encoding:NSUTF8StringEncoding error:&error];
92 NSRunAlertPanel(@"SimpleHTMLEditor-Error-", [error localizedDescription], @"OK", nil, nil);
99 - (IBAction)revertToSaved:(id)sender
101 NSBeginAlertSheet(@"SimpleHTMLEditor", @"No", @"Yes", nil, mainWindow, self.self, @selector(revertToSaved_sheetClosed: returnCode:contextInfo:), nil, nil, @"Do you want to revert to saved?");
104 - (void)revertToSaved_sheetClosed:(id)sheet returnCode:(int)returnCode contextInfo:(id)contextInfo
106 switch (returnCode) {
107 case NSAlertDefaultReturn:
111 case NSAlertAlternateReturn:
112 sourceEditor.string = [mainWebView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('html')[0].innerHTML"];