2 // HMJSONViewWindowController.m
5 // Created by Hori,Masaki on 2014/02/09.
6 // Copyright (c) 2014年 Hori,Masaki. All rights reserved.
9 #import "HMJSONViewWindowController.h"
11 @interface HMJSONViewWindowController ()
12 @property (strong, readwrite) NSMutableArray *commands;
14 @property (weak, readwrite) id json;
17 @implementation HMJSONViewWindowController
21 self = [super initWithWindowNibName:NSStringFromClass([self class])];
23 _commands = [NSMutableArray new];
30 [self.apis addObserver:self
31 forKeyPath:@"selection"
32 options:NSKeyValueObservingOptionNew
36 - (void)setCommand:(NSDictionary *)command
38 [self willChangeValueForKey:@"commands"];
39 [self.commands addObject:command];
40 [self didChangeValueForKey:@"commands"];
42 - (void)setCommandArray:(NSArray *)commands
44 [self willChangeValueForKey:@"commands"];
45 [self.commands addObjectsFromArray:commands];
46 [self didChangeValueForKey:@"commands"];
49 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
51 if([keyPath isEqualToString:@"selection"]) {
52 [self willChangeValueForKey:@"arguments"];
53 self.arguments = [self.apis valueForKeyPath:@"selection.argument"];
54 [self didChangeValueForKey:@"arguments"];
56 [self willChangeValueForKey:@"json"];
57 self.json = [self.apis valueForKeyPath:@"selection.json"];
58 [self didChangeValueForKey:@"json"];
63 [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
66 - (IBAction)clearLog:(id)sender
68 [self willChangeValueForKey:@"commands"];
69 [self.commands removeAllObjects];
70 [self didChangeValueForKey:@"commands"];