• 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: 10.4 System Preferences Cannot Find Its Main Window When Launched by a Pane Bundle
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 10.4 System Preferences Cannot Find Its Main Window When Launched by a Pane Bundle


  • Subject: Re: 10.4 System Preferences Cannot Find Its Main Window When Launched by a Pane Bundle
  • From: Grant Erickson <email@hidden>
  • Date: Thu, 29 Oct 2009 15:31:49 -0700
  • Thread-topic: 10.4 System Preferences Cannot Find Its Main Window When Launched by a Pane Bundle

On 10/29/09 8:38 AM, Michael Ash wrote:
> On Wed, Oct 28, 2009 at 7:18 PM, Grant Erickson <email@hidden> wrote:
>> I am working on a preference pane and in order to accommodate differences
>> among 10.4 and 10.5 and later without hard-coding widths, I call my own
>> [self resizeView] from mainViewDidLoad to adjust the view width as
>> appropriate:
>>
>> [ ... sample code omitted ... ]
>>
>> Overall, this seems to work well; however, when testing automatic updates
>> with Sparkle, I noticed that when Sparkle relaunches the bundle
>> ("/Library/PreferencePanes/MyPane.prefPane") using its 'relaunch' binary
>> (which in turn uses NSWorkspace), that [[NSApplication sharedApplication]
>> mainWindow] returns NULL.
>>
>> In fact, when I check [[NSApplication sharedApplication] mainWindow] in all
>> of:
>>
>>    * initWithBundle
>>    * mainViewDidLoad
>>    * willSelect
>>    * didSelect
>>
>> Anyone else seen this behavior or developed a reasonable workaround? Perhaps
>> registering for and resize on NSWindowDidBecomeMainNotification?
>
> Quoth the docs:
>
> -----
> mainWindow
> Returns the main window.
>
> - (NSWindow *)mainWindow
>
> Return Value
> The application¹s main window or nil if there is no main window.
>
> Discussion
> This method might return nil if the application¹s nib file hasn¹t
> finished loading,
> if the receiver is not active,
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> or if the application is hidden.

I definitely saw that in the documentation; however, my confusion and
reconciliation was around 10.4 vs. 10.5 behaviors and direction application
vs. bundle launch behavior variances.

> For a workaround, why not just query for the window that your view is in?

That appears to work well enough for the didSelect case, whether opening by
the application or by a pane bundle.

The following also correctly catches the pane bundle launch case
effectively:

    - (void) windowDidBecomeMain: (NSNotification *)inNotification
    {
        NSWindow * changedWindow = [inNotification object];
        NSWindow * mainWindow = [[NSApplication sharedApplication]
                                 mainWindow];

        if ([changedWindow isEqualTo: mainWindow]) {
            [self resizeView];
        }
    }

Regards,

Grant


_______________________________________________

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: 
 >Re: 10.4 System Preferences Cannot Find Its Main Window When Launched by a Pane Bundle (From: Michael Ash <email@hidden>)

  • Prev by Date: Re: Changing the NSView bounds origin point
  • Next by Date: Re: Help debugging "Dangling reference to an invalid object." Core Data error
  • Previous by thread: Re: 10.4 System Preferences Cannot Find Its Main Window When Launched by a Pane Bundle
  • Next by thread: Showing activity indicator during data download
  • Index(es):
    • Date
    • Thread