diff --git a/ChangeLog b/ChangeLog index 5f5253634..68b1ff272 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2003-05-11 Richard Frith-Macdonald + + * Source/NSWorkspace.m: Add support for generic application icon. + Reduce private method name pollution a little. + * Images/common_UnknownApplication.tiff: copied from WM ... + 2003-05-05 Michael Hanni * Source/NSTabView.m: implemented diff --git a/Images/GNUmakefile b/Images/GNUmakefile index 6338f8aea..b4f2dc1bb 100644 --- a/Images/GNUmakefile +++ b/Images/GNUmakefile @@ -85,6 +85,7 @@ common_retH.tiff \ common_WMClose.tiff \ common_WMCloseBroken.tiff \ common_Unknown.tiff \ +common_UnknownApplication.tiff \ common_Folder.tiff \ common_Root_PC.tiff \ common_Root_SGI.tiff \ diff --git a/Images/common_UnknownApplication.tiff b/Images/common_UnknownApplication.tiff new file mode 100644 index 000000000..7e3ebe744 Binary files /dev/null and b/Images/common_UnknownApplication.tiff differ diff --git a/Source/NSWorkspace.m b/Source/NSWorkspace.m index 343b0f538..74061a2ba 100644 --- a/Source/NSWorkspace.m +++ b/Source/NSWorkspace.m @@ -56,6 +56,13 @@ #define PosixExecutePermission (0111) +static NSImage *folderImage = nil; +static NSImage *homeImage = nil; +static NSImage *multipleFiles = nil; +static NSImage *rootImage = nil; +static NSImage *unknownApp = nil; + + static NSString *GSWorkspaceNotification = @"GSWorkspaceNotification"; @interface _GSWorkspaceCenter: NSNotificationCenter @@ -174,10 +181,7 @@ static NSString *GSWorkspaceNotification = @"GSWorkspaceNotification"; - (NSImage*) _extIconForApp: (NSString*)appName info: (NSDictionary*)extInfo; - (NSImage*) _getImageWithName: (NSString*)name alternate: (NSString*)alternate; -- (NSImage*) folderImage; -- (NSImage*) homeDirectoryImage; - (NSImage*) unknownFiletypeImage; -- (NSImage*) rootImage; - (NSImage*) _iconForExtension: (NSString*)ext; - (BOOL) _extension: (NSString*)ext role: (NSString*)role @@ -799,6 +803,7 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath { NSFileManager *mgr = [NSFileManager defaultManager]; NSString *iconPath = nil; + BOOL isApplication = NO; if ([pathExtension isEqualToString: @"app"] || [pathExtension isEqualToString: @"debug"] @@ -806,6 +811,7 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath { NSBundle *bundle; + isApplication = YES; bundle = [NSBundle bundleWithPath: fullPath]; iconPath = [[bundle infoDictionary] objectForKey: @"NSIcon"]; if (iconPath && [iconPath isAbsolutePath] == NO) @@ -842,6 +848,10 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath if ([mgr isReadableFileAtPath: iconPath] == NO) { iconPath = nil; + /* + * Just use the appropriate icon for the path extension + */ + image = [self _iconForExtension: pathExtension]; } } } @@ -863,8 +873,13 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath { NS_DURING { - image = [[NSImage alloc] initWithContentsOfFile: iconPath]; - AUTORELEASE(image); + NSImage *tmp; + + tmp = [[NSImage alloc] initWithContentsOfFile: iconPath]; + if (tmp != nil) + { + image = AUTORELEASE(tmp); + } } NS_HANDLER { @@ -880,15 +895,33 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath { if ([fullPath isEqual: _rootPath]) { - image = [self rootImage]; + if (rootImage == nil) + { + rootImage = RETAIN([self _getImageWithName: + @"Root_PC.tiff" + alternate: @"common_Root_PC.tiff"]); + } + + image = rootImage; } else if ([fullPath isEqual: NSHomeDirectory ()]) { - image = [self homeDirectoryImage]; + if (homeImage == nil) + { + homeImage = RETAIN([self _getImageWithName: + @"HomeDirectory.tiff" + alternate: @"common_HomeDirectory.tiff"]); + } + image = homeImage; } else { - image = [self folderImage]; + if (folderImage == nil) + { + folderImage = RETAIN([self _getImageWithName: + @"Folder.tiff" alternate: @"common_Folder.tiff"]); + } + image = folderImage; } } } @@ -910,8 +943,6 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath - (NSImage*) iconForFiles: (NSArray*)pathArray { - static NSImage *multipleFiles = nil; - if ([pathArray count] == 1) { return [self iconForFile: [pathArray objectAtIndex: 0]]; @@ -1535,34 +1566,6 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath return image; } -/** Returns the default icon to display for a directory */ -- (NSImage*) folderImage -{ - static NSImage *image = nil; - - if (image == nil) - { - image = RETAIN([self _getImageWithName: @"Folder.tiff" - alternate: @"common_Folder.tiff"]); - } - - return image; -} - -/** Returns the default icon to display for the user home directory */ -- (NSImage*) homeDirectoryImage -{ - static NSImage *image = nil; - - if (image == nil) - { - image = RETAIN([self _getImageWithName: @"HomeDirectory.tiff" - alternate: @"common_HomeDirectory.tiff"]); - } - - return image; -} - /** Returns the default icon to display for a directory */ - (NSImage*) unknownFiletypeImage { @@ -1577,20 +1580,6 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath return image; } -/** Returns the default icon to display for a directory */ -- (NSImage*) rootImage -{ - static NSImage *image = nil; - - if (image == nil) - { - image = RETAIN([self _getImageWithName: @"Root_PC.tiff" - alternate: @"common_Root_PC.tiff"]); - } - - return image; -} - - (NSImage*) _iconForExtension: (NSString*)ext { NSImage *icon = nil; @@ -1663,7 +1652,22 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath */ if (icon == nil) { - icon = [self unknownFiletypeImage]; + if ([ext isEqualToString: @"app"] == YES + || [ext isEqualToString: @"debug"] == YES + || [ext isEqualToString: @"profile"] == YES) + { + if (unknownApp == nil) + { + unknownApp = RETAIN([self _getImageWithName: + @"UnknownApplication.tiff" alternate: + @"common_UnknownApplication.tiff"]); + } + icon = unknownApp; + } + else + { + icon = [self unknownFiletypeImage]; + } } /*