如何在扩展坞中的应用程序中添加菜单? [英] How can I add a menu to the application in the dock?

查看:127
本文介绍了如何在扩展坞中的应用程序中添加菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在扩展坞中右键单击该应用程序时,将弹出一个上下文菜单.如何在其中添加菜单项?

When you right click on the application in the dock a context menu pops up. How can I add a menu item to this?

例如,使用Safari时,上下文菜单中会出现新建"窗口.

As for example with Safari you got New window in the context menu.

推荐答案

使用Nib文件添加静态菜单项

如果您的应用程序需要在应用程序的"Dock"图块菜单中添加静态项,则可以在nib文件中提供这些项.为此,请执行以下步骤.

If your application needs to add static items to the application’s Dock tile’s menu, you can provide those items in a nib file. To do this, perform the following steps.

  1. 启动界面生成器.
  2. 为菜单创建一个新的nib文件.
  3. 创建一个包含要添加到菜单中的项目的菜单.
  4. 将文件所有者的 dockMenu 出口(默认为 NSApplication )连接到菜单.
  5. 使用键 AppleDockMenu 将笔尖名称添加到 Info.plist 中.指定的笔尖名称不带扩展名.
  1. Launch Interface Builder.
  2. Create a new nib file for your menu.
  3. Create a menu that includes the items you wish to add to the menu.
  4. Connect the dockMenu outlet of the file’s owner (which by default is NSApplication) to your menu.
  5. Add the nib name to the Info.plist, using the key AppleDockMenu. The nib name is specified without an extension.

使用应用程序委托动态添加菜单项

应用程序还可以向应用程序的Dock磁贴菜单中动态提供项目.为此,您的应用程序的委托对象提供了一个 applicationDockMenu:方法.此方法返回一个NSMenu对象,该对象提供要添加到菜单的所有自定义菜单项.如果您还提供了使用笔尖文件的菜单(请参见

An application can also provide items dynamically to your application’s Dock tile’s menu. To do this, your application’s delegate object provides a applicationDockMenu: method. This method returns a NSMenu object that provides all the custom menu items you wish to add to the menu. If you also provided a menu using a nib file (see Adding Static Menu Items With a Nib File), any menu returned by your delegate replaces the menu provided in the nib file.

(来源: 查看全文

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