Edit text in NSOutlineView like Finder

瘦欲@ 提交于 2019-12-11 04:18:58

问题


If you rename a file in the Finder, the text field expands horizontally up to about the width of the column. And then it expands vertically up to three rows before scrolling. I'm assuming this has to be done in a text field outside the outline view. And I can get a text field to resize while I type. I just don't know how to place it over the outline view when necessary. And keep it pinned to the row if the outline view scrolls. Does anyone have any insights? Thanks!


回答1:


Text editing is handled by a dedicated NSText and it’s called “field editor”. This shared single view is used for all text editing that happens in the window. It’s separate from what usually displays the text (when not editing).

Here are the docs: https://developer.apple.com/documentation/appkit/nswindow/1419647-fieldeditor

As mentioned in the docs discussion section, you can use and customize another field editor. This should be a starting point for your task.

The window’s delegate can substitute a custom field editor in place of the window’s field editor by implementing windowWillReturnFieldEditor(_:to:). The custom field editor can become the default editor (common to all text-displaying objects) or specific to a particular text-displaying object (object).

NSControl docs also have a section about Field Editor that might help.



来源:https://stackoverflow.com/questions/54202861/edit-text-in-nsoutlineview-like-finder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!