Skip to content

Commit

Permalink
improve the way files are labeled, improve performance
Browse files Browse the repository at this point in the history
For name:
  * trust `lastPathComponent` for the filesystem name instead of asking
Spotlight
For label:
  * use NSFileManager's `displayNameAtPath` for almost everything
  * use non-standard techniques only for types where it's been found to
be an improvement over NSFileManager
  * not getting MDItemRef for every single file really speeds things up
  • Loading branch information
skurfer committed Dec 4, 2012
1 parent eea18e2 commit 4641413
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions Quicksilver/Code-QuickStepCore/QSObject_FileHandling.m
Expand Up @@ -777,33 +777,23 @@ - (void)getNameFromFiles {
} else {
// generally: name = what you see in Terminal, label = what you see in Finder
NSString *path = [self objectForType:QSFilePathType];
MDItemRef mdItem = MDItemCreate(kCFAllocatorDefault, (CFStringRef)path);
if (mdItem) {
// get the actual filesystem name, in case we were passed a localized path
newName = [(NSString *)MDItemCopyAttribute(mdItem, kMDItemFSName) autorelease];
}
if (!newName) {
newName = [path lastPathComponent];
}
// check packages for a descriptive name
if ([self isPackage]) {
newLabel = [self descriptiveNameForPackage:path withKindSuffix:![self isApplication]];
}
newName = [path lastPathComponent];
[self setName:newName];
// look for a more suitable display name
if (!newLabel || [newLabel isEqualToString:newName]) {
// try getting kMDItemDisplayName first
// tends to work better than `displayNameAtPath:` for things like Preference Panes
if (mdItem) {
newLabel = [(NSString *)MDItemCopyAttribute(mdItem, kMDItemDisplayName) autorelease];
}
if (!newLabel) {
newLabel = [[NSFileManager defaultManager] displayNameAtPath:path];
}
}
// discard the label if it's still identical to name
if ([newLabel isEqualToString:newName]) newLabel = nil;
if ([[self fileExtension] isEqualToString:@"qsplugin"]) {
newLabel = [self descriptiveNameForPackage:path withKindSuffix:![self isApplication]];
} else if (UTTypeConformsTo((CFStringRef)[self fileUTI], (CFStringRef)@"com.apple.systempreference.prefpane")) {
// kMDItemDisplayName works better for Preference Panes
MDItemRef mdItem = MDItemCreate(kCFAllocatorDefault, (CFStringRef)path);
if (mdItem) {
newLabel = [(NSString *)MDItemCopyAttribute(mdItem, kMDItemDisplayName) autorelease];
}
}
// fall back to the default display name
if (!newLabel) {
newLabel = [[NSFileManager defaultManager] displayNameAtPath:path];
}
}
[self setName:newName];
[self setLabel:newLabel];
}

Expand Down

0 comments on commit 4641413

Please sign in to comment.