OSDN Git Service

swiftlint 'line_length'の警告を修正
[kcd/KCD.git] / KCD / ScreenshotDetailViewController.swift
1 //
2 //  ScreenshotDetailViewController.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2016/12/29.
6 //  Copyright © 2016年 Hori,Masaki. All rights reserved.
7 //
8
9 import Cocoa
10
11 class ScreenshotDetailViewController: BridgeViewController {
12     deinit {
13         arrayController.removeObserver(self, forKeyPath: NSSelectionIndexesBinding)
14     }
15     
16     
17     @IBOutlet var imageView: ImageView!
18     
19     override var nibName: String! {
20         return "ScreenshotDetailViewController"
21     }
22     override var contentRect: NSRect {
23         return imageView.convert(imageView.imageRect, to: nil)
24     }
25     
26     private var currentSelection: [ScreenshotInformation] = []
27     
28     override func viewDidLoad() {
29         super.viewDidLoad()
30         
31         arrayController.addObserver(self, forKeyPath: NSSelectionIndexesBinding, context: nil)
32         updateSelections()
33     }
34     
35     override func observeValue(forKeyPath keyPath: String?,
36                                of object: Any?,
37                                change: [NSKeyValueChangeKey: Any]?,
38                                context: UnsafeMutableRawPointer?) {
39         if keyPath == NSSelectionIndexesBinding {
40             updateSelections()
41             return
42         }
43         
44         super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
45     }
46     
47     private func updateSelections() {
48         guard let selection = arrayController.selectedObjects as? [ScreenshotInformation]
49             else { return }
50         if currentSelection == selection { return }
51         imageView.images = selection.flatMap { NSImage(contentsOf: $0.url) }
52         currentSelection = selection
53     }
54 }