OSDN Git Service

Doutaku を 1.0 にアップデート
[kcd/KCD.git] / KCD / JSONViewWindowController.swift
1 //
2 //  JSONViewWindowController.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2017/01/05.
6 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
7 //
8
9 import Cocoa
10
11 final class JSONViewWindowController: NSWindowController {
12     
13     deinit {
14         
15         unbind(NSBindingName(#keyPath(arguments)))
16         unbind(NSBindingName(#keyPath(json)))
17     }
18     
19     @IBOutlet private var argumentsView: NSTableView!
20     @IBOutlet private var jsonView: NSOutlineView!
21     @IBOutlet private var apis: NSArrayController!
22     
23     override var windowNibName: NSNib.Name {
24         
25         return .nibName(instanceOf: self)
26     }
27     
28     @objc var arguments: NSArray?
29     @objc var json: AnyObject?
30     @objc var commands: [[String: Any]] = []
31     
32     override func windowDidLoad() {
33         
34         super.windowDidLoad()
35         
36         bind(NSBindingName(#keyPath(arguments)), to: apis, withKeyPath: "selection.argument")
37         bind(NSBindingName(#keyPath(json)), to: apis, withKeyPath: "selection.json")
38     }
39     
40     func setCommand(_ command: [String: Any]) {
41         
42         notifyChangeValue(forKey: #keyPath(commands)) {
43             
44             commands += [command]
45         }
46     }
47     
48     @IBAction func clearLog(_ sender: AnyObject?) {
49         
50         notifyChangeValue(forKey: #keyPath(commands)) {
51             
52             commands = []
53         }
54     }
55 }