Editable NSTextField in NSMenuItem Custom View

I have a subclass of NSView that I would like to contain an editable NSTextField similar to Spotlight.

It is very difficult for me to get a text box for selection and selection. If I quickly and quickly clicked on the edit field of a text field, I can actually enter the text, but it looks gray, as if I are adding text to an application field that is not the main one.

I tried to get the focus of the View window using viewDidMoveToWindow, but apparently, NSMenuItem are windows with windows that don't handle keys very well.

In short, what is a good way to make this work a success? I know that Spotlight is a borderless window, but it is not suitable for my purposes.

Any suggestions would be very helpful.

+3
source share
2 answers

After much research, two things have a common consensus:

(1) If you find that you are looking for ways to subclass a built-in user interface element for special features, you are doing something wrong, or at least there is a better way to do what you are trying to do.

(2) The reason for following the interface guidelines is more reliable compatibility with the future. There is no guarantee that a subclassified user interface element will be compatible with future versions of the OS.

Brass Tacks - UI subclass elements are generally not recommended.

+1
source

You might want to check out Matt Gemmell MAAttachedWindow.

http://mattgemmell.com/2007/10/03/maattachedwindow-nswindow-subclass

0

Source: https://habr.com/ru/post/1795389/


All Articles