OSDN Git Service

staticプロパティをインスタンスプロパティに変更
[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     @IBOutlet private var imageView: ImageView!
14     
15     override var nibName: NSNib.Name {
16         
17         return .nibName(instanceOf: self)
18     }
19     
20     override var contentRect: NSRect {
21         
22         return imageView.convert(imageView.imageRect, to: nil)
23     }
24     
25     private var currentSelection: [ScreenshotInformation] = []
26     
27     private var selectionObservation: NSKeyValueObservation?
28     
29     override func viewDidLoad() {
30         
31         super.viewDidLoad()
32         
33         selectionObservation = arrayController.observe(\NSArrayController.selectionIndexes) { [weak self] (_, _) in
34             
35             self?.updateSelections()
36         }
37         
38         updateSelections()
39     }
40     
41     private func updateSelections() {
42         
43         guard let selection = arrayController.selectedObjects as? [ScreenshotInformation] else {
44             
45             return
46         }
47         
48         if currentSelection == selection {
49             
50             return
51         }
52         
53         imageView.images = selection.compactMap { NSImage(contentsOf: $0.url) }
54         currentSelection = selection
55     }
56 }