2

I have an application I'm developing in cocoa, and I have a problem with NSPathControl.

I set the style of the control to Popup, and when I launch my App and click on the path control, it shows me a popup menu with the components of the URL I set. I.e., for URL like file://localhost/Applications/Games/ it shows me the following: My Macbook, Macintosh HD, Applications, Games.

Now, when I click on Applications, I receive an action, and whithin that action [[sender clickedPathComponentCell] URL] returns correct URL: file://localhost/Applications/.

Problem 1: But when I click on Macintosh HD, I get an URL with double trailing slash: file://localhost//.

Problem 2: is that I get the same URL file://localhost// when I click on My Macbook item. So, I have 2 questions:

  1. Why does the URL to Macintosh HD ends with double slash?

  2. How can I distinguish clicks on Macintosh HD and My Macbook, and what is the correct URL to My Macbook, where Finder shows the list of mounted volumes (on my macbook it is Macintosh HD and BOOTCAMP)?

I've examined the tutorial named "SourceView", but there was no item like My Macbook, so I was not able to find out, whether My Macbook is really exists as a some kind of virtual folder, or I should just use NSFileManager to get the list of mounted volumes.

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
Uniqus
  • 564
  • 1
  • 5
  • 21

1 Answers1

1

Problem #1:

The URL is file://localhost// because the path to your boot volume is /. It's a bit odd, but file://localhost/ (single slash) would mean "a file on localhost with no path", so you get file://localhost// (double slash) to mean "a file on localhost at path /.

You shouldn't really have to worry about the eccentricities of the URL you're getting - just pass it along to whatever needs it and it should deal with it just fine.

Problem #2:

"My MacBook" doesn't really exist - it's a virtual folder that shows the list of connected volumes, /Network, etc. There's isn't a valid path for it since it doesn't exist, so instead you get the path to your boot volume instead.

iKenndac
  • 18,730
  • 3
  • 35
  • 51
  • >The URL is file://localhost// because the path to your boot volume is /. Yeah, I thought about that, but what I do not understand, is why then URL to, say, Applications folder do not have double slash after localhost and just looks normally like file://localhost/Applications/, not file://localhost//Applications/ – Uniqus May 22 '12 at 20:44
  • And about #2, I'm still interested in how to distinguish clicks on "Macintosh HD" and "My Macbook" within NSPathControl. And thank you very much for answering) – Uniqus May 22 '12 at 20:51
  • It should be noted that if the path set on NSPathControl begins with a double slash "//", it will show "Macintosh HD > Users > Username > Example Directory". If the path begins with a single slash "/" it will show "Username > Example Directory". This question and answer helped me figure that out, I didn't see it documented anywhere else. – Andrew Mar 28 '18 at 04:44