在OS X中的停靠上下文菜单中显示图标? [英] Show icons in the dock contextual menus in OS X?

查看:134
本文介绍了在OS X中的停靠上下文菜单中显示图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单:

要使用底座上应用程序图标的自定义菜单, - (NSMenu *)applicationDockMenu: (id)发送者; NSApplicationDelegate 必须返回dock将显示的菜单。

To use a custom menu for the apps icon on the dock, - (NSMenu*) applicationDockMenu: (id) sender; of the NSApplicationDelegate has to return the menu that the dock will display.

NSMenuItem 上使用 setImage 添加图标到菜单。它们显示在正常菜单上,但不显示在应用程序的停靠栏图标的上下文菜单中。

Using setImage on a NSMenuItem, you can normaly add icons to the menu. They show up on the normal menu, but not on in contextual menu of the app's dock icon.

然后苹果如何管理QuickTime,XCode,预览在最近打开的文件的列表中显示图标在他们的停靠上下文菜单中可访问?

Then how did Apple manage QuickTime, XCode, Preview to show icons in the list of recent opened files accessible in their dock contextual menu ?

Thx。

推荐答案

最近的文件列表实际上是标准Dock图标菜单的一部分。要在您的应用程序中使用它,您应该构建一个 NSDocument 的应用程序。通过使用 NSDocument ,您将免费获得最近的文件菜单/行为。

The recent files list is actually part of the standard Dock icon menu. To use it in your app, you should build an NSDocument-based application. By using NSDocument, you will get the recent files menu/behaviour for free.

如果您的应用程序不能基于在 NSDocument 上,您可以指示Cocoa根据网址维护最近的文档列表:

If your application cannot be based on NSDocument, you can instruct Cocoa to maintain a recent documents list based on URLs:

NSDocumentController *docController = [NSDocumentController sharedDocumentController];
[docController noteNewRecentDocumentURL:locationOfMyRecentFile1];
[docController noteNewRecentDocumentURL:locationOfMyRecentFile2];
[docController noteNewRecentDocumentURL:locationOfMyRecentFile3];

请注意,目前只有 -noteNewRecentDocumentURL:支持 file:// URL(您可以使用 + [NSURL fileURLWithPath:] 未来,它的行为将推定更改为允许与其他方案的URL。

Note that currently, -noteNewRecentDocumentURL: only supports file:// URLs (which you can create from a path with +[NSURL fileURLWithPath:].) In the future, its behaviour will presumably change to allow URLs with other schemes.

这篇关于在OS X中的停靠上下文菜单中显示图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆