From a0b07ade1328ddec03a4c18ce317bf201cc6ad68 Mon Sep 17 00:00:00 2001 From: Richard Frith-Macdonald Date: Tue, 29 Jun 2004 10:31:05 +0000 Subject: [PATCH] Added a couple of MacOS-X compatibility methods. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@19651 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 ++++ Headers/Foundation/NSUserDefaults.h | 4 +++ Source/NSUserDefaults.m | 44 +++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/ChangeLog b/ChangeLog index 867ea78ed..590fe36f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-06-29 Richard Frith-Macdonald + + * Source/NSUserDefaults.m: Added MacOS-X compatibility methods .. + ([addSuiteNamed:]) and ([removeSuiteNamed:]) + 2004-06-27 Richard Frith-Macdonald * Tools/plparse.m: Check for and report illegal (non-ascii) characters diff --git a/Headers/Foundation/NSUserDefaults.h b/Headers/Foundation/NSUserDefaults.h index c06348582..769c772f4 100644 --- a/Headers/Foundation/NSUserDefaults.h +++ b/Headers/Foundation/NSUserDefaults.h @@ -167,6 +167,10 @@ GS_EXPORT NSString* const NSLocale; /* Returning the Search List */ - (NSMutableArray*) searchList; - (void) setSearchList: (NSArray*)newList; +#ifndef STRICT_OPENSTEP +- (void) addSuiteNamed: (NSString*)aName; +- (void) removeSuiteNamed: (NSString*)aName; +#endif /* Maintaining Persistent Domains */ - (NSDictionary*) persistentDomainForName: (NSString*)domainName; diff --git a/Source/NSUserDefaults.m b/Source/NSUserDefaults.m index 320baac5a..6d498b041 100644 --- a/Source/NSUserDefaults.m +++ b/Source/NSUserDefaults.m @@ -908,6 +908,32 @@ static NSString *pathForUser(NSString *user) return desc; } +/** + * Adds the domain names aName to the search list of the receiver.
+ * The domain is added after the application domain.
+ * Suites may be removed using the -removeSuiteName: method. + */ +- (void) addSuiteNamed: (NSString*)aName +{ + unsigned index; + + if (aName == nil) + { + [NSException raise: NSInvalidArgumentException + format: @"attempt to add suite with nil name"]; + } + [_lock lock]; + DESTROY(_dictionaryRep); + if (self == sharedDefaults) invalidatedLanguages = YES; + [_searchList removeObject: aName]; + index = [_searchList indexOfObject: processName]; + index++; // NSNotFound wraps to zero ... insert at start. + aName = [aName copy]; + [_searchList insertObject: aName atIndex: index]; + [_lock unlock]; + RELEASE(aName); +} + /** * Looks up a value for a specified default using -objectForKey: * and checks that it is an NSArray object. Returns nil if it is not. @@ -1758,6 +1784,24 @@ static BOOL isPlistObject(id o) [_lock unlock]; } +/** + * Removes the named domain from the serach list of the receiver.
+ * Suites may be added using the -addSuiteName: method. + */ +- (void) removeSuiteNamed: (NSString*)aName +{ + if (aName == nil) + { + [NSException raise: NSInvalidArgumentException + format: @"attempt to remove suite with nil name"]; + } + [_lock lock]; + DESTROY(_dictionaryRep); + if (self == sharedDefaults) invalidatedLanguages = YES; + [_searchList removeObject: aName]; + [_lock unlock]; +} + /************************************************************************* *** Accessing the User Defaults database *************************************************************************/