添加到“最近打开”菜单项不指向文件

发布于 2024-09-09 10:01:31 字数 1401 浏览 1 评论 0原文

有没有办法将一个不指向文件系统上存在的文件的项目添加到“打开最近的”菜单?

在不基于NSDocument,我可以使用以下代码将一个项目添加到“打开最近的”子菜单:

[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL URLWithString:stringToFilePath]];

它的工作方式为 记录,只要 URL 指向文件系统上存在的文件即可。

如果 url 不指向系统上的文件(例如 Web url 或自定义 url 方案),则不会发生任何情况。

例如,即使我的应用程序处理 URL 中使用的方案,此代码也没有任何效果,并且在执行期间不会生成任何日志:

[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL URLWithString:@"http://www.stackoverflow.com"]];

更新: 有人(很久以前)找到了一种调整此方法的方法菜单让它显示文件是否存在: http:// /lists.apple.com/archives/cocoa-dev/2007/Apr/msg00651.html

我成功地创建了 NSDocumentController 的子类,但我对方法的重写 - (NSArray *)recentDocumentURLs 从未被调用。

正如医生所说,这并不奇怪:

这个方法不太好 覆盖自内部 NSDocumentController 一般不会 使用它。

但文档没有说明该使用什么,海报也没有提供更多细节。有什么想法吗?


如果没有解决方案,解决方法是从头开始重写整个菜单。 如果可能的话,我宁愿避免这种情况,因为我免费获得的所有东西(例如当您有两个具有相同名称的项目时,它也会显示父目录以帮助区分它们)。

Is there a way to add an item that doesn't point to a file that exists on the file system to the "Open Recent" menu?

In an application not based on NSDocument, I can add an item to the "Open Recent" submenu with the following code:

[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL URLWithString:stringToFilePath]];

It works as documented, as long as the URL points to a file that exists on the file system.

If the url doesn't point to a file on the system, such as a web url, or a custom url scheme, nothing happens.

For example, this code has no effect, and produce no log during execution, even if my app handles the scheme used in the URL:

[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL URLWithString:@"http://www.stackoverflow.com"]];

Update: someone found (a long time ago) a way to tweak this menu to have it show files whether they exist or not: http://lists.apple.com/archives/cocoa-dev/2007/Apr/msg00651.html

I successfully managed to subclass NSDocumentController, but my override of the method - (NSArray *)recentDocumentURLs is never called.

It's not very surprising, as the doc says:

This method is not a good one to
override since the internals of
NSDocumentController do not generally
use it.

But the doc doesn't say what to use instead and the poster didn't give more detail. Any idea?


If there is no solution, on workaround would be to rewrite the entire menu from scratch.
If possible, I would prefer to avoid that, for all the stuff I get for free (like when you have two items with the same name, it displays the parent directory as well to help differentiate them).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓬勃野心 2024-09-16 10:01:31

看起来您可能必须创建自己的菜单并维护自己的单独列表。此菜单自动排除不存在的文件。

我相信对于不存在的可移动媒体上的文件也是如此(即,如果媒体回来,我相信该文件在列表中再次可用,如果它没有被更新的项目推迟)。

It looks like you'll probably have to create your own menu and maintain your own separate list. This menu automatically excludes files that don't exist.

I believe this is also true of files on removable media that is absent (ie, if the media comes back, the I believe the file is once again available in the list if it hasn't been pushed off by more recent items).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文