OSDN Git Service

HMScreenshotListWindowControllerクラスをSwiftで書き換え
authormasakih <masakih@users.sourceforge.jp>
Sat, 27 Dec 2014 15:53:14 +0000 (00:53 +0900)
committermasakih <masakih@users.sourceforge.jp>
Sat, 27 Dec 2014 15:53:14 +0000 (00:53 +0900)
KCD.xcodeproj/project.pbxproj
KCD/HMAppDelegate.m
KCD/HMScreenshotListWindowController.h [deleted file]
KCD/HMScreenshotListWindowController.m [deleted file]
KCD/HMScreenshotListWindowController.swift [new file with mode: 0644]
KCD/KCD-Bridging-Header.h
KCD/ja.lproj/HMScreenshotListWindowController.xib

index d8adcc2..1ab61db 100644 (file)
@@ -61,7 +61,6 @@
                F494DC6A18C8BAB900AE97E4 /* HMPowerUpSupportViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F494DC6818C8BAB900AE97E4 /* HMPowerUpSupportViewController.xib */; };
                F494DC6D18CC054800AE97E4 /* HMNyukyoDockStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = F494DC6C18CC054800AE97E4 /* HMNyukyoDockStatus.m */; };
                F49828FC1902A226000D6BBE /* HMStrokeTextFieldCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F49828FB1902A226000D6BBE /* HMStrokeTextFieldCell.m */; };
-               F4A2AF521A074DCF0024BD9E /* HMScreenshotListWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = F4A2AF501A074DCF0024BD9E /* HMScreenshotListWindowController.m */; };
                F4A2AF541A074DE40024BD9E /* HMScreenshotListWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4A2AF561A074DE40024BD9E /* HMScreenshotListWindowController.xib */; };
                F4A2AF581A0930160024BD9E /* Quartz.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F4A2AF571A0930160024BD9E /* Quartz.framework */; };
                F4A3AD82199F529700FDBF80 /* HMCombinedBattleCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4A3AD81199F529700FDBF80 /* HMCombinedBattleCommand.m */; };
                F4D2CBC518AE2AE2000EBC59 /* HMCompositCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4D2CBC418AE2AE2000EBC59 /* HMCompositCommand.m */; };
                F4D2CBC818B0555A000EBC59 /* HMKCManagedObject.m in Sources */ = {isa = PBXBuildFile; fileRef = F4D2CBC718B0555A000EBC59 /* HMKCManagedObject.m */; };
                F4D2CBCB18B05E58000EBC59 /* HMMaserShipCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4D2CBCA18B05E58000EBC59 /* HMMaserShipCommand.m */; };
+               F4E1BC081A4D9D610089A82D /* HMScreenshotListWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4A046EC1A4C5C1300E54C2D /* HMScreenshotListWindowController.swift */; };
                F4E33B5818BF5F67005B8C07 /* HMMemberSlotItemCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E33B5718BF5F67005B8C07 /* HMMemberSlotItemCommand.m */; };
                F4E7802818DBD2A00011BC4C /* HMGetShipCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E7802718DBD2A00011BC4C /* HMGetShipCommand.m */; };
                F4E7802B18DC3A820011BC4C /* HMLocalDataStore.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E7802A18DC3A820011BC4C /* HMLocalDataStore.m */; };
                F494DC6C18CC054800AE97E4 /* HMNyukyoDockStatus.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMNyukyoDockStatus.m; sourceTree = "<group>"; };
                F49828FA1902A226000D6BBE /* HMStrokeTextFieldCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMStrokeTextFieldCell.h; sourceTree = "<group>"; };
                F49828FB1902A226000D6BBE /* HMStrokeTextFieldCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMStrokeTextFieldCell.m; sourceTree = "<group>"; };
-               F4A2AF4F1A074DCF0024BD9E /* HMScreenshotListWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMScreenshotListWindowController.h; sourceTree = "<group>"; };
-               F4A2AF501A074DCF0024BD9E /* HMScreenshotListWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMScreenshotListWindowController.m; sourceTree = "<group>"; };
+               F4A046EC1A4C5C1300E54C2D /* HMScreenshotListWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMScreenshotListWindowController.swift; sourceTree = "<group>"; };
                F4A2AF551A074DE40024BD9E /* ja */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = ja; path = ja.lproj/HMScreenshotListWindowController.xib; sourceTree = "<group>"; };
                F4A2AF571A0930160024BD9E /* Quartz.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quartz.framework; path = System/Library/Frameworks/Quartz.framework; sourceTree = SDKROOT; };
                F4A3AD80199F529700FDBF80 /* HMCombinedBattleCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMCombinedBattleCommand.h; sourceTree = "<group>"; };
                                F4B37F0119FC8DCC002F371A /* HMUpgradableShipsWindowController.xib */,
                                F4551BE51A48711D00BB0235 /* HMScreenshotInformation.swift */,
                                F4551BE91A48FA6000BB0235 /* HMCacheVersionInfo.swift */,
-                               F4A2AF4F1A074DCF0024BD9E /* HMScreenshotListWindowController.h */,
-                               F4A2AF501A074DCF0024BD9E /* HMScreenshotListWindowController.m */,
+                               F4A046EC1A4C5C1300E54C2D /* HMScreenshotListWindowController.swift */,
                                F4A2AF561A074DE40024BD9E /* HMScreenshotListWindowController.xib */,
                                F4551BE11A47044A00BB0235 /* HMExternalBrowserWindowController.swift */,
                                F4B2A08E1A1F9C2100D2EF12 /* HMExternalBrowserWindowController.xib */,
                        isa = PBXSourcesBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
+                               F4E1BC081A4D9D610089A82D /* HMScreenshotListWindowController.swift in Sources */,
                                F4513EE818B77A5300073552 /* HMMemberKDockCommand.m in Sources */,
                                F4551BEA1A48FA6000BB0235 /* HMCacheVersionInfo.swift in Sources */,
                                F426802B194D0F4800B2C27F /* HMMemberShip2Command.m in Sources */,
                                F4FDF2411A3D50420033E0AD /* HMShipMasterDetailWindowController.m in Sources */,
                                F44AB20619E053CB00F217AF /* HMKCDeck+Extension.m in Sources */,
                                F4B414F218B1013C00468DAF /* HMMasterSlotItemCommand.m in Sources */,
-                               F4A2AF521A074DCF0024BD9E /* HMScreenshotListWindowController.m in Sources */,
                                F4131EE61910318F004F7F9A /* HMMasterSlotItemEquipTypeCommand.m in Sources */,
                                F4551BF01A49350B00BB0235 /* HMPowerUpSupportViewController.swift in Sources */,
                                F4D2CBC818B0555A000EBC59 /* HMKCManagedObject.m in Sources */,
index 33af38f..c199504 100644 (file)
@@ -9,7 +9,6 @@
 #import "HMAppDelegate.h"
 
 #import "HMUserDefaults.h"
-#import "HMScreenshotListWindowController.h"
 #import "HMShipMasterDetailWindowController.h"
 
 #import "HMFleetInformation.h"
 - (HMScreenshotListWindowController *)screenshotListWindowController
 {
        if(_screenshotListWindowController) return _screenshotListWindowController;
-       _screenshotListWindowController = [HMScreenshotListWindowController new];
+       _screenshotListWindowController = [HMScreenshotListWindowController create];
        return _screenshotListWindowController;
 }
 
diff --git a/KCD/HMScreenshotListWindowController.h b/KCD/HMScreenshotListWindowController.h
deleted file mode 100644 (file)
index 3955a09..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-//
-//  HMScreenshotListWindowController.h
-//  KCD
-//
-//  Created by Hori,Masaki on 2014/11/03.
-//  Copyright (c) 2014年 Hori,Masaki. All rights reserved.
-//
-
-#import <Cocoa/Cocoa.h>
-
-
-@class HMMaskSelectView;
-
-@interface HMScreenshotListWindowController : NSWindowController
-
-
-- (IBAction)reloadData:(id)sender;
-
-- (void)reloadData;
-- (void)registerScreenshot:(NSBitmapImageRep *)image fromOnScreen:(NSRect)screenRect;
-
-
-// Tweet
-@property BOOL appendKanColleTag;
-@property (copy, nonatomic) NSString *tagString;
-
-@property (strong, nonatomic) IBOutlet HMMaskSelectView *maskSelectView;
-@property BOOL useMask;
-
-- (IBAction)share:(id)sender;
-
-- (IBAction)delete:(id)sender;
-- (IBAction)revealInFinder:(id)sender;
-
-@end
diff --git a/KCD/HMScreenshotListWindowController.m b/KCD/HMScreenshotListWindowController.m
deleted file mode 100644 (file)
index 2733366..0000000
+++ /dev/null
@@ -1,313 +0,0 @@
-//
-//  HMScreenshotListWindowController.m
-//  KCD
-//
-//  Created by Hori,Masaki on 2014/11/03.
-//  Copyright (c) 2014年 Hori,Masaki. All rights reserved.
-//
-
-#import "HMScreenshotListWindowController.h"
-#import "HMMaskSelectView.h"
-
-#import <Quartz/Quartz.h>
-
-#import "HMAppDelegate.h"
-#import "HMUserDefaults.h"
-
-#import <Accounts/Accounts.h>
-#import <Social/Social.h>
-
-#import "KCD-Swift.h"
-
-
-@interface NSFileManager (KCDExtension)
-- (NSString *)_web_pathWithUniqueFilenameForPath:(NSString *)path;
-@end
-
-@interface HMScreenshotListWindowController ()
-@property (weak, nonatomic) IBOutlet NSArrayController *screenshotsController;
-@property (strong) NSArray *screenshots;
-@property (weak) NSIndexSet *selectedIndexes;
-@property (strong) NSMutableArray *deletedPaths;
-
-@property (weak, nonatomic) IBOutlet IKImageBrowserView *browser;
-@property (weak, nonatomic) IBOutlet NSMenu *contextMenu;
-@property (weak, nonatomic) IBOutlet NSButton *shareButton;
-
-@end
-
-@interface HMScreenshotListWindowController (HMSharingService) <NSSharingServiceDelegate, NSSharingServicePickerDelegate>
-
-@end
-
-@implementation HMScreenshotListWindowController
-
-- (id)init
-{
-       self = [super initWithWindowNibName:NSStringFromClass([self class])];
-       if(self) {
-               _screenshots = [NSArray new];
-               _deletedPaths = [NSMutableArray new];
-               
-               NSString *tag = NSLocalizedString(@"kancolle", @"kancolle twitter hash tag");
-               if(tag) {
-                       _tagString = [NSString stringWithFormat:@" #%@", tag];
-               } else {
-                       _tagString = @"";
-               }
-               _appendKanColleTag = HMStandardDefaults.appendKanColleTag;
-               _useMask = HMStandardDefaults.useMask;
-       }
-       return self;
-}
-
-- (void)awakeFromNib
-{
-       [self.browser setCanControlQuickLookPanel:YES];
-       [self.shareButton sendActionOn:NSLeftMouseDownMask];
-       
-       NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO];
-       self.screenshotsController.sortDescriptors = @[sortDescriptor];
-       [self performSelector:@selector(reloadData:)
-                          withObject:nil
-                          afterDelay:0.0];
-}
-
-- (NSString *)screenshotSaveDirectoryPath
-{
-       HMAppDelegate *appDelegate = [[NSApplication sharedApplication] delegate];
-       NSString *parentDirctory = appDelegate.screenShotSaveDirectory;
-       NSBundle *mainBundle = [NSBundle mainBundle];
-       NSDictionary *localizedInfoDictionary = [mainBundle localizedInfoDictionary];
-       NSString *saveDirectoryName = localizedInfoDictionary[@"CFBundleName"];
-       NSString *path = [parentDirctory stringByAppendingPathComponent:saveDirectoryName];
-       
-       NSFileManager *fm = [NSFileManager defaultManager];
-       BOOL isDir = NO;
-       NSError *error = nil;
-       if(![fm fileExistsAtPath:path isDirectory:&isDir]) {
-               BOOL ok = [fm createDirectoryAtPath:path
-                               withIntermediateDirectories:NO
-                                                                attributes:nil
-                                                                         error:&error];
-               if(!ok) {
-                       NSLog(@"Can not create screenshot save directory.");
-                       return parentDirctory;
-               }
-       } else if(!isDir) {
-               NSLog(@"%@ is regular file, not direcory.", path);
-               return parentDirctory;
-       }
-       
-       return path;
-}
-
-- (void)reloadData
-{
-       NSMutableArray *screenshotNames = [NSMutableArray new];
-       NSMutableArray *currentArray = [self.screenshots mutableCopy];
-       NSFileManager *fm = [NSFileManager defaultManager];
-       
-       NSError *error = nil;
-       NSArray *files = [fm contentsOfDirectoryAtPath:self.screenshotSaveDirectoryPath error:&error];
-       if(error) {
-               NSLog(@"%s: error -> %@", __PRETTY_FUNCTION__, error);
-       }
-       
-       NSArray *imageTypes = [NSImage imageTypes];
-       NSWorkspace *ws = [NSWorkspace sharedWorkspace];
-       for(NSString *file in files) {
-               NSString *fullpath = [self.screenshotSaveDirectoryPath stringByAppendingPathComponent:file];
-               NSString *fileType = [ws typeOfFile:fullpath error:NULL];
-               if([imageTypes containsObject:fileType]) {
-                       [screenshotNames addObject:fullpath];
-               }
-       }
-       
-       // 無くなっているものを調べる
-       NSMutableArray *deleteObjects = [NSMutableArray new];
-       for(HMScreenshotInformation *info in self.screenshots) {
-               if(![screenshotNames containsObject:info.path]) {
-                       [self incrementCacheVersionForPath:info.path];
-                       [deleteObjects addObject:info];
-               }
-       }
-       [currentArray removeObjectsInArray:deleteObjects];
-       
-       // 新しいものを調べる
-       for(NSString *path in screenshotNames) {
-               NSUInteger index = [self.screenshots indexOfObjectPassingTest:^(HMScreenshotInformation *obj, NSUInteger idx, BOOL *stop) {
-                       if([path isEqualToString:obj.path]) {
-                               *stop = YES;
-                               return YES;
-                       }
-                       return NO;
-               }];
-               if(index == NSNotFound) {
-                       HMScreenshotInformation *info = [[HMScreenshotInformation alloc] initWithPath:path];
-                       [currentArray addObject:info];
-               }
-       }
-       self.screenshots = [currentArray copy];
-       
-       if(!self.selectedIndexes) {
-               self.selectedIndexes = [NSIndexSet indexSetWithIndex:0];
-       }
-}
-
-- (IBAction)reloadData:(id)sender
-{
-       [self reloadData];
-}
-- (IBAction)delete:(id)sender
-{
-       NSString *imagePath = [self.screenshotsController valueForKeyPath:@"selection.path"];   
-       NSString *scriptTmplate =
-       @"tell application \"Finder\"\n"
-       @"      move ( \"%@\" as POSIX file) to trash\n"
-       @"end tell";
-       NSString *script = [NSString stringWithFormat:scriptTmplate, imagePath];
-       NSAppleScript *appleScript = [[NSAppleScript alloc] initWithSource:script];
-       if(!appleScript) NSBeep();
-       [appleScript executeAndReturnError:nil];
-       
-       NSUInteger selectionIndex = self.screenshotsController.selectionIndex;
-       [self.screenshotsController removeObjectAtArrangedObjectIndex:selectionIndex];
-       
-       [self incrementCacheVersionForPath:imagePath];
-}
-- (IBAction)revealInFinder:(id)sender
-{
-       NSString *imagePath = [self.screenshotsController valueForKeyPath:@"selection.path"];
-       NSWorkspace *ws = [NSWorkspace sharedWorkspace];
-       [ws selectFile:imagePath inFileViewerRootedAtPath:@""];
-}
-
-- (void)registerScreenshot:(NSBitmapImageRep *)image fromOnScreen:(NSRect)screenRect
-{
-       NSData *imageData = [image representationUsingType:NSJPEGFileType properties:nil];
-       
-       NSBundle *mainBundle = [NSBundle mainBundle];
-       NSDictionary *infoList = [mainBundle localizedInfoDictionary];
-       NSString *filename = [infoList objectForKey:@"CFBundleName"];
-       if([filename length] == 0) {
-               filename = @"KCD";
-       }
-       filename = [filename stringByAppendingPathExtension:@"jpg"];
-       NSString *path = [[self screenshotSaveDirectoryPath] stringByAppendingPathComponent:filename];
-       path = [[NSFileManager defaultManager] _web_pathWithUniqueFilenameForPath:path];
-       
-       [imageData writeToFile:path atomically:YES];
-       HMScreenshotInformation *info = [[HMScreenshotInformation alloc] initWithPath:path];
-       info.version = [self cacheVersionForPath:path];
-       
-       [self.screenshotsController insertObject:info atArrangedObjectIndex:0];
-       self.screenshotsController.selectedObjects = @[info];
-       
-       if(HMStandardDefaults.showsListWindowAtScreenshot) {
-               [self.window makeKeyAndOrderFront:nil];
-       }
-}
-
-- (void)incrementCacheVersionForPath:(NSString *)fullpath
-{
-       NSPredicate *predicate = [NSPredicate predicateWithFormat:@"fullpath = %@", fullpath];
-       NSArray *filteredArray = [self.deletedPaths filteredArrayUsingPredicate:predicate];
-       if(filteredArray.count == 0) {
-               HMCacheVersionInfo *info = [[HMCacheVersionInfo alloc] initWithPath:fullpath];
-               info.version = 1;
-               [self.deletedPaths addObject:info];
-       } else {
-               HMCacheVersionInfo *info = filteredArray[0];
-               info.version += 1;
-       }
-}
-- (NSUInteger)cacheVersionForPath:(NSString *)fullpath
-{
-       NSPredicate *predicate = [NSPredicate predicateWithFormat:@"fullpath = %@", fullpath];
-       NSArray *filteredArray = [self.deletedPaths filteredArrayUsingPredicate:predicate];
-       if(filteredArray.count == 0) {
-               return 0;
-       }
-       
-       HMCacheVersionInfo *cacheInfo = filteredArray[0];
-       return cacheInfo.version;
-}
-
-#pragma mark - Tweet
-@synthesize useMask = _useMask;
-@synthesize appendKanColleTag = _appendKanColleTag;
-
-
-- (BOOL)useMask
-{
-       return _useMask;
-}
-- (void)setUseMask:(BOOL)useMask
-{
-       HMStandardDefaults.useMask = useMask;
-       _useMask = useMask;
-}
-
-- (BOOL)appendKanColleTag
-{
-       return _appendKanColleTag;
-}
-- (void)setAppendKanColleTag:(BOOL)appendKanColleTag
-{
-       HMStandardDefaults.appendKanColleTag = appendKanColleTag;
-       _appendKanColleTag = appendKanColleTag;
-}
-
-- (IBAction)share:(id)sender
-{
-       NSString *imagePath = [self.screenshotsController valueForKeyPath:@"selection.path"];
-       NSImage *image = [[NSImage alloc] initWithContentsOfFile:imagePath];
-       
-       NSString *tags = nil;
-       if(self.appendKanColleTag) {
-               tags = self.tagString;
-               tags = [@" \n" stringByAppendingString:tags];
-       }
-       NSArray *items = [NSArray arrayWithObjects:image, tags, nil];
-       NSSharingServicePicker *picker = [[NSSharingServicePicker alloc] initWithItems:items];
-       picker.delegate = self;
-       [picker showRelativeToRect:[sender bounds]
-                                               ofView:sender
-                                preferredEdge:NSMinXEdge];
-}
-
-
-#pragma mark - IKImageBrowserDelegate
-- (void) imageBrowser:(IKImageBrowserView *) aBrowser cellWasRightClickedAtIndex:(NSUInteger) index withEvent:(NSEvent *) event
-{
-       [NSMenu popUpContextMenu:self.contextMenu withEvent:event forView:aBrowser];
-}
-
-
-#pragma mark - NSSharingServiceDelegate NSSharingServicePickerDelegate
-- (id <NSSharingServiceDelegate>)sharingServicePicker:(NSSharingServicePicker *)sharingServicePicker delegateForSharingService:(NSSharingService *)sharingService
-{
-       return self;
-}
-
-- (NSRect)sharingService:(NSSharingService *)sharingService sourceFrameOnScreenForShareItem:(id<NSPasteboardWriting>)item
-{
-       if([item isKindOfClass:[NSString class]]) return NSZeroRect;
-       
-       NSRect frame = self.maskSelectView.frame;
-       return [self.window convertRectToScreen:frame];
-}
-- (NSImage *)sharingService:(NSSharingService *)sharingService transitionImageForShareItem:(id<NSPasteboardWriting>)item contentRect:(NSRect *)contentRect
-{
-       if([item isKindOfClass:[NSImage class]]) return (NSImage *)item;
-       
-       return nil;
-}
-- (NSWindow *)sharingService:(NSSharingService *)sharingService sourceWindowForShareItems:(NSArray *)items sharingContentScope:(NSSharingContentScope *)sharingContentScope
-{
-       return self.window;
-}
-
-
-@end
diff --git a/KCD/HMScreenshotListWindowController.swift b/KCD/HMScreenshotListWindowController.swift
new file mode 100644 (file)
index 0000000..8cf1194
--- /dev/null
@@ -0,0 +1,265 @@
+//
+//  HMScreenshotListWindowController.swift
+//  KCD
+//
+//  Created by Hori,Masaki on 2014/12/25.
+//  Copyright (c) 2014年 Hori,Masaki. All rights reserved.
+//
+
+import Cocoa
+import Quartz
+
+class HMScreenshotListWindowController: NSWindowController, NSSharingServiceDelegate, NSSharingServicePickerDelegate
+{
+       override init() {
+               super.init()
+       }
+       override init(window: NSWindow?) {
+               super.init(window: window)
+       }
+       required init?(coder: NSCoder) {
+               super.init(coder: coder)
+       }
+       
+       class func create() -> HMScreenshotListWindowController {
+               let result =  HMScreenshotListWindowController(windowNibName: "HMScreenshotListWindowController")
+               result.loadWindow()
+               return result
+       }
+
+       var screenshots:[HMScreenshotInformation] = [] {
+               willSet {
+                       willChangeValueForKey("screenshots")
+               }
+               didSet {
+                       didChangeValueForKey("screenshots")
+               }
+       }
+       var deletedPaths:[HMCacheVersionInfo] = []
+       var selectedIndexes: NSIndexSet? {
+               willSet {
+                       willChangeValueForKey("selectedIndexes")
+               }
+               didSet {
+                       didChangeValueForKey("selectedIndexes")
+               }
+       }
+       
+       var screenshotSaveDirectoryPath: String {
+               let appDelegate = NSApplication.sharedApplication().delegate as HMAppDelegate
+               let parentDirectory = appDelegate.screenShotSaveDirectory
+               let localizedInfoDictionary = NSBundle.mainBundle().localizedInfoDictionary
+               let saceDirectoryName = localizedInfoDictionary!["CFBundleName"] as? String
+               let path = parentDirectory.stringByAppendingPathComponent(saceDirectoryName!)
+               let fm = NSFileManager.defaultManager()
+               var isDir: ObjCBool = false
+               var error: NSError? = nil
+               if !fm.fileExistsAtPath(path, isDirectory: &isDir) {
+                       if !fm.createDirectoryAtPath(path, withIntermediateDirectories: false, attributes: nil, error: &error) {
+                               println("Can not create screenshot save directory.")
+                               return parentDirectory
+                       }
+               } else if !isDir {
+                       println("\(path) is regular file, not directory")
+                       return parentDirectory
+               }
+               
+               return path
+       }
+       
+       override func awakeFromNib() {
+               browser.setCanControlQuickLookPanel(true)
+               shareButton.sendActionOn(Int(NSEventMask.LeftMouseDownMask.rawValue))
+               
+               screenshotsController.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
+               dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(1 * Double(NSEC_PER_MSEC))), dispatch_get_main_queue()) {
+                       [unowned self] in
+                       self.reloadData(nil)
+               }
+       }
+       
+       func reloadData() {
+               var error: NSError? = nil
+               let files = NSFileManager.defaultManager().contentsOfDirectoryAtPath(screenshotSaveDirectoryPath, error: &error) as? [String]
+               if error != nil {
+                       println(__FUNCTION__, ": error -> \(error!)")
+                       return
+               }
+               let paths = files!.map() { self.screenshotSaveDirectoryPath.stringByAppendingPathComponent($0) }
+               let imageTypes = NSImage.imageTypes() as [String]
+               let ws = NSWorkspace.sharedWorkspace()
+               let screenshotNames = paths.filter() {
+                       if let type = ws.typeOfFile($0, error: &error) {
+                               if contains(imageTypes, type) {
+                                       return true
+                               }
+                       }
+                       return false
+               }
+               // 無くなっているものを削除
+               var currentArray = screenshots.filter() {
+                       if !contains(screenshotNames, $0.path) {
+                               self.incrementCacheVersionForPath($0.path)
+                               return false
+                       }
+                       return true
+               }
+               // 新しいものを追加
+               var newNames = screenshotNames.filter() {
+                       f in
+                       let b = self.screenshots.filter() { $0.path == f }
+                       return b.count == 0
+               }
+               currentArray += newNames.map() { HMScreenshotInformation(path: $0) }
+               
+               screenshots = currentArray
+               
+               if selectedIndexes == nil {
+                       selectedIndexes = NSIndexSet(index: 0)
+               }
+       }
+       func registerScreenshot(image: NSBitmapImageRep, fromOnScreen: NSRect) {
+               let imageData = image.representationUsingType(NSBitmapImageFileType.NSJPEGFileType, properties: [:])
+               if imageData == nil {
+                       println("Can not create image data.")
+                       NSBeep()
+                       return
+               }
+               let infoList = NSBundle.mainBundle().localizedInfoDictionary
+               var filename = infoList!["CFBundleName"] as? String
+               if filename == nil || filename!.isEmpty {
+                       filename = "KCD"
+               }
+               filename = filename!.stringByAppendingPathExtension("jpg")
+               var path = screenshotSaveDirectoryPath.stringByAppendingPathComponent(filename!)
+               path = NSFileManager.defaultManager()._web_pathWithUniqueFilenameForPath(path)
+               
+               imageData!.writeToFile(path, atomically: true)
+               let info = HMScreenshotInformation(path: path)
+               info.version = cacheVersionForPath(path)
+               screenshotsController.insertObject(info, atArrangedObjectIndex: 0)
+               screenshotsController.setSelectedObjects([info])
+               
+               if HMUserDefaults.hmStandardDefauls().showsListWindowAtScreenshot {
+                       window!.makeKeyAndOrderFront(nil)
+               }
+               
+       }
+       func incrementCacheVersionForPath(fullpath: String) {
+               let match = deletedPaths.filter() { fullpath == $0.fullpath }
+               if match.count == 0 {
+                       let info = HMCacheVersionInfo(path: fullpath)
+                       info.version = 1
+                       deletedPaths += [info]
+               } else {
+                       match[0].version += 1
+               }
+       }
+       func cacheVersionForPath(fullpath: String) -> Int {
+               let match = deletedPaths.filter() { fullpath == $0.fullpath }
+               return match.count == 0 ? 0 : match[0].version
+       }
+       
+       @IBOutlet var browser: IKImageBrowserView!
+       @IBOutlet var contextMenu: NSMenu!
+       @IBOutlet var screenshotsController: NSArrayController!
+       
+       @IBAction func reloadData(sender: AnyObject?) {
+               reloadData()
+       }
+       @IBAction func delete(sender: AnyObject?) {
+               let imagePath = screenshotsController.valueForKeyPath("selection.path") as? String
+               if imagePath == nil { return }
+               let script = [
+                       "tell application \"Finder\"\n",
+                       "move ( \"",
+                       imagePath,
+                       "\" as POSIX file) to trash\n",
+                       "end tell",
+                       ].reduce("") { $0 + $1! }
+               if let appleScript = NSAppleScript(source: script) as NSAppleScript? {
+                       appleScript.executeAndReturnError(nil)
+                       let selectionIndex = screenshotsController.selectionIndex
+                       screenshotsController.removeObjectAtArrangedObjectIndex(selectionIndex)
+                       incrementCacheVersionForPath(imagePath!)
+               } else {
+                       println("can not create AppleScript")
+               }
+       }
+       @IBAction func revealInFinder(sender: AnyObject?) {
+               let imagePath = screenshotsController.valueForKeyPath("selection.path") as? String
+               if imagePath == nil { return }
+               NSWorkspace.sharedWorkspace().selectFile(imagePath!, inFileViewerRootedAtPath: "")
+       }
+       
+       // MARK: - Tweet
+       var appendKanColleTag: Bool {
+               get {
+                       return HMUserDefaults.hmStandardDefauls().appendKanColleTag
+               }
+               set {
+                       HMUserDefaults.hmStandardDefauls().appendKanColleTag = newValue
+               }
+       }
+       var tagString: String = {
+               return " #" + NSLocalizedString("kancolle", comment: "kancolle twitter hash tag")
+       }()
+       var useMask: Bool {
+               get {
+                       return HMUserDefaults.hmStandardDefauls().useMask
+               }
+               set {
+                       HMUserDefaults.hmStandardDefauls().useMask = newValue
+               }
+       }
+       
+       
+       @IBOutlet var maskSelectView: HMMaskSelectView!
+       @IBOutlet var shareButton: NSButton!
+       
+       @IBAction func share(sender: AnyObject?) {
+               let rect = sender?.bounds
+               if rect == nil { return }
+               let imagePath = screenshotsController.valueForKeyPath("selection.path") as? String
+               if imagePath == nil {
+                       NSBeep()
+                       return
+               }
+               let image = NSImage(contentsOfFile: imagePath!)
+               if image == nil {
+                       NSBeep()
+                       return
+               }
+               var items:[AnyObject] = [image!]
+               if appendKanColleTag {
+                       items += [" \n" + tagString]
+               }
+               let picker = NSSharingServicePicker(items: items)
+               picker.delegate = self
+               picker.showRelativeToRect(rect!, ofView: sender! as NSView, preferredEdge: NSMinXEdge)
+       }
+       
+       // MARK: - IKImageBrowserDelegate
+       override func imageBrowser(aBrowser: IKImageBrowserView!, cellWasRightClickedAtIndex index: Int, withEvent event: NSEvent!) {
+               NSMenu.popUpContextMenu(contextMenu, withEvent: event, forView: aBrowser)
+       }
+       
+       // MARK: mark - NSSharingServiceDelegate NSSharingServicePickerDelegate
+       func sharingServicePicker(sharingServicePicker: NSSharingServicePicker, delegateForSharingService sharingService: NSSharingService) -> NSSharingServiceDelegate? {
+               return self
+       }
+       func sharingService(sharingService: NSSharingService, sourceFrameOnScreenForShareItem item: NSPasteboardWriting) -> NSRect {
+               if item is String { return NSZeroRect }
+               let frame = maskSelectView.frame
+               return window!.convertRectToScreen(frame)
+       }
+       func sharingService(sharingService: NSSharingService, transitionImageForShareItem item: NSPasteboardWriting, contentRect: UnsafeMutablePointer<NSRect>) -> NSImage? {
+               if item is NSImage { return item as? NSImage }
+               return nil
+       }
+       func sharingService(sharingService: NSSharingService, sourceWindowForShareItems items: [AnyObject], sharingContentScope: UnsafeMutablePointer<NSSharingContentScope>) -> NSWindow? {
+               return window!
+       }
+
+}
+
index c3e642c..7e2bff3 100644 (file)
@@ -2,8 +2,6 @@
 //  Use this file to import your target's public headers that you would like to expose to Swift.
 //
 
-//#import <NSAppKit/NSApplication.h>
-
 #import "HMAppDelegate.h"
 #import "HMUserDefaults.h"
 
@@ -17,8 +15,9 @@
 #import "HMFleetInformation.h"
 
 #import "HMSuppliesView.h"
-
-#import "HMScreenshotListWindowController.h"
-
+#import "HMMaskSelectView.h"
 
 
+@interface NSFileManager (KCDExtension)
+- (NSString *)_web_pathWithUniqueFilenameForPath:(NSString *)path;
+@end
index 0e686c3..b161f75 100644 (file)
@@ -1,12 +1,12 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6250" systemVersion="13F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6254" systemVersion="13F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
     <dependencies>
         <deployment identifier="macosx"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6250"/>
-        <plugIn identifier="com.apple.imagekit.ibplugin" version="6250"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6254"/>
+        <plugIn identifier="com.apple.imagekit.ibplugin" version="6254"/>
     </dependencies>
     <objects>
-        <customObject id="-2" userLabel="File's Owner" customClass="HMScreenshotListWindowController">
+        <customObject id="-2" userLabel="File's Owner" customClass="HMScreenshotListWindowController" customModule="KCD" customModuleProvider="target">
             <connections>
                 <outlet property="browser" destination="FPI-Ma-X6H" id="1Jw-Ae-EMa"/>
                 <outlet property="contextMenu" destination="jCv-QN-9O1" id="BjD-Nc-kNQ"/>
                             <rect key="frame" x="1" y="1" width="166" height="79"/>
                             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                             <subviews>
-                                <ikImageBrowserView autoresizesSubviews="NO" zoomValue="3.2822258472442627" allowsMultipleSelection="NO" allowsEmptySelection="NO" id="FPI-Ma-X6H">
-                                    <rect key="frame" x="0.0" y="0.0" width="10000" height="2183"/>
+                                <ikImageBrowserView autoresizesSubviews="NO" zoomValue="4.5748710632324219" allowsMultipleSelection="NO" allowsEmptySelection="NO" id="FPI-Ma-X6H">
+                                    <rect key="frame" x="0.0" y="0.0" width="10000" height="2534"/>
                                     <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES"/>
                                     <ikCellsStyle key="cellsStyleMask" none="YES" shadowed="YES" titled="YES" subtitled="YES"/>
                                     <autoresizingMask key="contentResizingMask" heightSizable="YES"/>
-                                    <size key="cellSize" width="3556" height="3556"/>
+                                    <size key="cellSize" width="6867" height="6867"/>
                                     <connections>
                                         <binding destination="mrq-7Y-mHG" name="content" keyPath="arrangedObjects" id="G0M-vZ-Pyi"/>
                                         <binding destination="-2" name="selectionIndexes" keyPath="selectedIndexes" previousBinding="G0M-vZ-Pyi" id="hZm-cJ-NmG"/>