forked from rentzsch/clicktoflash
/
CTFPreferencesDictionary.m
92 lines (76 loc) · 2.04 KB
/
CTFPreferencesDictionary.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
//
// CTFPreferencesDictionary.m
// ClickToFlash
//
// Created by Simone Manganelli on 2009-05-25.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
// the rationale for this class is so that we can monitor when
// defaults change, and update the *external* preference file accordingly.
// to do so, we need to monitor the mutable dictionary that represents the
// defaults. this class follows @bbum's suggestion at this URL:
// http://www.omnigroup.com/mailman/archive/macosx-dev/1999-April/007726.html
#import "CTFPreferencesDictionary.h"
static CTFPreferencesDictionary *sharedInstance = nil;
@implementation CTFPreferencesDictionary
+ (id)dictionaryWithDictionary:(NSDictionary *)otherDictionary;
{
return [[[CTFPreferencesDictionary alloc] initWithDictionary:otherDictionary] autorelease];
}
+ (id)allocWithZone:(NSZone *)zone;
{
if (sharedInstance) {
return [sharedInstance retain];
} else {
return [super allocWithZone:zone];
}
}
- (id)init;
{
if (! sharedInstance) {
if ((self = [super init])) {
realMutableDictionary = [[NSMutableDictionary alloc] init];
hasInited = YES;
}
}
return self;
}
- (id)initWithDictionary:(NSDictionary *)otherDictionary;
{
if (! sharedInstance) {
if ((self = [super init])) {
realMutableDictionary = [[NSMutableDictionary dictionaryWithDictionary:otherDictionary] retain];
hasInited = YES;
}
} else {
[sharedInstance setDictionary:otherDictionary];
}
return self;
}
- (void)dealloc;
{
[realMutableDictionary release];
[super dealloc];
}
- (void)setObject:(id)object forKey:(id)key;
{
[realMutableDictionary setObject:object forKey:key];
[[NSNotificationCenter defaultCenter] postNotificationName:@"ClickToFlashPluginDefaultsDidChange" object:self];
}
- (void)removeObjectForKey:(id)key;
{
[realMutableDictionary removeObjectForKey:key];
}
- (id)objectForKey:(id)key;
{
return [realMutableDictionary objectForKey:key];
}
- (NSUInteger)count;
{
return [realMutableDictionary count];
}
- (NSEnumerator *)keyEnumerator;
{
return [realMutableDictionary keyEnumerator];
}
@end