FROM : Corbin Dunn
DATE : Fri May 02 20:40:15 2008
On May 1, 2008, at 6:47 PM, Mike Rossetti wrote:
> So I've discovered an interesting behavior in NSPathControl and am
> wondering if it warrants a Radar.
>
> I'm building up my own presentation of the file path to be shown in
> the NSPathControl. Specifically, if the file for which the path is
> being presented is in some standard location then I'm abbreviating
> the path. As a simple example, if the file is in ~/Documents/
> FIle.txt then instead of:
>
> Users > User A > Documents > File.txt
>
> I will show:
>
> Documents > File.txt
>
> The approach I'm taking is to pass a payload (an NSArray) to my
> customization of NSPathControl's setObjectValue. In setObjectValue
> I compose a string ("/Documents/File.txt") that I pass on to [super
> setObjectValue:], which sets up the NSPathComponentCells just fine.
> Then I iterate over the pathComponentCells calling each one's
> setURL. (And in this example that would be 'file://localhost/Users/
> User A/Documents/' for the first cell, and 'file://localhost/Users/
> User A/Documents/File.txt' for the second cell.)
>
> Doing this in a forward direction gives the following cell URLs:
>
> 0. file://localhost/Users/User A/Documents/File.txt
> 1. NSPathCell://localhost/Documents/File.txt
>
> Say what?
>
> Interestingly, if I do this in a reverse direction I get the
> _proper_ cell URLs:
>
> 0. file://localhost/Users/User A/Documents/
> 1. file://localhost/Users/User A/Documents/File.txt
>
> If this is a bug, I'll be happy to write up a small test app to
> present the problem.
This isn't a bug. If you pass a given string to NSPathCell, it doesn't
know if it is a file path. Since it doesn't know it is a file path, it
assumes the string represents some arbitrary non-file:// path, and
creates the URL with:
result = [[[NSURL alloc] initWithScheme:[self className]
host:@"localhost" path:[[self stringValue]
stringByExpandingTildeInPath]] autorelease];
This lets it avoid finding icons for things which aren't really paths
(even if they "look" like paths).
When filling up each of the pathcomponent cells, it passes along the
same scheme, host, etc to it:
NSURL *itemUrl = [[NSURL alloc] initWithScheme:[url scheme]
host:(host ? host : @"") path:path];
It is possible that there is an error in there, but I didn't see any
when I was looking at the code.
Long story short: use setURL:, or manually manage the path component
cells after calling super setObjectValue:
corbin
DATE : Fri May 02 20:40:15 2008
On May 1, 2008, at 6:47 PM, Mike Rossetti wrote:
> So I've discovered an interesting behavior in NSPathControl and am
> wondering if it warrants a Radar.
>
> I'm building up my own presentation of the file path to be shown in
> the NSPathControl. Specifically, if the file for which the path is
> being presented is in some standard location then I'm abbreviating
> the path. As a simple example, if the file is in ~/Documents/
> FIle.txt then instead of:
>
> Users > User A > Documents > File.txt
>
> I will show:
>
> Documents > File.txt
>
> The approach I'm taking is to pass a payload (an NSArray) to my
> customization of NSPathControl's setObjectValue. In setObjectValue
> I compose a string ("/Documents/File.txt") that I pass on to [super
> setObjectValue:], which sets up the NSPathComponentCells just fine.
> Then I iterate over the pathComponentCells calling each one's
> setURL. (And in this example that would be 'file://localhost/Users/
> User A/Documents/' for the first cell, and 'file://localhost/Users/
> User A/Documents/File.txt' for the second cell.)
>
> Doing this in a forward direction gives the following cell URLs:
>
> 0. file://localhost/Users/User A/Documents/File.txt
> 1. NSPathCell://localhost/Documents/File.txt
>
> Say what?
>
> Interestingly, if I do this in a reverse direction I get the
> _proper_ cell URLs:
>
> 0. file://localhost/Users/User A/Documents/
> 1. file://localhost/Users/User A/Documents/File.txt
>
> If this is a bug, I'll be happy to write up a small test app to
> present the problem.
This isn't a bug. If you pass a given string to NSPathCell, it doesn't
know if it is a file path. Since it doesn't know it is a file path, it
assumes the string represents some arbitrary non-file:// path, and
creates the URL with:
result = [[[NSURL alloc] initWithScheme:[self className]
host:@"localhost" path:[[self stringValue]
stringByExpandingTildeInPath]] autorelease];
This lets it avoid finding icons for things which aren't really paths
(even if they "look" like paths).
When filling up each of the pathcomponent cells, it passes along the
same scheme, host, etc to it:
NSURL *itemUrl = [[NSURL alloc] initWithScheme:[url scheme]
host:(host ? host : @"") path:path];
It is possible that there is an error in there, but I didn't see any
when I was looking at the code.
Long story short: use setURL:, or manually manage the path component
cells after calling super setObjectValue:
corbin
| Related mails | Author | Date |
|---|---|---|
| Mike Rossetti | May 2, 03:47 | |
| Kyle Sluder | May 2, 10:18 | |
| Corbin Dunn | May 2, 20:40 |






Cocoa mail archive

