5 // Created by 西田 耀 on 13/04/13.
6 // Copyright (c) 2013年 CHNOSProject. All rights reserved.
9 #import "AppDelegate.h"
11 @implementation AppDelegate
13 NSString *strNotOpened = @"Not opened a file.";
15 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
17 // Insert code here to initialize your application
18 [_filePathLabel setStringValue:strNotOpened];
21 - (IBAction)display:(id)sender {
22 if(![[_filePathLabel stringValue] isEqualToString:strNotOpened]){
23 [mainWebView setMainFrameURL:[_filePathLabel stringValue]];
24 [_addressBar setStringValue:[_filePathLabel stringValue]];
28 - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
30 //最後のwindowが閉じたときに終了するか否か
34 - (void)saveHTMLForFile:(id)sender
36 NSSavePanel *savePanel;
37 NSArray *allowedFileType;
38 NSInteger pressedButton;
42 if([[_filePathLabel stringValue] isEqualToString:strNotOpened] || sender == _menuSaveAsButton){
43 savePanel = [NSSavePanel savePanel];
44 allowedFileType = [NSArray arrayWithObjects:@"htm", @"html", nil];
45 [savePanel setAllowedFileTypes:allowedFileType];
47 pressedButton = [savePanel runModal];
49 switch(pressedButton){
51 path = [savePanel URL];
53 [[_editBox string] writeToURL:path atomically:YES encoding:NSUTF8StringEncoding error:&error];
55 NSRunAlertPanel(@"SimpleHTMLEditor-Error-", [error localizedDescription], @"OK", nil, nil);
57 [_filePathLabel setStringValue:[path path]];
66 path = [NSURL fileURLWithPath:[_filePathLabel stringValue]];
69 [[_editBox string] writeToURL:path atomically:YES encoding:NSUTF8StringEncoding error:&error];
71 NSRunAlertPanel(@"SimpleHTMLEditor-Error-", [error localizedDescription], @"OK", nil, nil);
78 - (void)webViewDidChange:(NSNotification *)notification
80 [_addressBar setStringValue:[[[[[mainWebView mainFrame] dataSource] request] URL] absoluteString]];