mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-01 00:40:48 +00:00
Cache folders and their assdociation with icon names in dictionaries
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@31611 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
4a4dc924aa
commit
aa8d2b6778
2 changed files with 62 additions and 75 deletions
|
@ -4,6 +4,9 @@
|
||||||
* Images/GNUmakefile
|
* Images/GNUmakefile
|
||||||
Added new icon
|
Added new icon
|
||||||
|
|
||||||
|
* Source/NSWorkspace.m
|
||||||
|
Cache folders and their assdociation with icon names in dictionaries.
|
||||||
|
|
||||||
2010-11-11 Riccardo Mottola
|
2010-11-11 Riccardo Mottola
|
||||||
|
|
||||||
* Images/common_ImageFolder.tif
|
* Images/common_ImageFolder.tif
|
||||||
|
|
|
@ -88,14 +88,11 @@
|
||||||
|
|
||||||
#define PosixExecutePermission (0111)
|
#define PosixExecutePermission (0111)
|
||||||
|
|
||||||
|
static NSMutableDictionary *folderPathIconDict = nil;
|
||||||
|
static NSMutableDictionary *folderIconCache = nil;
|
||||||
|
|
||||||
static NSImage *folderImage = nil;
|
static NSImage *folderImage = nil;
|
||||||
static NSImage *libraryImage = nil;
|
|
||||||
static NSImage *systemImage = nil;
|
|
||||||
static NSImage *homeImage = nil;
|
|
||||||
static NSImage *documentsImage = nil;
|
|
||||||
static NSImage *imagesImage = nil;
|
|
||||||
static NSImage *multipleFiles = nil;
|
static NSImage *multipleFiles = nil;
|
||||||
static NSImage *rootImage = nil;
|
|
||||||
static NSImage *unknownApplication = nil;
|
static NSImage *unknownApplication = nil;
|
||||||
static NSImage *unknownTool = nil;
|
static NSImage *unknownTool = nil;
|
||||||
|
|
||||||
|
@ -655,6 +652,13 @@ static NSString *_rootPath = @"/";
|
||||||
|
|
||||||
- (id) init
|
- (id) init
|
||||||
{
|
{
|
||||||
|
NSArray *documentDir;
|
||||||
|
NSArray *libraryDirs;
|
||||||
|
NSArray *sysAppDir;
|
||||||
|
NSArray *downloadDir;
|
||||||
|
NSString *sysDir;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (sharedWorkspace != self)
|
if (sharedWorkspace != self)
|
||||||
{
|
{
|
||||||
RELEASE(self);
|
RELEASE(self);
|
||||||
|
@ -675,6 +679,42 @@ static NSString *_rootPath = @"/";
|
||||||
[self findApplications];
|
[self findApplications];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* icon associtation and caching */
|
||||||
|
folderPathIconDict = [[NSMutableDictionary alloc] initWithCapacity:5];
|
||||||
|
|
||||||
|
documentDir = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
||||||
|
downloadDir = NSSearchPathForDirectoriesInDomains(NSDownloadsDirectory, NSUserDomainMask, YES);
|
||||||
|
libraryDirs = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSAllDomainsMask, YES);
|
||||||
|
sysAppDir = NSSearchPathForDirectoriesInDomains(NSApplicationDirectory, NSSystemDomainMask, YES);
|
||||||
|
|
||||||
|
/* we try to guess a System directory and check if looks like one */
|
||||||
|
sysDir = nil;
|
||||||
|
if ([sysAppDir count] > 0)
|
||||||
|
{
|
||||||
|
sysDir = [[sysAppDir objectAtIndex: 0] stringByDeletingLastPathComponent];
|
||||||
|
if (![[sysDir lastPathComponent] isEqualToString: @"System"])
|
||||||
|
sysDir = nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sysDir != nil)
|
||||||
|
[folderPathIconDict setObject: @"GSFolder" forKey: sysDir];
|
||||||
|
|
||||||
|
[folderPathIconDict setObject: @"HomeDirectory" forKey: NSHomeDirectory()];
|
||||||
|
[folderPathIconDict setObject: @"ImageFolder" forKey: [NSHomeDirectory () stringByAppendingPathComponent: @"Images"]];
|
||||||
|
/* it would be nice to use different root icons... */
|
||||||
|
[folderPathIconDict setObject: @"Root_PC" forKey: _rootPath];
|
||||||
|
|
||||||
|
for (i = 0; i < [libraryDirs count]; i++)
|
||||||
|
[folderPathIconDict setObject: @"LibraryFolder" forKey: [libraryDirs objectAtIndex: i]];
|
||||||
|
|
||||||
|
for (i = 0; i < [documentDir count]; i++)
|
||||||
|
[folderPathIconDict setObject: @"DocsFolder" forKey: [documentDir objectAtIndex: i]];
|
||||||
|
|
||||||
|
for (i = 0; i < [downloadDir count]; i++)
|
||||||
|
[folderPathIconDict setObject: @"DownloadFolder" forKey: [downloadDir objectAtIndex: i]];
|
||||||
|
|
||||||
|
folderIconCache = [[NSMutableDictionary alloc] init];
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1167,92 +1207,36 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath
|
||||||
|
|
||||||
if (image == nil)
|
if (image == nil)
|
||||||
{
|
{
|
||||||
NSArray *documentDir;
|
|
||||||
NSArray *libraryDirs;
|
|
||||||
NSArray *sysAppDir;
|
|
||||||
NSString *sysDir;
|
|
||||||
|
|
||||||
documentDir = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
||||||
libraryDirs = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSAllDomainsMask, YES);
|
|
||||||
sysAppDir = NSSearchPathForDirectoriesInDomains(NSApplicationDirectory, NSSystemDomainMask, YES);
|
|
||||||
|
|
||||||
/* we try to guess a System directory and check if looks like one */
|
|
||||||
sysDir = nil;
|
|
||||||
if ([sysAppDir count] > 0)
|
|
||||||
{
|
|
||||||
sysDir = [[sysAppDir objectAtIndex: 0] stringByDeletingLastPathComponent];
|
|
||||||
if (![[sysDir lastPathComponent] isEqualToString: @"System"])
|
|
||||||
sysDir = nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
image = [self _iconForExtension: pathExtension];
|
image = [self _iconForExtension: pathExtension];
|
||||||
if (image == nil || image == [self unknownFiletypeImage])
|
if (image == nil || image == [self unknownFiletypeImage])
|
||||||
{
|
{
|
||||||
if ([fullPath isEqual: _rootPath])
|
NSString *iconName;
|
||||||
|
iconName = nil;
|
||||||
|
iconName = [folderPathIconDict objectForKey: fullPath];
|
||||||
|
if (iconName != nil)
|
||||||
{
|
{
|
||||||
if (rootImage == nil)
|
NSImage *iconImage;
|
||||||
{
|
|
||||||
rootImage = RETAIN([NSImage _standardImageWithName:
|
|
||||||
@"Root_PC"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
image = rootImage;
|
iconImage = [folderIconCache objectForKey: iconName];
|
||||||
}
|
if (iconImage == nil)
|
||||||
else if (sysDir != nil && [fullPath isEqual: sysDir])
|
|
||||||
{
|
|
||||||
if (systemImage == nil)
|
|
||||||
{
|
{
|
||||||
systemImage = RETAIN([NSImage _standardImageWithName:
|
iconImage = [NSImage _standardImageWithName: iconName];
|
||||||
@"GSFolder"]);
|
/* the dictionary retains the image */
|
||||||
|
[folderIconCache setObject: iconImage forKey: iconName];
|
||||||
}
|
}
|
||||||
image = systemImage;
|
image = iconImage;
|
||||||
}
|
|
||||||
else if ([libraryDirs containsObject: fullPath])
|
|
||||||
{
|
|
||||||
if (libraryImage == nil)
|
|
||||||
{
|
|
||||||
libraryImage = RETAIN([NSImage _standardImageWithName:
|
|
||||||
@"LibraryFolder"]);
|
|
||||||
}
|
|
||||||
image = libraryImage;
|
|
||||||
}
|
|
||||||
else if ([fullPath isEqual: NSHomeDirectory ()])
|
|
||||||
{
|
|
||||||
if (homeImage == nil)
|
|
||||||
{
|
|
||||||
homeImage = RETAIN([NSImage _standardImageWithName:
|
|
||||||
@"HomeDirectory"]);
|
|
||||||
}
|
|
||||||
image = homeImage;
|
|
||||||
}
|
|
||||||
else if ([fullPath isEqual: [NSHomeDirectory () stringByAppendingPathComponent: @"Images"]])
|
|
||||||
{
|
|
||||||
if (imagesImage == nil)
|
|
||||||
{
|
|
||||||
imagesImage = RETAIN([NSImage _standardImageWithName:
|
|
||||||
@"ImageFolder"]);
|
|
||||||
}
|
|
||||||
image = imagesImage;
|
|
||||||
}
|
|
||||||
else if ([documentDir count] > 0 && [fullPath isEqual: [documentDir objectAtIndex:0]])
|
|
||||||
{
|
|
||||||
if (documentsImage == nil)
|
|
||||||
{
|
|
||||||
documentsImage = RETAIN([NSImage _standardImageWithName:
|
|
||||||
@"DocsFolder"]);
|
|
||||||
}
|
|
||||||
image = documentsImage;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (folderImage == nil)
|
if (folderImage == nil)
|
||||||
{
|
{
|
||||||
folderImage = RETAIN([NSImage _standardImageWithName:
|
folderImage = RETAIN([NSImage _standardImageWithName:
|
||||||
@"Folder"]);
|
@"Folder"]);
|
||||||
}
|
}
|
||||||
image = folderImage;
|
image = folderImage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue