• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Set focus on NSView in an NSMenuItem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Set focus on NSView in an NSMenuItem


  • Subject: Re: Set focus on NSView in an NSMenuItem
  • From: Pierre Bernard <email@hidden>
  • Date: Wed, 6 Feb 2008 09:37:59 +0100

Hi!

OK, I figured out how to add a timer. Unfortunately, that does not help with my problem of the misbehaving field editor.

- (void)viewDidMoveToWindow
{
	[super viewDidMoveToWindow];

	self.focusTimer = [NSTimer timerWithTimeInterval:1.0
											  target:self
											selector:@selector(focusOnSearchField)
											userInfo:nil
											 repeats:NO];

[[NSRunLoop currentRunLoop] addTimer:self.focusTimer forMode:NSEventTrackingRunLoopMode];
}


- (void)focusOnSearchField
{
	[[self window] makeFirstResponder:searchField];

	[self.focusTimer invalidate];
	self.focusTimer = nil;
}

Pierre


On 6 Feb 2008, at 00:43, Pierre Bernard wrote:

Hi Peter!
Hi Hendrik!

I have almost the same setup as Hendrik: I use a NSSearchField in a menu. When the menu is opened I want the focus to go to the search field.

At first sight, the solution suggested by Peter appears to work fine. But something goes wrong. My search field misbehaves when I do this.

To be exact, the window's text editor does not respect the properties of my search field. E.g. if I hit return while editing, I get a newline in my search field. I however expect the search field's action to be called.

So I figured, I could delay setting the focus using performSelector:afterDelay: or using a NSTimer. I wouldn't know if this could alleviate the above described problem. The thing is: in both cases my selector only gets called after the menu is dismissed.

Hendrik, did you get this to work as expected?
Peter, could it be that the text editor is called upon too early?

Best,
Pierre

On 4 Jan 2008, at 21:30, Peter Ammon wrote:


On Jan 4, 2008, at 6:20 AM, Hendrik Holtmann wrote:

Hi everyone,

I got another question regarding the new setView method in Leopard.
Let's assume I set the view for an NSMenuItem to myView. myView contains an NSTextField. Now when I open the NSMenu I want to set the focus on this textfield, so the user can directly enter some text without having to click on the control first (like it works in the spotlight menu). How can I achieve that? I know how to call keyOrderAndFront and setFirstRespinder for NSWindows but how can I do this with an NSMenu. Setting the firstresponder for myView to the NSTextField does not help unfortunately.

Probably the easiest approach would be to override viewDidMoveToWindow on the view that will be in the menu, and from within it call [[self window] makeFirstResponder:self];. makeFirstResponder is one of a very few methods that is safe to call on the menu window.


-Peter

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

--- Pierre Bernard http://www.bernard-web.com/pierre http://www.houdah.com




- - - Houdah Software s. à r. l. http://www.houdah.com

HoudahGeo: One-stop photo geocoding
HoudahSpot: Powerful Spotlight frontend



---
Pierre Bernard
http://www.bernard-web.com/pierre
http://www.houdah.com



Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Set focus on NSView in an NSMenuItem
      • From: Ron Fleckner <email@hidden>
References: 
 >Re: Set focus on NSView in an NSMenuItem (From: Pierre Bernard <email@hidden>)

  • Prev by Date: Server Address from Mounted SMB Volume
  • Next by Date: Re: Once again: Clickable hyperlink in NSTableView
  • Previous by thread: Re: Set focus on NSView in an NSMenuItem
  • Next by thread: Re: Set focus on NSView in an NSMenuItem
  • Index(es):
    • Date
    • Thread