-
Notifications
You must be signed in to change notification settings - Fork 12
/
SMFDictionaryEditor.m
148 lines (136 loc) · 3.92 KB
/
SMFDictionaryEditor.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//
// SMFDictionaryEditor.m
// SMFramework
//
// Created by Thomas Cool on 5/1/11.
// Copyright 2011 Thomas Cool. All rights reserved.
//
#import "SMFDictionaryEditor.h"
#import "SMFramework.h"
#import "SMFDictionaryObjectEditor.h"
@implementation SMFDictionaryEditor
@synthesize delegate;
@synthesize key=_k;
-(void)refresh
{
[_keys release];
_keys =[[[_d allKeys] sortedArrayUsingSelector:@selector(compare:)] retain];
NSLog(@"keys: %@",_keys);
[[self list]removeDividers];
[[self list] addDividerAtIndex:0 withLabel:@"Keys"];
[[self list] addDividerAtIndex:[_keys count] withLabel:@"Options"];
[[self list]reload];
}
-(id)previewControlForItem:(long)row
{
if (row<[_keys count])
{
SMFMediaPreview *p = [SMFMediaPreview mediaPreview];
SMFBaseAsset *a = [SMFBaseAsset asset];
[a setCustomKeys:[NSArray arrayWithObjects:@"Key",@"Value",@"Class",nil]
forObjects:[NSArray arrayWithObjects:
[_keys objectAtIndex:row],
[_d objectForKey:[_keys objectAtIndex:row]],
NSStringFromClass([[_d objectForKey:[_keys objectAtIndex:row]] class]),
nil]];
[a setCoverArt:[[BRThemeInfo sharedTheme]appleTVIcon]];
[a setTitle:[self titleForRow:row]];
[p setAsset:a];
return p;
}
return [super previewControlForItem:row];
}
-(id)initWithDictionary:(NSDictionary *)d
{
self=[super init];
if (self) {
if (d==nil) {
_d=[[NSMutableDictionary dictionary] retain];
}
else {
_d=[d mutableCopy];
}
NSLog(@"d: %@",d);
}
[self refresh];
return self;
}
-(id)initWithMutableDictionary:(NSMutableDictionary *)d inplace:(BOOL)inpl
{
self=[super init];
if (self) {
if (inpl)
_d=[d retain];
else
_d=[d mutableCopy];
}
[self refresh];
return self;
}
-(long)itemCount
{
return [[_d allKeys] count]+2;
}
-(id)titleForRow:(long)row
{
if (row<[_keys count]) {
return [_keys objectAtIndex:row];
}
else {
row-=[_keys count];
if (row==0) {
return @"New Object";
}
else if(row==1)
{
return @"Save";
}
}
return @"";
}
-(id)itemForRow:(long)row
{
SMFMenuItem *it=[SMFMenuItem menuItem];
[it setTitle:[self titleForRow:row]];
return it;
}
-(void)itemSelected:(long)row
{
if (row<[_keys count]) {
SMFDictionaryObjectEditor *e = [[[SMFDictionaryObjectEditor alloc] initWithKey:[_keys objectAtIndex:row]
withObject:[_d objectForKey:[_keys objectAtIndex:row]]
withDelegate:self] autorelease];
[[self stack]pushController:e];
}
else {
row-=[_keys count];
if (row==0) {
SMFDictionaryObjectEditor *ee = [[[SMFDictionaryObjectEditor alloc] initWithKey:nil
withObject:nil
withDelegate:self] autorelease];
[[self stack]pushController:ee];
}
else if(row==1)
{
if (self.delegate!=nil && [self.delegate respondsToSelector:@selector(setObject:forKey:)]) {
[self.delegate setObject:_d forKey:(NSString *)self.key];
}
[[self stack]popController];
}
}
}
-(void)deleteObjectForKey:(NSString *)k
{
if (k!=nil && [[_d allKeys] containsObject:k]) {
[_d removeObjectForKey:k];
}
[self refresh];
}
-(void)setObject:(NSObject *)obj forKey:(NSString *)k
{
if (obj!=nil && k!=nil) {
[_d setObject:obj forKey:k];
}
[self refresh];
}
@end