I'm trying to implement my own autocomplemention system (result is pull from an sqlite database)
I've set up a NSTextField and the appropriate delegate. Each time the text in the NSTextField change, it call - (void)controlTextDidChange:(NSNotification *)aNotification
method
It work fine, in this method I build a menu programtically and finally I call/show it with that code:
NSRect frame = [address frame];
NSPoint menuOrigin = [[address superview] convertPoint:NSMakePoint(frame.origin.x, frame.origin.y+frame.size.height-25)
toView:nil];
NSEvent *event = [NSEvent mouseEventWithType:NSLeftMouseDown
location:menuOrigin
modifierFlags:NSLeftMouseDownMask // 0x100
timestamp:0
windowNumber:[[address window] windowNumber]
context:[[address window] graphicsContext]
eventNumber:0
clickCount:1
pressure:1];
[NSMenu popUpContextMenu:menu withEvent:event forView:address];
Where address
is my NSTextField
and menu
is my NSMenu
.
The problem is that the menu take the focus, so you can type only 1 letter in the text field and then you can't type text anymore because the menu is now the first responder.
My questions is how to show the menu and keep the text field as first responder so you can type in it while the menu is reloaded at each text change in the field.
It should be like in Safari or chrome address bar in fact for example.