• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

iSightを使ってBooklog,MediaMarkerインポート用CSVファイルを生成するアプリ


Commit MetaInfo

Revisione9e7cdedf9e5412fbce49efd2ba2a4a1ad8fdd63 (tree)
Time2011-04-10 09:11:52
Authormasakih <masakih@user...>
Commitermasakih

Log Message

[Mod] 開くサイトをUserDefaultsに保存するようにした。

Change Summary

Incremental Difference

--- a/BEExporterAttribute.m
+++ b/BEExporterAttribute.m
@@ -37,10 +37,7 @@ static NSArray *attributes = nil;
3737 while((aType = types[i++]) != NSUIntegerMax) {
3838 //
3939 BEExporterAttribute *attr = [[[BEExporterAttribute alloc] init] autorelease];
40- attr.type = aType;
41- // restore from UserDefaults
42-#warning MUST IMPLEMENT
43-
40+ attr.type = aType;
4441 if(!attr.site) {
4542 attr.site = [[BERegisterSite sites] objectAtIndex:0];
4643 }
@@ -100,4 +97,12 @@ static NSArray *attributes = nil;
10097 [aCoder encodeBool:isOpenAfterExport forKey:@"BEExpoterIsOpenAfterExport"];
10198 [aCoder encodeObject:site forKey:@"BEExporterSite"];
10299 }
100+
101+
102+- (id)description
103+{
104+ return [NSString stringWithFormat:
105+ @"Type->%d, open->%@, Site->%@",
106+ type, isOpenAfterExport ? @"YES":@"NO", site];
107+}
103108 @end
--- a/BEGeneralPreference.m
+++ b/BEGeneralPreference.m
@@ -12,6 +12,11 @@
1212 #import "BEExporterAttribute.h"
1313
1414
15+@interface BEGeneralPreference (BEPrivate)
16+- (void)restoreAttributes;
17+- (void)setSelection:(id)newSelection;
18+@end
19+
1520 @implementation BEGeneralPreference
1621
1722 - (id)init
@@ -20,12 +25,8 @@
2025 if(self) {
2126 [self setTitle:NSLocalizedString(@"General", @"General")];
2227 sites = [[BERegisterSite sites] retain];
23- attributes = [[BEExporterAttribute attribtues] retain];
24- selection = [BEPreference preference].openSite;
25- if(!selection) {
26- selection = [attributes objectAtIndex:0];
27- }
28- [selection retain];
28+ [self restoreAttributes];
29+ [self setSelection:[attributes objectAtIndex:0]];
2930 }
3031 return self;
3132 }
@@ -33,18 +34,56 @@
3334 {
3435 [sites release];
3536 [attributes release];
36- [selection retain];
37+ [self setSelection:nil];
3738 [super dealloc];
3839 }
3940
41+- (void)restoreAttributes
42+{
43+ NSArray *stored = [BEPreference preference].attributes;
44+ if(!stored) {
45+ attributes = [[BEExporterAttribute attribtues] retain];
46+ return;
47+ }
48+
49+ NSArray *origin = [BEExporterAttribute attribtues];
50+ if([origin isEqual:stored]) {
51+ attributes = [stored retain];
52+ return;
53+ }
54+
55+ NSMutableArray *array = [stored mutableCopy];
56+ for(id obj in origin) {
57+ if(![array containsObject:obj]) {
58+ [array addObject:obj];
59+ }
60+ }
61+ attributes = [[NSArray alloc] initWithArray:array];
62+}
63+
64+
4065 - (void)setSelection:(id)newSelection
4166 {
4267 if(selection == newSelection) return;
68+
69+ if(selection) {
70+ [selection removeObserver:self forKeyPath:@"isOpenAfterExport"];
71+ [selection removeObserver:self forKeyPath:@"site"];
72+ }
4373 id temp = selection;
4474 selection = [newSelection retain];
4575 [temp release];
4676
47- [BEPreference preference].openSite = selection;
77+ [selection addObserver:self forKeyPath:@"isOpenAfterExport" options:0 context:NULL];
78+ [selection addObserver:self forKeyPath:@"site" options:0 context:NULL];
79+}
80+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
81+{
82+ if(![keyPath isEqualToString:@"isOpenAfterExport"] && ![keyPath isEqualToString:@"site"]) {
83+ return [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
84+ }
85+
86+ [BEPreference preference].attributes = attributes;
4887 }
4988
5089 - (NSString *)iconName
--- a/BEPreference.h
+++ b/BEPreference.h
@@ -12,13 +12,9 @@
1212 extern NSString *const BEOpenAfterExported; // NSNumber of BOOL.
1313 extern NSString *const BEOpenSite; // BERegisterSite.
1414
15-
16-@class BERegisterSite;
17-
1815 @interface BEPreference : NSObject
1916
2017 + (BEPreference *)preference;
2118
22-@property (getter=isOpenAfterExport) BOOL openAfterExport;
23-@property (nonatomic, retain) BERegisterSite *openSite;
19+@property (nonatomic, retain) NSArray *attributes;
2420 @end
--- a/BEPreference.m
+++ b/BEPreference.m
@@ -12,7 +12,7 @@
1212 NSString *const BEOpenAfterExported = @"openAfterExported";
1313 NSString *const BEOpenSite = @"targetSite";
1414
15-
15+static NSString *const BESiteOpenAttributes = @"SiteOpenAttributes";
1616
1717 @implementation BEPreference
1818 static BEPreference *sharedInstance = nil;
@@ -36,25 +36,16 @@ static BEPreference *sharedInstance = nil;
3636 [ud setObject:object forKey:key];
3737 }
3838
39-- (BOOL)isOpenAfterExport
40-{
41- id val = [self objectForKey:BEOpenAfterExported];
42- return [val boolValue];
43-}
44-- (void)setOpenAfterExport:(BOOL)flag
39+- (NSArray *)attributes
4540 {
46- [self setObject:[NSNumber numberWithBool:flag]
47- forKey:BEOpenAfterExported];
48-}
49-
50-- (BERegisterSite *)openSite
51-{
52- id data = [self objectForKey:BEOpenSite];
41+ NSData *data = [self objectForKey:BESiteOpenAttributes];
42+ if(!data) return nil;
5343 return [NSKeyedUnarchiver unarchiveObjectWithData:data];
5444 }
55-- (void)setOpenSite:(BERegisterSite *)site
45+- (void)setAttributes:(NSArray *)attributes
5646 {
57- id data = [NSKeyedArchiver archivedDataWithRootObject:site];
58- [self setObject:data forKey:BEOpenSite];
47+ NSData *data = [NSKeyedArchiver archivedDataWithRootObject:attributes];
48+ [self setObject:data forKey:BESiteOpenAttributes];
5949 }
50+
6051 @end
--- a/BERegisterSite.m
+++ b/BERegisterSite.m
@@ -130,4 +130,11 @@ static NSArray *sSites = nil;
130130 [aCoder encodeObject:account forKey:@"account"];
131131 }
132132
133+- (id)description
134+{
135+ return [NSString stringWithFormat:
136+ @"Name->%@, Home->%@, Reg->%@, id->%@, ac->%@",
137+ name, home, registerPage, needID, account];
138+}
139+
133140 @end