Fix writeToFile: to use the specified file name.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@23594 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2006-09-22 18:02:57 +00:00
parent 785107cede
commit a34cac104e
3 changed files with 77 additions and 35 deletions

View file

@ -1,3 +1,9 @@
2006-09-22 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/AppKit/NSColorList.h: Add documentation.
* Source/NSColorList.m: Fix ([-writeToFile:]) to work as specified
by Apple's documentation.
2006-09-22 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/Additions/GNUstepGUI/GSDrawFunctions.h:

View file

@ -65,7 +65,7 @@
/**
* Initializes a new, empty color list registered under given name.
*/
- (id)initWithName:(NSString *)name;
- (id) initWithName: (NSString *)name;
/**
* <p>Initializes a new color list registered under given name, taking
@ -86,48 +86,78 @@
* for now the only supported method is "0", which is an RGBA format with
* the arguments in order R,G,B, A.</p>
*/
- (id)initWithName:(NSString *)name
fromFile:(NSString *)path;
- (id) initWithName: (NSString *)name
fromFile: (NSString *)path;
//
// Getting All Color Lists
//
+ (NSArray *)availableColorLists;
+ (NSArray *) availableColorLists;
//
// Getting a Color List by Name
//
+ (NSColorList *)colorListNamed:(NSString *)name;
- (NSString *)name;
/** Returns the first color list (from the array of available lists)
* matching name.
*/
+ (NSColorList *) colorListNamed: (NSString *)name;
//
// Managing Colors by Key
//
- (NSArray *)allKeys;
- (NSColor *)colorWithKey:(NSString *)key;
- (void)insertColor:(NSColor *)color
key:(NSString *)key
atIndex:(unsigned)location;
- (void)removeColorWithKey:(NSString *)key;
- (void)setColor:(NSColor *)aColor
forKey:(NSString *)key;
/** Returns an array containing all the keyus in the color list
*/
- (NSArray *) allKeys;
//
// Editing
//
- (BOOL)isEditable;
/** Returns the color for the specified key (if any).
*/
- (NSColor *) colorWithKey: (NSString *)key;
//
// Writing and Removing Files
//
- (BOOL)writeToFile:(NSString *)path;
- (void)removeFile;
/**
* Returns a flag indicating whether the receiver is editable.
*/
- (BOOL) isEditable;
/** Inserts a color into the color list at the specified index.
* Removes any other color with the same name.
*/
- (void) insertColor: (NSColor *)color
key: (NSString *)key
atIndex: (unsigned)location;
/**
* Returns the name of the receiver.
*/
- (NSString *) name;
/** Removes the color for the specified key from the list.
*/
- (void) removeColorWithKey: (NSString *)key;
/** Removes the on-disk representation of the list.
*/
- (void) removeFile;
/**
* Sets the color for this key and appends it to the color list.
*/
- (void) setColor: (NSColor *)aColor
forKey: (NSString *)key;
/**
* Writes the receiver to the specified path.<br />
* If path is nil, writes to a file located in the current user's personal
* Colors directory whose name is that of the list with the extension
* 'clr' appended.<br />
* If path is a directory, writes to a file in that directory whose name
* is that of the list with the extension 'clr' appended.<br />
* Otherwise (path is neither nil nor a directory), writes to the path
* without appending the l.ist name.<br />
* Returns YES on success, NO on failure.<br />
* Writing with a path of nil will cause the receiver to be added to the
* +availableColorLists if it is not already there.
*/
- (BOOL) writeToFile: (NSString *)path;
//
// NSCoding protocol
//
- (void)encodeWithCoder: (NSCoder *)aCoder;
- initWithCoder: (NSCoder *)aDecoder;
- (void) encodeWithCoder: (NSCoder *)aCoder;
- (id) initWithCoder: (NSCoder *)aDecoder;
@end

View file

@ -421,7 +421,7 @@ static NSColorList *themeColorList = nil;
*/
[NSColorList _loadAvailableColorLists: nil];
if (path == nil || ([fm fileExistsAtPath: path isDirectory: &isDir] == NO))
if (path == nil)
{
NSArray *paths;
@ -437,6 +437,10 @@ static NSColorList *themeColorList = nil;
stringByAppendingPathComponent: @"Colors"];
isDir = YES;
}
else
{
[fm fileExistsAtPath: path isDirectory: &isDir];
}
if (isDir)
{
@ -445,7 +449,6 @@ static NSColorList *themeColorList = nil;
}
else // it is a file
{
_fullFileName = path;
if ([[path pathExtension] isEqual: @"clr"] == YES)
{
ASSIGN (_fullFileName, path);
@ -455,11 +458,14 @@ static NSColorList *themeColorList = nil;
ASSIGN (_fullFileName, [[path stringByDeletingPathExtension]
stringByAppendingPathExtension: @"clr"]);
}
path = [path stringByDeletingLastPathComponent];
}
// Check if the path is a standard path
if ([[path lastPathComponent] isEqualToString: @"Colors"] == NO)
path_is_standard = NO;
{
path_is_standard = NO;
}
else
{
tmpPath = [path stringByDeletingLastPathComponent];
@ -500,7 +506,7 @@ static NSColorList *themeColorList = nil;
return YES;
}
return NO;
return success;
}
- (void) removeFile