tags:

views:

294

answers:

2

I want to create an NSOpenPanel that can select any kind of file, so I do this

NSOpenPanel*    panel = [NSOpenPanel openPanel];

if([panel runModalForTypes:nil] == NSOKButton) {
    // process files here
}

which lets me select all files except symbolic links.
They're simply not selectable and the obvious setResolvesAliases
does nothing.

What gives?

Update 1: I did some more testing and found that this strangeness
is present in Leopard (10.5.5) but not in Tiger (10.4.8).

Update 2: The code above can select mac aliases (persistent path
data that lives in the resource fork) but not symlinks (files created with ln -s).

+1  A: 

I cannot reproduce this. I just tried it and it works just fine. If symlink points to a directory, it shows the directory content when I select the symlink and if the symlink points to a file, I can select it as well.

Of course if the symlink points to a directory, you can only select it if choosing directories is allowed

NSOpenPanel * panel = [NSOpenPanel openPanel];
[panel setCanChooseDirectories:YES];
if ([panel runModalForTypes:nil] == NSOKButton) {
 NSLog(@"%@", [panel filenames]);
}
Mecki
If I add your line `[panel setCanChooseDirectories:YES];`, then I can select symlinks, but I can also select directories, which I don't want. Strange that it works for you. You're not running Leopard I take it.
Rhythmic Fistman
A: 

Your code sample worked for me, as well - I'm using 10.5.5 and XCode 3.1, if it matters.

If the alias is to a directory, I couldn't select the alias, since it resolved to the directory that it was pointing to, not the alias itself (the panel seems to resolve aliases by default). I was able to select an alias to a file, though.

Andy
That's my exact setup. So with my sample you can select an alias to a file and then click the Open button?
Rhythmic Fistman
Yes - I copy + pasted the code that you included in the question into a test app that I just created.
Andy
Actually, it works for me too, but only when the file is an mac alias (a sort of persistent path that lives in the resource fork). I still can't select symlinks (files created with ln -s).
Rhythmic Fistman
When I try to select a symbolic link, I get the same behavior as you - I can't select it. It sounds like this is a bug in Leopard, then.
Andy