On 26 Oct 2012, at 16:11, Kyle Sluder <k...@ksluder.com> wrote:

> On Oct 26, 2012, at 1:52 AM, "Gerriet M. Denkmann" <gerr...@mdenkmann.de> 
> wrote:
> 
>> 
>> On 26 Oct 2012, at 01:11, Seth Willits <sli...@araelium.com> wrote:
>> 
>>> On Oct 25, 2012, at 4:36 AM, Gerriet M. Denkmann wrote:
>>> 
>>>> This works, but I have a strong feeling that there is a very obvious 
>>>> better solution which I somehow cannot see.
>>> 
>>> 
>>> There actually isn't an obvious solution.
>> 
>> Strange. 
>> I thought that having some InfoPanel which shows data of the current 
>> NSDocument would be a fairly common scenario.
>> But anyway. 
>> 
>> I decided to follow your suggestions.
>> 
>> My app delegate now has:
>> @property (strong) GmdDocument *currentDocument;
>> 
>> In applicationDidFinishLaunching: it registers for 
>> NSWindowDidBecomeMainNotification and NSWindowWillCloseNotification (not for 
>> NSWindowDidResignMainNotification because I want my InfoPanel to keep it's 
>> data when some other app becomes active).
>> 
>> The notification method is:
>> 
>> - (void)someWindowChanged: (NSNotification *)noti
>> {
>>   NSWindow *window = [ noti object ];
>> 
>>   if ( ![ window isMemberOfClass: [ NSWindow class ] ] ) return;    //    
>> ignore non-Windows
> 
> This check is wrong because it is too strict; it will fail for NSWindow 
> subclasses including NSPanel. The proper check here is -isKindOfClass:.

I am NOT interested if some panel closes (it probably would not become Main 
because being a Panel).
So I use isMemberOfClass because I am not interested in Window subclasses.

> 
>> 
>>   NSWindowController *windowController = [ window windowController ];
>>   if ( windowController == nil ) return;    //    ignore strange windows
> 
> NSWindow has a -document accessor. Use that instead of going though the 
> window controller.
Yes. I saw that in your previous post. But I asked both AppKiDo and Xcode and 
nobody showed me any documentation about this accessor. 
So I am wary of using undocumented stuff.
> 
>> 
>>   GmdDocument *document = [ windowController document ];
>>   if ( ![ document isKindOfClass: [ GmdDocument class ] ] ) return;    //    
>> ignore strange documents
> 
> This will bail out early without setting currentDocument if the new window 
> has no document. That's probably not want you want.

I am not interested in windows without a document. They won't belong to my 
NSDocument subclass, will they?
> 
>> 
>>   if ( [ [ noti name ] isEqualToString: NSWindowWillCloseNotification ] ) 
>> document = nil;         
>> 
>>   self.currentDocument = document; 
>> }
> 
> 
> Actually, I wouldn't write this method at all. I'd use the new block-based 
> NSNotification API and register different blocks for 
> NSWindowDidCloseNotification and NSWindowDidBecomeMainNotification.

Yes. This might be more efficient. And I might try this in the near future.
Thanks for this suggestion.


Kind regards,

Gerriet.



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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

This email sent to arch...@mail-archive.com

Reply via email to