Add NSString category for methods that get a couple of useful path-related strings (volume name, and file/folder display name).

Also fix memory leak in [NSView removeAllSubviews].
This commit is contained in:
smfr%smfr.org 2005-11-06 06:32:18 +00:00
Родитель 788efaad65
Коммит 10f146e768
3 изменённых файлов: 37 добавлений и 0 удалений

Просмотреть файл

@ -87,3 +87,10 @@ typedef enum
- (void)truncateToWidth:(float)maxWidth at:(ETruncationType)truncationType withAttributes:(NSDictionary *)attributes;
@end
@interface NSString (ChimeraFilePathStringUtils)
- (NSString*)volumeNamePathComponent;
- (NSString*)displayNameOfLastPathComponent;
@end

Просмотреть файл

@ -358,3 +358,32 @@
}
@end
@implementation NSString (ChimeraFilePathStringUtils)
- (NSString*)volumeNamePathComponent
{
// if the file doesn't exist, then componentsToDisplayForPath will return nil,
// so back up to the nearest existing dir
NSString* curPath = self;
while (![[NSFileManager defaultManager] fileExistsAtPath:curPath])
{
NSString* parentDirPath = [curPath stringByDeletingLastPathComponent];
if ([parentDirPath isEqualToString:curPath])
break; // avoid endless loop
curPath = parentDirPath;
}
NSArray* displayComponents = [[NSFileManager defaultManager] componentsToDisplayForPath:curPath];
if ([displayComponents count] > 0)
return [displayComponents objectAtIndex:0];
return self;
}
- (NSString*)displayNameOfLastPathComponent
{
return [[NSFileManager defaultManager] displayNameAtPath:self];
}
@end

Просмотреть файл

@ -188,6 +188,7 @@ static void RedistributeSpace(int resizeMask, float newWidth, /* in out */ float
// clone the array to avoid issues with the array changing during the enumeration
NSArray* subviewsArray = [[self subviews] copy];
[subviewsArray makeObjectsPerformSelector:@selector(removeFromSuperview)];
[subviewsArray release];
}
@end