--- /dev/null
+//
+// AppDelegate.m
+// SimpleHTMLEditor
+//
+// Created by 西田 耀 on 13/04/13.
+// Copyright (c) 2013年 CHNOSProject. All rights reserved.
+//
+
+#import "AppDelegate.h"
+
+@implementation AppDelegate
+
+NSString *strNotOpened = @"Not opened a file.";
+
+- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
+{
+ // Insert code here to initialize your application
+ [_filePathLabel setStringValue:strNotOpened];
+}
+
+- (IBAction)display:(id)sender {
+ if(![[_filePathLabel stringValue] isEqualToString:strNotOpened]){
+ [mainWebView setMainFrameURL:[_filePathLabel stringValue]];
+ [_addressBar setStringValue:[_filePathLabel stringValue]];
+ }
+}
+
+- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
+{
+ //最後のwindowが閉じたときに終了するか否か
+ return YES;
+}
+
+- (void)saveHTMLForFile:(id)sender
+{
+ NSSavePanel *savePanel;
+ NSArray *allowedFileType;
+ NSInteger pressedButton;
+ NSURL *path;
+ NSError *error;
+
+ if([[_filePathLabel stringValue] isEqualToString:strNotOpened] || sender == _menuSaveAsButton){
+ savePanel = [NSSavePanel savePanel];
+ allowedFileType = [NSArray arrayWithObjects:@"htm", @"html", nil];
+ [savePanel setAllowedFileTypes:allowedFileType];
+
+ pressedButton = [savePanel runModal];
+
+ switch(pressedButton){
+ case NSOKButton:
+ path = [savePanel URL];
+ error = nil;
+ [[_editBox string] writeToURL:path atomically:YES encoding:NSUTF8StringEncoding error:&error];
+ if(error != nil){
+ NSRunAlertPanel(@"SimpleHTMLEditor-Error-", [error localizedDescription], @"OK", nil, nil);
+ } else{
+ [_filePathLabel setStringValue:[path path]];
+ }
+
+ break;
+ case NSCancelButton:
+
+ break;
+ };
+ } else{
+ path = [NSURL fileURLWithPath:[_filePathLabel stringValue]];
+
+ error = nil;
+ [[_editBox string] writeToURL:path atomically:YES encoding:NSUTF8StringEncoding error:&error];
+ if(error != nil){
+ NSRunAlertPanel(@"SimpleHTMLEditor-Error-", [error localizedDescription], @"OK", nil, nil);
+ }
+
+
+ }
+}
+
+- (void)webViewDidChange:(NSNotification *)notification
+{
+ [_addressBar setStringValue:[[[[[mainWebView mainFrame] dataSource] request] URL] absoluteString]];
+
+}
+
+@end