简体   繁体   English

没有“编辑”菜单项的可可应用程序中是否可以具有“编辑”功能?

[英]Is it possible to have 'Edit' functionality in a Cocoa applciation that doesn't have the 'Edit' menu item?

I'm working on a Cocoa application that will eventually only have 2 items in the main window menu. 我正在开发一个Cocoa应用程序,最终在主窗口菜单中只有2个项目。 Not included in these items is the 'Edit' menu item. 这些项目中未包含“编辑”菜单项。 Is it possible to add all the functionality of the 'Edit' item to the application without having 'Edit'? 是否可以在没有“编辑”的情况下将“编辑”项的所有功能添加到应用程序中? I'm talking about all of the copy, paste, undo etc.... I know one could do this by adding keyboard listeners in window controllers, but I'm wondering if this can be done any other way? 我正在谈论所有的复制,粘贴,撤消等操作。。。我知道可以通过在窗口控制器中添加键盘侦听器来做到这一点,但是我想知道是否可以通过其他方法完成?

The reason I want to do it differently is that I still want to use these commands in the native About window. 我想以其他方式执行此操作的原因是,我仍然想在本地“关于”窗口中使用这些命令。 That window doesn't have a controller (that I know of) that a listener could be added to. 该窗口没有可以添加侦听器的控制器(据我所知)。 If anyone has alternative ideas about how to do this I'm all ears. 如果有人对如何执行此操作有其他想法,我会非常高兴。

Yes. 是。 The edit menu items are just sending arbitrary "messages" to the "responder chain". 编辑菜单项只是向“响应者链”发送任意“消息”。

[[NSApplication sharedApplication] sendAction:@selector(copy:) to:nil from:self];

If you look at the event menu items inside interface builder, you can see the list of selectors being sent. 如果查看界面生成器中的事件菜单项,则可以看到正在发送的选择器列表。

From the documentation: 从文档中:

If aTarget is nil, sharedApplication looks for an object that can respond to the message—that is, an object that implements a method matching anAction. 如果aTarget为nil,则sharedApplication将寻找一个可以响应消息的对象,即,一个实现与anAction匹配的方法的对象。 It begins with the first responder of the key window. 它从键窗口的第一个响应者开始。 If the first responder can't respond, it tries the first responder's next responder and continues following next responder links up the responder chain. 如果第一个响应者无法响应,它将尝试第一个响应者的下一个响应者,并继续跟随下一个响应者将响应者链接起来。 If none of the objects in the key window's responder chain can handle the message, sharedApplication attempts to send the message to the key window's delegate. 如果键窗口的响应者链中没有任何对象可以处理该消息,则sharedApplication尝试将消息发送到键窗口的委托。

More details are here: 更多详细信息在这里:

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/EventArchitecture.html#//apple_ref/doc/uid/10000060i-CH3-SW2 https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/EventArchitecture.html#//apple_ref/doc/uid/10000060i-CH3-SW2

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

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