OSDN Git Service

UIを調整
[kcd/KCD.git] / KCD / HMJSONViewWindowController.m
1 //
2 //  HMJSONViewWindowController.m
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2014/02/09.
6 //  Copyright (c) 2014年 Hori,Masaki. All rights reserved.
7 //
8
9 #import "HMJSONViewWindowController.h"
10
11 @interface HMJSONViewWindowController ()
12 @property (strong, readwrite) NSMutableArray *commands;
13
14 @property (weak, readwrite) id json;
15 @end
16
17 @implementation HMJSONViewWindowController
18
19 - (id)init
20 {
21         self = [super initWithWindowNibName:NSStringFromClass([self class])];
22         if(self) {
23                 _commands = [NSMutableArray new];
24         }
25         return self;
26 }
27
28 - (void)awakeFromNib
29 {
30         [self.apis addObserver:self
31                                 forKeyPath:@"selection"
32                                    options:NSKeyValueObservingOptionNew
33                                    context:NULL];
34 }
35
36 - (void)setCommand:(NSDictionary *)command
37 {
38         [self willChangeValueForKey:@"commands"];
39         [self.commands addObject:command];
40         [self didChangeValueForKey:@"commands"];
41 }
42 - (void)setCommandArray:(NSArray *)commands
43 {
44         [self willChangeValueForKey:@"commands"];
45         [self.commands addObjectsFromArray:commands];
46         [self didChangeValueForKey:@"commands"];
47 }
48
49 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
50 {
51         if([keyPath isEqualToString:@"selection"]) {
52                 [self willChangeValueForKey:@"arguments"];
53                 self.arguments = [self.apis valueForKeyPath:@"selection.argument"];
54                 [self didChangeValueForKey:@"arguments"];
55                 
56                 [self willChangeValueForKey:@"json"];
57                 self.json = [self.apis valueForKeyPath:@"selection.json"];
58                 [self didChangeValueForKey:@"json"];
59                                 
60                 return;
61         }
62         
63         [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
64 }
65
66 - (IBAction)clearLog:(id)sender
67 {
68         [self willChangeValueForKey:@"commands"];
69         [self.commands removeAllObjects];
70         [self didChangeValueForKey:@"commands"];
71 }
72
73 @end