Improve website.
[enjoyable.git] / Classes / NJOutputMapping.m
1 //
2 // NJOutputMapping.m
3 // Enjoy
4 //
5 // Created by Sam McCall on 6/05/09.
6 //
7
8 #import "NJOutputMapping.h"
9
10 #import "EnjoyableApplicationDelegate.h"
11 #import "NJMapping.h"
12 #import "NJMappingsController.h"
13
14 @implementation NJOutputMapping
15
16 + (NSString *)serializationCode {
17 return @"mapping";
18 }
19
20 - (NSDictionary *)serialize {
21 return _mapping
22 ? @{ @"type": self.class.serializationCode, @"name": _mapping.name }
23 : nil;
24 }
25
26 + (NJOutputMapping *)outputDeserialize:(NSDictionary *)serialization
27 withMappings:(NSArray *)mappings {
28 NSString *name = serialization[@"name"];
29 NJOutputMapping *output = [[NJOutputMapping alloc] init];
30 for (NJMapping *mapping in mappings) {
31 if ([mapping.name isEqualToString:name]) {
32 output.mapping = mapping;
33 return output;
34 }
35 }
36 return nil;
37 }
38
39 - (void)trigger {
40 EnjoyableApplicationDelegate *ctrl = (EnjoyableApplicationDelegate *)NSApplication.sharedApplication.delegate;
41 [ctrl.mappingsController activateMapping:_mapping];
42 }
43
44 @end