зеркало из https://github.com/mozilla/pjs.git
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:
Родитель
788efaad65
Коммит
10f146e768
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче