On 10/29/09 8:38 AM, Michael Ash wrote:
> On Wed, Oct 28, 2009 at 7:18 PM, Grant Erickson <[email protected]> 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 protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to