0

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).

4

2 回答 2

1

我无法重现这一点。我刚试了一下,效果很好。如果符号链接指向一个目录,它会在我选择符号链接时显示目录内容,如果符号链接指向一个文件,我也可以选择它。

当然如果符号链接指向一个目录,你只能在允许选择目录的情况下选择它

NSOpenPanel * panel = [NSOpenPanel openPanel];
[panel setCanChooseDirectories:YES];
if ([panel runModalForTypes:nil] == NSOKButton) {
    NSLog(@"%@", [panel filenames]);
}
于 2008-10-10T15:49:58.410 回答
0

您的代码示例也对我有用——如果重要的话,我使用的是 10.5.5 和 XCode 3.1。

如果别名指向目录,我无法选择别名,因为它解析为它指向的目录,而不是别名本身(面板似乎默认解析别名)。不过,我能够为文件选择别名。

于 2008-10-10T23:20:06.613 回答