OSDN Git Service

ソースコード整形
[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 final class ScreenshotDetailViewController: BridgeViewController {
12     
13     deinit {
14         
15         arrayController.removeObserver(self, forKeyPath: NSSelectionIndexesBinding)
16     }
17     
18     @IBOutlet var imageView: ImageView!
19     
20     override var nibName: String! {
21         
22         return "ScreenshotDetailViewController"
23     }
24     
25     override var contentRect: NSRect {
26         
27         return imageView.convert(imageView.imageRect, to: nil)
28     }
29     
30     private var currentSelection: [ScreenshotInformation] = []
31     
32     override func viewDidLoad() {
33         
34         super.viewDidLoad()
35         
36         arrayController.addObserver(self, forKeyPath: NSSelectionIndexesBinding, context: nil)
37         updateSelections()
38     }
39     
40     override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {
41         
42         if keyPath == NSSelectionIndexesBinding {
43             
44             updateSelections()
45             
46             return
47         }
48         
49         super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
50     }
51     
52     private func updateSelections() {
53         
54         guard let selection = arrayController.selectedObjects as? [ScreenshotInformation]
55             else { return }
56         
57         if currentSelection == selection { return }
58         
59         imageView.images = selection.flatMap { NSImage(contentsOf: $0.url) }
60         currentSelection = selection
61     }
62 }