On 26 Oct 2012, at 10:55, "Gerriet M. Denkmann" <gerr...@mdenkmann.de> wrote:

> 
> 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.

This is a fundamental aspect of Cocoa programming. Cocoa is entirely free to 
use its own private subclasses of NSWindow if it sees fit, and indeed some bits 
of the runtime will dynamically create subclasses too. -isMemberOfClass: is 
very rarely the right thing to use, and isn't correct here.
> 
>> 
>>> 
>>>  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.

It's actually a method on NSWindowController.
_______________________________________________

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