简体   繁体   English

为什么在NSOpenPanel中选择别名而不选择符号链接?

[英]Why can I select aliases but not symbolic links in NSOpenPanel?

I want to create an NSOpenPanel that can select any kind of file, so I do this 我想创建一个可以选择任何文件的NSOpenPanel ,所以我要这样做

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 它们根本是不可选的,并且明显是setResolvesAliases
does nothing. 什么也没做。

What gives? 是什么赋予了?

Update 1: I did some more testing and found that this strangeness 更新1:我进行了更多测试,发现这种奇怪之处
is present in Leopard (10.5.5) but not in Tiger (10.4.8). 在豹(10.5.5)中存在,但在老虎(10.4.8)中不存在。

Update 2: The code above can select mac aliases (persistent path 更新2:上面的代码可以选择mac别名(永久路径
data that lives in the resource fork) but not symlinks (files created with ln -s). 驻留在资源派生中的数据)而不是符号链接(使用ln -s创建的文件)。

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. 如果symlink指向目录,则在选择symlink时它会显示目录内容,如果symlink指向文件,则也可以选择它。

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]);
}

Your code sample worked for me, as well - I'm using 10.5.5 and XCode 3.1, if it matters. 您的代码示例也对我有用-如果重要,我正在使用10.5.5和XCode 3.1。

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. 不过,我能够为文件选择别名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM