NSTextfield + NSMenu and first responder
up vote
4
down vote
favorite
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.
objective-c cocoa autocomplete nstextfield nsmenu
add a comment |
up vote
4
down vote
favorite
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.
objective-c cocoa autocomplete nstextfield nsmenu
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
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.
objective-c cocoa autocomplete nstextfield nsmenu
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.
objective-c cocoa autocomplete nstextfield nsmenu
objective-c cocoa autocomplete nstextfield nsmenu
edited Nov 11 at 16:38
Marek H
2,2971222
2,2971222
asked May 20 '11 at 10:19
Dimillian
2,02432346
2,02432346
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
4
down vote
accepted
I don't believe this is possible with NSMenu. NSMenu implementation is controlled by the system at a quite low level, and it is designed to take keyboard focus. What you need is to create your own view, or window, that looks somewhat like a menu, but is not using NSMenu. Notice for example that that the menu in the chrome address bar does not look like a standard NSMenu. You need to create a view that will appear and draw, and receive callbacks or notifications to update as the user types, but will not take keyboard focus. There are methods on NSView (NSResponder actually) that control whether a view accepts first responder status.
I already trashed the NSMenu and go for a TableView view.The problem is that if I give the firstResponder to the TableView I will not be able to type anymore chars into the text field. The solution would be to forward only the arrow up and down key to the TableView and do the appropriate actions.
– Dimillian
May 22 '11 at 9:04
add a comment |
up vote
1
down vote
As mgorbach stated it is not really possible with NSMenu.
I've switched to NSTableView and customized my textfield. The textfield forward the up and down arrow to the Table view and that work fine !
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
I don't believe this is possible with NSMenu. NSMenu implementation is controlled by the system at a quite low level, and it is designed to take keyboard focus. What you need is to create your own view, or window, that looks somewhat like a menu, but is not using NSMenu. Notice for example that that the menu in the chrome address bar does not look like a standard NSMenu. You need to create a view that will appear and draw, and receive callbacks or notifications to update as the user types, but will not take keyboard focus. There are methods on NSView (NSResponder actually) that control whether a view accepts first responder status.
I already trashed the NSMenu and go for a TableView view.The problem is that if I give the firstResponder to the TableView I will not be able to type anymore chars into the text field. The solution would be to forward only the arrow up and down key to the TableView and do the appropriate actions.
– Dimillian
May 22 '11 at 9:04
add a comment |
up vote
4
down vote
accepted
I don't believe this is possible with NSMenu. NSMenu implementation is controlled by the system at a quite low level, and it is designed to take keyboard focus. What you need is to create your own view, or window, that looks somewhat like a menu, but is not using NSMenu. Notice for example that that the menu in the chrome address bar does not look like a standard NSMenu. You need to create a view that will appear and draw, and receive callbacks or notifications to update as the user types, but will not take keyboard focus. There are methods on NSView (NSResponder actually) that control whether a view accepts first responder status.
I already trashed the NSMenu and go for a TableView view.The problem is that if I give the firstResponder to the TableView I will not be able to type anymore chars into the text field. The solution would be to forward only the arrow up and down key to the TableView and do the appropriate actions.
– Dimillian
May 22 '11 at 9:04
add a comment |
up vote
4
down vote
accepted
up vote
4
down vote
accepted
I don't believe this is possible with NSMenu. NSMenu implementation is controlled by the system at a quite low level, and it is designed to take keyboard focus. What you need is to create your own view, or window, that looks somewhat like a menu, but is not using NSMenu. Notice for example that that the menu in the chrome address bar does not look like a standard NSMenu. You need to create a view that will appear and draw, and receive callbacks or notifications to update as the user types, but will not take keyboard focus. There are methods on NSView (NSResponder actually) that control whether a view accepts first responder status.
I don't believe this is possible with NSMenu. NSMenu implementation is controlled by the system at a quite low level, and it is designed to take keyboard focus. What you need is to create your own view, or window, that looks somewhat like a menu, but is not using NSMenu. Notice for example that that the menu in the chrome address bar does not look like a standard NSMenu. You need to create a view that will appear and draw, and receive callbacks or notifications to update as the user types, but will not take keyboard focus. There are methods on NSView (NSResponder actually) that control whether a view accepts first responder status.
answered May 21 '11 at 9:12
Michael Gorbach
47923
47923
I already trashed the NSMenu and go for a TableView view.The problem is that if I give the firstResponder to the TableView I will not be able to type anymore chars into the text field. The solution would be to forward only the arrow up and down key to the TableView and do the appropriate actions.
– Dimillian
May 22 '11 at 9:04
add a comment |
I already trashed the NSMenu and go for a TableView view.The problem is that if I give the firstResponder to the TableView I will not be able to type anymore chars into the text field. The solution would be to forward only the arrow up and down key to the TableView and do the appropriate actions.
– Dimillian
May 22 '11 at 9:04
I already trashed the NSMenu and go for a TableView view.The problem is that if I give the firstResponder to the TableView I will not be able to type anymore chars into the text field. The solution would be to forward only the arrow up and down key to the TableView and do the appropriate actions.
– Dimillian
May 22 '11 at 9:04
I already trashed the NSMenu and go for a TableView view.The problem is that if I give the firstResponder to the TableView I will not be able to type anymore chars into the text field. The solution would be to forward only the arrow up and down key to the TableView and do the appropriate actions.
– Dimillian
May 22 '11 at 9:04
add a comment |
up vote
1
down vote
As mgorbach stated it is not really possible with NSMenu.
I've switched to NSTableView and customized my textfield. The textfield forward the up and down arrow to the Table view and that work fine !
add a comment |
up vote
1
down vote
As mgorbach stated it is not really possible with NSMenu.
I've switched to NSTableView and customized my textfield. The textfield forward the up and down arrow to the Table view and that work fine !
add a comment |
up vote
1
down vote
up vote
1
down vote
As mgorbach stated it is not really possible with NSMenu.
I've switched to NSTableView and customized my textfield. The textfield forward the up and down arrow to the Table view and that work fine !
As mgorbach stated it is not really possible with NSMenu.
I've switched to NSTableView and customized my textfield. The textfield forward the up and down arrow to the Table view and that work fine !
answered May 23 '11 at 14:40
Dimillian
2,02432346
2,02432346
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f6070492%2fnstextfield-nsmenu-and-first-responder%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown