• 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: newbie:how to get the frontmost window but a key window
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: newbie:how to get the frontmost window but a key window


  • Subject: Re: newbie:how to get the frontmost window but a key window
  • From: j o a r <email@hidden>
  • Date: Fri, 11 Jan 2008 08:41:06 -0800


On Jan 11, 2008, at 2:58 AM, norio wrote:

What I want to do is to search text from the window just below "Find..." dialog, like almost every text editor do.


This should be a standard key window <-> main window relationship between your document window and the find panel.


My app opens a window which doesn't have text input field at launch time. The window just displays something.

Then open a document by selecting Open... from File menu. So you can open several windows. I thought they were main windows.


And they typically would be. Or to be more precise, at any given time _one_ of them would be the main window of your application:

<http://developer.apple.com/documentation/Cocoa/Conceptual/WinPanel/Concepts/ChangingMainKeyWindow.html >


And open Find.. window and when you press Find button on the window, text is being searched from the document of the window just below the Find window.

With these steps, currentDocument and mainWindow return nil as I told in the previous mail.
Who sets a window to main window? I went to see the inspector window of the window in IB but I couldn't get.


The main window is set automatically by AppKit as the user opens or switches between document windows. The same goes for the key window. This should work correctly out of the box.

Some troubleshooting steps:

* The basic requirement for this to work is that your document window is a type of window that assumes main status - typically NSWindow and subclasses thereof, but not including NSPanel. Likewise, your panels should be of a type that doesn't assume main window status, like NSPanel (or subclasses thereof).

* Sign up for and log the NSWindow key / main notifications to track how key & main window status changes while you work with your application. To do this, add notification registration to one of your shared controller objects:

[[NSNotificationCenter notificationCenter] addObserver: self
selector: @selector(windowDidBecomeKey:)
name: NSWindowDidBecomeKeyNotification
object: nil];


A good place for signing up for notifications is "awakeFromNib". Also implement the corresponding callback method:

- (void) windowDidBecomeKey:(NSNotification *) notification
{
NSWindow *window = [notification object];
NSLog(@"WindowDidBecomeKey: %@, (Title: \"%@\", Delegate: %@)", window, [window title], [window delegate]);
}


...and repeat for all relevant notifications:

	(NSWindowDidBecomeKeyNotification)
	NSWindowDidBecomeMainNotification
	NSWindowDidResignKeyNotification
	NSWindowDidResignMainNotification

Try opening, closing and switching between your application windows and panels and verify that the key and main status changes as you would expect.

j o a r


_______________________________________________

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


References: 
 >newbie:how to get the frontmost window but a key window (From: norio <email@hidden>)
 >Re: newbie:how to get the frontmost window but a key window (From: j o a r <email@hidden>)
 >Re: newbie:how to get the frontmost window but a key window (From: norio <email@hidden>)

  • Prev by Date: Re: BMP bug in ImageIO?
  • Next by Date: NSPanel hides with GC enabled
  • Previous by thread: Re: newbie:how to get the frontmost window but a key window
  • Next by thread: BMP bug in ImageIO?
  • Index(es):
    • Date
    • Thread