PathStyle changes

This commit is contained in:
Gregory John Casamento 2020-05-03 13:07:53 -04:00
parent 9a70a452b5
commit a27119c56d
4 changed files with 54 additions and 19 deletions

View file

@ -39,6 +39,7 @@ extern "C" {
{
NSImage *_image;
NSURL *_url;
BOOL _lastComponent;
}
- (NSImage *) image;

View file

@ -31,6 +31,10 @@
+ (NSArray *) _generateCellsForURL: (NSURL *)url;
@end
@interface NSPathComponentCell (Private)
- (void) _setLastComponent: (BOOL)f;
@end
@implementation NSPathCell
- (void)mouseEntered:(NSEvent *)event
@ -204,7 +208,7 @@
{
[self setPathStyle: NSPathStyleStandard];
if ([coder containsValueForKey: @"NSPathStyle"])
// if ([coder containsValueForKey: @"NSPathStyle"])
{
[self setPathStyle: [coder decodeIntegerForKey: @"NSPathStyle"]];
}
@ -244,16 +248,16 @@
NSPathComponentCell *cell = [[NSPathComponentCell alloc] init];
NSImage *image = nil;
if ([[url path] isEqualToString: @"/"])
{
at_root = YES;
}
AUTORELEASE(cell);
[cell setURL: url];
[fm fileExistsAtPath: [url path]
isDirectory: &isDir];
if ([[url path] isEqualToString: @"/"])
{
at_root = YES;
}
if (isDir && at_root == NO)
{
image = [NSImage imageNamed: @"NSFolder"];
@ -265,6 +269,16 @@
[cell setImage: image];
string = [string stringByDeletingLastPathComponent];
if ([array count] == 0) // the element we are adding is the last component that will show
{
[cell _setLastComponent: YES];
}
else
{
[cell _setLastComponent: NO];
}
[array insertObject: cell
atIndex: 0];
url = [NSURL URLWithString: string
@ -284,3 +298,12 @@
}
@end
@implementation NSPathComponentCell (Private)
- (void) _setLastComponent: (BOOL)f
{
_lastComponent = f;
}
@end

View file

@ -56,23 +56,35 @@
{
NSString *string = [[_url path] lastPathComponent];
NSRect textFrame = f;
NSRect imgFrame = f; // NSMakeRect(0.0, 0.0, 20.0, 20.0);
NSRect imgFrame = f;
NSRect arrowFrame = f;
NSImage *arrowImage = [NSImage imageNamed: @"NSMenuArrow"];
[super drawInteriorWithFrame: f inView: v];
// Modify positions...
textFrame.origin.x += 23.0; // the width of the image plus a few pixels.
textFrame.origin.y += 3; // center with the image...
textFrame.origin.x += 25.0; // the width of the image plus a few pixels.
textFrame.origin.y += 3.0; // center with the image...
imgFrame.size.width = 20.0;
imgFrame.size.height = 20.0;
arrowFrame.origin.x += f.size.width - 20.0;
arrowFrame.size.width = 8.0;
arrowFrame.size.height = 8.0;
arrowFrame.origin.y += 5.0;
// string = (string != nil) ? string : @"/";
[super drawInteriorWithFrame: f inView: v];
// Draw the image...
[_image drawInRect: imgFrame];
// Draw the text...
[[NSColor whiteColor] set];
[[NSColor textColor] set];
[string drawAtPoint: textFrame.origin
withAttributes: nil];
// Draw the arrow...
if (_lastComponent == NO)
{
[arrowImage drawInRect: arrowFrame];
}
}
@end

View file

@ -133,6 +133,7 @@
- (void) setPathItems: (NSArray *)items
{
ASSIGNCOPY(_pathItems, items);
[self setNeedsDisplay];
}
- (NSAttributedString *) placeholderAttributedString
@ -168,13 +169,6 @@
[self setNeedsDisplay];
}
/*
- (void) drawRect: (NSRect)frame
{
[super drawRect: frame];
}
*/
- (instancetype) initWithCoder: (NSKeyedUnarchiver *)coder
{
self = [super initWithCoder: coder];
@ -188,6 +182,11 @@
{
[self setBackgroundColor: [coder decodeObjectForKey: @"NSBackgroundColor"]];
}
if ([coder containsValueForKey: @"NSDragTypes"])
{
[self setAllowedTypes: [coder decodeObjectForKey: @"NSDragTypes"]];
}
}
else
{