OSDN Git Service

HMExternalBrowserWindowControllerクラスをSwiftで書き換え
authormasakih <masakih@users.sourceforge.jp>
Sun, 21 Dec 2014 15:19:30 +0000 (00:19 +0900)
committermasakih <masakih@users.sourceforge.jp>
Sun, 21 Dec 2014 15:19:30 +0000 (00:19 +0900)
KCD.xcodeproj/project.pbxproj
KCD/HMAppDelegate.m
KCD/HMExternalBrowserWindowController.h [deleted file]
KCD/HMExternalBrowserWindowController.m [deleted file]
KCD/HMExternalBrowserWindowController.swift [new file with mode: 0644]
KCD/HMExternalBrowserWindowController.xib

index 252f2a6..1906ef0 100644 (file)
@@ -44,6 +44,7 @@
                F454F7831A261844003042DD /* HMFleetInformation.m in Sources */ = {isa = PBXBuildFile; fileRef = F454F7821A261844003042DD /* HMFleetInformation.m */; };
                F4551BDC1A46A9D100BB0235 /* HMHistoryWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4551BDB1A46A9D100BB0235 /* HMHistoryWindowController.swift */; };
                F4551BDE1A46C23100BB0235 /* HMTimerCountFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4551BDD1A46C23100BB0235 /* HMTimerCountFormatter.swift */; };
+               F4551BE21A47044A00BB0235 /* HMExternalBrowserWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4551BE11A47044A00BB0235 /* HMExternalBrowserWindowController.swift */; };
                F46F103618A7CE310063E503 /* HMJSONViewCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F46F103518A7CE310063E503 /* HMJSONViewCommand.m */; };
                F46F104118A9B85E0063E503 /* HMJSONNode.m in Sources */ = {isa = PBXBuildFile; fileRef = F46F104018A9B85E0063E503 /* HMJSONNode.m */; };
                F46F104518AA50730063E503 /* HMBroserWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = F46F104318AA50730063E503 /* HMBroserWindowController.m */; };
@@ -77,7 +78,6 @@
                F4B1E30919C73B6A00805879 /* HMSuppliesView.m in Sources */ = {isa = PBXBuildFile; fileRef = F4B1E30619C73B6A00805879 /* HMSuppliesView.m */; };
                F4B1E30C19D1C06900805879 /* HMHokyuChargeCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4B1E30B19D1C06900805879 /* HMHokyuChargeCommand.m */; };
                F4B1E30F19D1C9C400805879 /* HMApplySuppliesCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4B1E30E19D1C9C400805879 /* HMApplySuppliesCommand.m */; };
-               F4B2A08F1A1F9C2100D2EF12 /* HMExternalBrowserWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = F4B2A08D1A1F9C2100D2EF12 /* HMExternalBrowserWindowController.m */; };
                F4B2A0901A1F9C2100D2EF12 /* HMExternalBrowserWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4B2A08E1A1F9C2100D2EF12 /* HMExternalBrowserWindowController.xib */; };
                F4B2D02B18F83A2F00542742 /* HMScreenshotWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4B2D02D18F83A2F00542742 /* HMScreenshotWindowController.xib */; };
                F4B2D03118F83CBB00542742 /* HMDeckViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F4B2D02F18F83CBB00542742 /* HMDeckViewController.m */; };
                F454F7821A261844003042DD /* HMFleetInformation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMFleetInformation.m; sourceTree = "<group>"; };
                F4551BDB1A46A9D100BB0235 /* HMHistoryWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMHistoryWindowController.swift; sourceTree = "<group>"; };
                F4551BDD1A46C23100BB0235 /* HMTimerCountFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMTimerCountFormatter.swift; sourceTree = "<group>"; };
+               F4551BE11A47044A00BB0235 /* HMExternalBrowserWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMExternalBrowserWindowController.swift; sourceTree = "<group>"; };
                F46F103418A7CE310063E503 /* HMJSONViewCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMJSONViewCommand.h; sourceTree = "<group>"; };
                F46F103518A7CE310063E503 /* HMJSONViewCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMJSONViewCommand.m; sourceTree = "<group>"; };
                F46F103F18A9B85E0063E503 /* HMJSONNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMJSONNode.h; sourceTree = "<group>"; };
                F4B1E30B19D1C06900805879 /* HMHokyuChargeCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMHokyuChargeCommand.m; sourceTree = "<group>"; };
                F4B1E30D19D1C9C400805879 /* HMApplySuppliesCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMApplySuppliesCommand.h; sourceTree = "<group>"; };
                F4B1E30E19D1C9C400805879 /* HMApplySuppliesCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMApplySuppliesCommand.m; sourceTree = "<group>"; };
-               F4B2A08C1A1F9C2100D2EF12 /* HMExternalBrowserWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMExternalBrowserWindowController.h; sourceTree = "<group>"; };
-               F4B2A08D1A1F9C2100D2EF12 /* HMExternalBrowserWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMExternalBrowserWindowController.m; sourceTree = "<group>"; };
                F4B2A08E1A1F9C2100D2EF12 /* HMExternalBrowserWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = HMExternalBrowserWindowController.xib; sourceTree = "<group>"; };
                F4B2D02C18F83A2F00542742 /* ja */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = ja; path = ja.lproj/HMScreenshotWindowController.xib; sourceTree = "<group>"; };
                F4B2D02E18F83CBB00542742 /* HMDeckViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMDeckViewController.h; sourceTree = "<group>"; };
                                F4A2AF561A074DE40024BD9E /* HMScreenshotListWindowController.xib */,
                                F4A2AF591A0F9B490024BD9E /* HMScreenshotInformation.h */,
                                F4A2AF5A1A0F9B490024BD9E /* HMScreenshotInformation.m */,
-                               F4B2A08C1A1F9C2100D2EF12 /* HMExternalBrowserWindowController.h */,
-                               F4B2A08D1A1F9C2100D2EF12 /* HMExternalBrowserWindowController.m */,
+                               F4551BE11A47044A00BB0235 /* HMExternalBrowserWindowController.swift */,
                                F4B2A08E1A1F9C2100D2EF12 /* HMExternalBrowserWindowController.xib */,
                        );
                        name = UI;
                                F426802B194D0F4800B2C27F /* HMMemberShip2Command.m in Sources */,
                                F4B30CFA1A468216008E3D79 /* HMPlanToShowsBoldFontTransformer.swift in Sources */,
                                F4AA06101931869E00844688 /* HMBattleResultCommand.m in Sources */,
+                               F4551BE21A47044A00BB0235 /* HMExternalBrowserWindowController.swift in Sources */,
                                F4B3DC4418E70B370011B4FC /* HMServerDataStore.m in Sources */,
                                F4AA0607192E3B6200844688 /* HMMapStartCommand.m in Sources */,
                                F4AA0604192E20F500844688 /* HMCalculateDamageCommand.m in Sources */,
                                F4B414FB18B1FB6C00468DAF /* HMMasterMapCellCommand.m in Sources */,
                                F4C118FA18A67B1C005D5B25 /* CacheStoragePolicy.m in Sources */,
                                F4A3AD9219BDDD8E00FDBF80 /* HMPreferencePanelController.m in Sources */,
-                               F4B2A08F1A1F9C2100D2EF12 /* HMExternalBrowserWindowController.m in Sources */,
                                F4B3DC2118DECF570011B4FC /* HMTSVSupport.m in Sources */,
                                F4B1E30819C73B6A00805879 /* HMSuppliesCell.m in Sources */,
                                F4A3AD8E19BB220000FDBF80 /* HMMaskInfomation.m in Sources */,
index a2908b5..3f644b6 100644 (file)
@@ -16,8 +16,6 @@
 
 #import "HMFleetInformation.h"
 
-#import "HMExternalBrowserWindowController.h"
-
 #import "HMTSVSupport.h"
 
 #import "KCD-Swift.h"
 - (IBAction)showExternalBrowserWindow:(id)sender
 {
        if(!self.externalBrowserWindowController) {
-               self.externalBrowserWindowController = [HMExternalBrowserWindowController new];
+               self.externalBrowserWindowController = [HMExternalBrowserWindowController create];
        }
        
        NSWindow *window = self.externalBrowserWindowController.window;
diff --git a/KCD/HMExternalBrowserWindowController.h b/KCD/HMExternalBrowserWindowController.h
deleted file mode 100644 (file)
index 9d19ddd..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-//
-//  HMExternalBrowserWindowController.h
-//  KCD
-//
-//  Created by Hori,Masaki on 2014/11/22.
-//  Copyright (c) 2014年 Hori,Masaki. All rights reserved.
-//
-
-#import <Cocoa/Cocoa.h>
-
-#import <WebKit/WebKit.h>
-
-
-@interface HMExternalBrowserWindowController : NSWindowController
-
-
-@property (nonatomic, weak) IBOutlet WebView *webView;
-@property (nonatomic, weak) IBOutlet NSSegmentedControl *goSegment;
-
-- (IBAction)clickGoBackSegment:(id)sender;
-
-@end
diff --git a/KCD/HMExternalBrowserWindowController.m b/KCD/HMExternalBrowserWindowController.m
deleted file mode 100644 (file)
index e378d0b..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-//
-//  HMExternalBrowserWindowController.m
-//  KCD
-//
-//  Created by Hori,Masaki on 2014/11/22.
-//  Copyright (c) 2014年 Hori,Masaki. All rights reserved.
-//
-
-#import "HMExternalBrowserWindowController.h"
-
-@interface HMExternalBrowserWindowController ()
-
-@end
-
-@implementation HMExternalBrowserWindowController
-
-- (id)init
-{
-       self = [super initWithWindowNibName:NSStringFromClass([self class])];
-       return self;
-}
-
-- (void)awakeFromNib
-{
-       [self goHome:nil];
-       
-       [self.webView addObserver:self
-                                  forKeyPath:@"canGoBack"
-                                         options:0
-                                         context:(__bridge void *)(self.webView)];
-       [self.webView addObserver:self
-                                  forKeyPath:@"canGoForward"
-                                         options:0
-                                         context:(__bridge void *)(self.webView)];
-}
-
-- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
-{
-       id contextObject = (__bridge id)(context);
-       if(self.webView == contextObject) {
-               if([keyPath isEqualToString:@"canGoBack"]) {
-                       [self.goSegment setEnabled:self.webView.canGoBack forSegment:0];
-               }
-               if([keyPath isEqualToString:@"canGoForward"]) {
-                       [self.goSegment setEnabled:self.webView.canGoForward forSegment:1];
-               }
-               
-               
-               return;
-       }
-       
-       [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
-}
-
-/*
- http://www.dmm.com/netgame/-/basket/
- */
-
-- (IBAction)reloadContent:(id)sender
-{
-       [self.webView reload:self];
-}
-
-- (IBAction)goHome:(id)sender
-{
-       self.webView.mainFrameURL = @"http://www.dmm.com/netgame/-/basket/";
-}
-- (IBAction)clickGoBackSegment:(id)sender
-{
-       NSSegmentedCell *cell = self.goSegment.cell;
-       NSInteger tag = [cell tagForSegment:[cell selectedSegment]];
-       switch (tag) {
-               case 0:
-                       [self.webView goBack:self];
-                       break;
-               case 1:
-                       [self.webView goForward:self];
-                       break;
-               default:
-                       break;
-       }
-}
-@end
diff --git a/KCD/HMExternalBrowserWindowController.swift b/KCD/HMExternalBrowserWindowController.swift
new file mode 100644 (file)
index 0000000..6556741
--- /dev/null
@@ -0,0 +1,70 @@
+//
+//  HMExternalBrowserWindowController.swift
+//  KCD
+//
+//  Created by Hori,Masaki on 2014/12/21.
+//  Copyright (c) 2014年 Hori,Masaki. All rights reserved.
+//
+
+import Cocoa
+import WebKit
+
+class HMExternalBrowserWindowController: NSWindowController
+{
+       override init() {
+               super.init()
+       }
+       override init(window: NSWindow?) {
+               super.init(window: window)
+       }
+       required init?(coder: NSCoder) {
+               super.init(coder: coder)
+       }
+       class func create() -> HMExternalBrowserWindowController {
+               return HMExternalBrowserWindowController.init(windowNibName:"HMExternalBrowserWindowController")
+       }
+       
+    override func windowDidLoad() {
+        super.windowDidLoad()
+               
+               goHome(nil)
+               webView!.addObserver(self, forKeyPath: "canGoBack", options: .Initial, context: nil)
+               webView!.addObserver(self, forKeyPath: "canGoForward", options: .Initial, context: nil)
+               
+    }
+       
+       override func observeValueForKeyPath(keyPath: String, ofObject object: AnyObject, change: [NSObject : AnyObject], context: UnsafeMutablePointer<Void>) {
+               switch keyPath {
+               case "canGoBack":
+                       goSegment!.setEnabled(webView!.canGoBack, forSegment: 0)
+               case "canGoForward":
+                       goSegment!.setEnabled(webView!.canGoForward, forSegment: 1)
+               default:
+                       super.observeValueForKeyPath(keyPath, ofObject: object, change: change, context: context)
+               }
+       }
+       
+       @IBOutlet var webView: WebView?
+       @IBOutlet var goSegment: NSSegmentedControl?
+       
+       @IBAction func reloadContent(sender: AnyObject?) {
+               webView!.reload(sender)
+       }
+       
+       @IBAction func goHome(sender: AnyObject?) {
+               webView!.mainFrameURL = "http://www.dmm.com/netgame/-/basket/"
+       }
+       
+       @IBAction func clickGoBackSegment(sender: AnyObject?) {
+               let cell = goSegment!.cell() as NSSegmentedCell
+               let tag = cell.tagForSegment(cell.selectedSegment)
+               switch tag {
+               case 0:
+                       webView!.goBack(sender)
+               case 1:
+                       webView!.goForward(sender)
+               default:
+                       break
+               }
+       }
+}
index 6cc271d..0a7e2cc 100644 (file)
@@ -6,7 +6,7 @@
         <plugIn identifier="com.apple.WebKitIBPlugin" version="6250"/>
     </dependencies>
     <objects>
-        <customObject id="-2" userLabel="File's Owner" customClass="HMExternalBrowserWindowController">
+        <customObject id="-2" userLabel="File's Owner" customClass="HMExternalBrowserWindowController" customModule="KCD" customModuleProvider="target">
             <connections>
                 <outlet property="goSegment" destination="TLp-GC-eT2" id="OZi-HB-8MM"/>
                 <outlet property="webView" destination="Vpq-H1-y1B" id="wm8-wa-ayH"/>
@@ -27,7 +27,9 @@
                     <webView id="Vpq-H1-y1B">
                         <rect key="frame" x="0.0" y="0.0" width="850" height="631"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES"/>
-                        <webPreferences key="preferences" defaultFontSize="12" defaultFixedFontSize="12"/>
+                        <webPreferences key="preferences" defaultFontSize="12" defaultFixedFontSize="12">
+                            <nil key="identifier"/>
+                        </webPreferences>
                         <connections>
                             <outlet property="UIDelegate" destination="-2" id="Qgz-H2-GJA"/>
                         </connections>