NSTextFinder对NSTextView的操作 [英] NSTextFinder action on NSTextView
问题描述
我正在尝试捕获自定义 NSTextView
子类上的所有 NSTextFinderClient
调用.
I'm trying to capture all the NSTextFinderClient
calls on my custom NSTextView
subclass.
在我的-(void)performTextFinderAction:(id)sender
覆盖上调用show动作,但是对于下一个查找,上一个查找等,则不调用.
The show action is called on my -(void)performTextFinderAction:(id)sender
override, but for find next, find previous, etc. it's not called.
有什么想法吗?
谢谢!
如果您创建一个新项目并从界面生成器中拖动一个 NSTextView
,则当第一个查找栏位于第一个位置时,command-g和command-shift-g(查找下一个并查找上一个)不起作用响应者.
If you create a new project and drag an NSTextView
from interface builder, command-g and command-shift-g (find next and find previous) don't work when the find bar is first responder.
这是为什么?
我需要一个 NSTextView
的自定义子类来响应每个事件的查找栏.
I need a custom subclass of NSTextView
to respond to the find bar for every event.
推荐答案
我在Apple的TextEdit源代码中进行搜索,因为使用TextEdit,文本视图"中的标准搜索栏对于Command-G(和其他快捷方式)都可以正常工作,即使是搜索字段是第一响应者.
I searched in the Apple's TextEdit source code because with TextEdit, the standard search bar within the Text View works fine for command-G (and other shortcuts) even the search field is the first responder.
我找到了解决方法.
转到主菜单的笔尖,然后选择查找"(及相关)菜单项.它们应绑定到名为"performFindPanelAction:"的默认操作.现在取消绑定它们,然后绑定到第一响应者"的"performTextFinderAction:".
Go to your nib for the main menu, and select the "Find" (and related) menu items. They should be bound to the default action called "performFindPanelAction:." Now unbind them and bind to "performTextFinderAction:" of the First Responder instead.
您可能在第一响应者"的操作列表中找不到该操作.因此,您需要自己在第一响应者"的属性"检查器窗格中添加它.
You may not find that action in the First Responder's action list. So you need to add it by yourself in the First Responder's attributes inspector pane.
这是由下面的文件说的
在OS X v10.7之前,这些菜单项的默认操作是performFindPanelAction:.只要有可能,您应该更新您的实现以使用此新操作.
Before OS X v10.7, the default action for these menu items was performFindPanelAction:. Whenever possible which you should update your implementation to use this new action.