diff --git a/Headers/Protocols/Preferences.h b/Headers/Protocols/Preferences.h index 636b7bc..37a849f 100644 --- a/Headers/Protocols/Preferences.h +++ b/Headers/Protocols/Preferences.h @@ -47,7 +47,8 @@ - (float)floatForKey:(NSString *)key; - (float)floatForKey:(NSString *)key defaultValue:(float)defaultValue; - +- (int) integerForKey: (NSString *)key + defaultValue: (int)defaultValue; - (NSColor *)colorForKey:(NSString *)key; - (NSColor *)colorForKey:(NSString *)key defaultValue:(NSColor *)defaultValue; @@ -61,6 +62,9 @@ - (void)setFloat:(float)floatValue forKey:(NSString *)aKey notify:(BOOL)notify; +- (void) setInteger: (int)intValue + forKey: (NSString *)aKey + notify: (BOOL)notify; - (void)setColor:(NSColor *)color forKey:(NSString *)aKey notify:(BOOL)notify; diff --git a/Modules/Preferences/Indentation/PCIndentationPrefs.h b/Modules/Preferences/Indentation/PCIndentationPrefs.h index 1c11928..24eea70 100644 --- a/Modules/Preferences/Indentation/PCIndentationPrefs.h +++ b/Modules/Preferences/Indentation/PCIndentationPrefs.h @@ -36,7 +36,10 @@ #define IndentForHash @"IndentForHash" #define IndentForReturn @"IndentForReturn" #define IndentForSoloOpenCurly @"IndentForSoloOpenCurly" -#define IndentForNumberOfSpaces @"IndentForNumberOfSpaces" +#define IndentNumberOfSpaces @"IndentNumberOfSpaces" +#define IndentUsingSpaces @"IndentUsingSpaces" +#define IndentWidth @"IndentWidth" +#define TabWidth @"TabWidth" @interface PCIndentationPrefs : NSObject { @@ -53,6 +56,10 @@ id _indentForReturn; id _indentForSoloOpenCurly; id _indentNumberOfSpaces; + + id _indentUsingSpaces; + id _indentWidth; + id _tabWidth; } // Indentation @@ -70,4 +77,5 @@ - (void) setIndentUsingSpaces: (id)sender; - (void) setIndentWidth: (id)sender; - (void) setTabWidth: (id)sender; + @end diff --git a/Modules/Preferences/Indentation/PCIndentationPrefs.m b/Modules/Preferences/Indentation/PCIndentationPrefs.m index b8589fc..b51dad2 100644 --- a/Modules/Preferences/Indentation/PCIndentationPrefs.m +++ b/Modules/Preferences/Indentation/PCIndentationPrefs.m @@ -98,12 +98,33 @@ state = bVal ? NSOnState : NSOffState; [_indentForSoloOpenCurly setState: state]; - val = [prefs stringForKey: IndentForNumberOfSpaces + val = [prefs stringForKey: IndentNumberOfSpaces defaultValue: spacesDefault]; if (val) { [_indentNumberOfSpaces setStringValue: val]; } + + val = [prefs stringForKey: IndentUsingSpaces + defaultValue: spacesDefault]; + if (val) + { + [_indentUsingSpaces setStringValue: val]; + } + + val = [prefs stringForKey: IndentWidth + defaultValue: spacesDefault]; + if (val) + { + [_indentWidth setStringValue: val]; + } + + val = [prefs stringForKey: TabWidth + defaultValue: spacesDefault]; + if (val) + { + [_tabWidth setStringValue: val]; + } } - (NSView *) view @@ -124,7 +145,6 @@ [prefs setBool: state forKey: IndentForOpenCurly notify: YES]; } - - (void) setIndentForCloseCurlyBrace: (id)sender { BOOL state = ([sender state] == NSOffState) ? NO : YES; @@ -155,7 +175,6 @@ [prefs setBool: state forKey: IndentForReturn notify: YES]; } - - (void) setIndentForSoloOpenBrace: (id)sender { BOOL state = ([sender state] == NSOffState) ? NO : YES; @@ -164,19 +183,27 @@ - (void) setIndentNumberOfSpaces: (id)sender { + int val = [sender intValue]; + [prefs setInteger: val forKey: IndentNumberOfSpaces notify: YES]; } // Tabs/Spaces - (void) setIndentUsingSpaces: (id)sender { + NSUInteger idx = [sender indexOfSelectedItem]; + [prefs setInteger: idx forKey: IndentUsingSpaces notify: YES]; } - (void) setIndentWidth: (id)sender { + int val = [sender intValue]; + [prefs setInteger: val forKey: IndentWidth notify: YES]; } - (void) setTabWidth: (id)sender { + int val = [sender intValue]; + [prefs setInteger: val forKey: TabWidth notify: YES]; } - (void) dealloc diff --git a/Modules/Preferences/Indentation/Resources/IndentationPrefs.gorm/objects.gorm b/Modules/Preferences/Indentation/Resources/IndentationPrefs.gorm/objects.gorm index 22e1a9e..ea64523 100644 Binary files a/Modules/Preferences/Indentation/Resources/IndentationPrefs.gorm/objects.gorm and b/Modules/Preferences/Indentation/Resources/IndentationPrefs.gorm/objects.gorm differ diff --git a/PCPrefController.m b/PCPrefController.m index b7398c6..503035f 100644 --- a/PCPrefController.m +++ b/PCPrefController.m @@ -199,6 +199,22 @@ static PCPrefController *_prefCtrllr = nil; } } +- (int) integerForKey: (NSString *)key defaultValue: (int)defaultValue +{ + NSString *stringValue = [[NSUserDefaults standardUserDefaults] + objectForKey:key]; + + if (stringValue) + { + return [stringValue intValue]; + } + else + { + [self setInteger: defaultValue forKey: key notify: NO]; + return defaultValue; + } +} + - (NSColor *)colorForKey:(NSString *)key { return [self colorForKey:key defaultValue:nil]; @@ -275,6 +291,23 @@ static PCPrefController *_prefCtrllr = nil; } } +- (void) setInteger: (int)intValue + forKey: (NSString *)aKey + notify: (BOOL)notify +{ + NSString *stringValue = [NSString stringWithFormat:@"%d", intValue]; + + [[NSUserDefaults standardUserDefaults] setObject:stringValue + forKey:aKey]; + + if (notify) + { + [[NSNotificationCenter defaultCenter] + postNotificationName:PCPreferencesDidChangeNotification + object:self]; + } +} + - (void)setColor:(NSColor *)color forKey:(NSString *)aKey notify:(BOOL)notify