Better handling of directory icons

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4795 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-09-02 08:30:14 +00:00
parent 1d47eda1d6
commit db55929472
2 changed files with 41 additions and 28 deletions

View file

@ -1,6 +1,8 @@
Wed Sep 1 12:35:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk> Thu Sep 2 9:50:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* NSWorkspace.m: Attempted fix for locateApplicationBinary and tidied. * NSWorkspace.m: Attempted fix for locateApplicationBinary and tidied.
Modified fix for getting file icons of directories where the extension
is meaningless. Look for .dir.tiff as well.
Wed Sep 1 9:55:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk> Wed Sep 1 9:55:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>

View file

@ -642,12 +642,15 @@ inFileViewerRootedAtPath: (NSString *)rootFullpath
- (NSImage *) iconForFile: (NSString *)aPath - (NSImage *) iconForFile: (NSString *)aPath
{ {
NSImage *image = nil; NSImage *image = nil;
BOOL isDir = NO;
NSString *iconPath = nil; NSString *iconPath = nil;
NSString *pathExtension = [[aPath pathExtension] lowercaseString]; NSString *pathExtension = [[aPath pathExtension] lowercaseString];
NSFileManager *mgr = [NSFileManager defaultManager]; NSFileManager *mgr = [NSFileManager defaultManager];
NSDictionary *attributes;
NSString *fileType;
if ([mgr fileExistsAtPath: aPath isDirectory: &isDir] && isDir) attributes = [mgr fileAttributesAtPath: aPath traverseLink: YES];
fileType = [attributes objectForKey: NSFileType];
if ([fileType isEqual: NSFileTypeDirectory] == YES)
{ {
if ([pathExtension isEqualToString: @"app"] if ([pathExtension isEqualToString: @"app"]
|| [pathExtension isEqualToString: @"debug"] || [pathExtension isEqualToString: @"debug"]
@ -663,8 +666,7 @@ inFileViewerRootedAtPath: (NSString *)rootFullpath
} }
/* /*
* If there is no icon specified in the Info.plist for app * If there is no icon specified in the Info.plist for app
* try 'wrapper/app.tiff' and 'wrapper/.dir.tiff' as * try 'wrapper/app.tiff'
* possible locations for the application icon.
*/ */
if (iconPath == nil) if (iconPath == nil)
{ {
@ -675,39 +677,48 @@ inFileViewerRootedAtPath: (NSString *)rootFullpath
iconPath = [iconPath stringByAppendingPathExtension: @"tiff"]; iconPath = [iconPath stringByAppendingPathExtension: @"tiff"];
if ([mgr isReadableFileAtPath: iconPath] == NO) if ([mgr isReadableFileAtPath: iconPath] == NO)
{ {
str = @".dir.tiff"; iconPath = nil;
iconPath = [aPath stringByAppendingPathComponent: str];
if ([mgr isReadableFileAtPath: iconPath] == NO)
iconPath = nil;
} }
} }
}
if (iconPath) /*
* If we have no iconPath, try 'dir/.dir.tiff' as a
* possible locations for the directory icon.
*/
if (iconPath == nil)
{
iconPath = [aPath stringByAppendingPathComponent: @".dir.tiff"];
if ([mgr isReadableFileAtPath: iconPath] == NO)
{ {
NS_DURING iconPath = nil;
{
image = [[NSImage alloc] initWithContentsOfFile: iconPath];
AUTORELEASE(image);
}
NS_HANDLER
{
NSLog(@"BAD TIFF FILE '%@'", iconPath);
}
NS_ENDHANDLER
} }
} }
if (iconPath != nil)
{
NS_DURING
{
image = [[NSImage alloc] initWithContentsOfFile: iconPath];
AUTORELEASE(image);
}
NS_HANDLER
{
NSLog(@"BAD TIFF FILE '%@'", iconPath);
}
NS_ENDHANDLER
}
if (image == nil) if (image == nil)
{ {
image = [self _iconForExtension: pathExtension]; image = [self _iconForExtension: pathExtension];
} if (image == nil || image == [self unknownFiletypeImage])
{
if (image == nil) if ([aPath isEqual: _rootPath])
{ image = [self rootImage];
if ([aPath isEqual: _rootPath]) else
image = [self rootImage]; image = [self folderImage];
else }
image= [self folderImage];
} }
} }
else else