Re: -[NSDocument fileURL] is observable (KVO). Documented?

2010-06-02 Thread Mike Abdullah

On 1 Jun 2010, at 23:25, Jerry Krinock wrote:

 
 On 2010 Jun 01, at 15:07, Mike Abdullah wrote:
 
 I'd advise subclassing to add your own notification posting code.
 
 Yuck.  Unless someone knows a better way, that means setting up either a 
 kqueue or FSEvents thingy for the document to watch its own path.  Does 
 anyone know an easier way?  Because of the way that a document window's title 
 changes instantly when its file is moved in Finder, apparently Apple has this 
 already built in to NSDocument.  Does anyone know how to hook into that, 
 ahead of setFileURL:?

er, I meant just override -setFileURL: to post a notification.

___

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

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


Re: -[NSDocument fileURL] is observable (KVO). Documented?

2010-06-02 Thread Jerry Krinock

On 2010 Jun 02, at 02:15, Mike Abdullah wrote:

 er, I meant just override -setFileURL: to post a notification.

But that doesn't solve the possibility of some future OS release changing 
fileURL in a non-KVO-compliant manner when another process changes the path of 
this document.  Not likely, I realize.

But anyhow, I realized later that I also need to watch the *contents* of this 
file (like BBEdit automatically reloads when a file on disk changes), so I'm 
dusting off my kqueue code anyhow.

Thanks for the ideas, all.


___

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

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


-[NSDocument fileURL] is observable (KVO). Documented?

2010-06-01 Thread Jerry Krinock
There is no mention in -[NSDocument fileURL] documentation, nor in 10.5 or 10.6 
release notes, that this property is observable using KVO.  But when I added 
some code to do this, created a document, and renamed the document in Finder 
while the document was open, my observer logged a hit.

Is there some underlying or other documentation I don't know about?

Jerry Krinock


- (void)observeValueForKeyPath:(NSString*)keyPath
  ofObject:(id)object
change:(NSDictionary*)change
   context:(void*)context {
NSLog(@2796: keyPath %@ observed:\n%@, keyPath, change) ;
}

- (id)init {
self = [super init] ;
if (self != nil) {
[self addObserver:self
   forKeyPath:@fileURL
  options:NSKeyValueObservingOptionNew
  context:NULL] ;
}

return self ;
}

- (void)dealloc {
[self removeObserver:self
  forKeyPath:@fileURL] ;

...;
[super dealloc];
}


___

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

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


Re: -[NSDocument fileURL] is observable (KVO). Documented?

2010-06-01 Thread Mike Abdullah
By default Cocoa classes use automatic KVO. So long as Cocoa always changes the 
URL by calling -setFileURL: you will get proper notifications.

On 1 Jun 2010, at 22:02, Jerry Krinock wrote:

 There is no mention in -[NSDocument fileURL] documentation, nor in 10.5 or 
 10.6 release notes, that this property is observable using KVO.  But when I 
 added some code to do this, created a document, and renamed the document in 
 Finder while the document was open, my observer logged a hit.
 
 Is there some underlying or other documentation I don't know about?
 
 Jerry Krinock
 
 
 - (void)observeValueForKeyPath:(NSString*)keyPath
  ofObject:(id)object
change:(NSDictionary*)change
   context:(void*)context {
NSLog(@2796: keyPath %@ observed:\n%@, keyPath, change) ;
 }
 
 - (id)init {
self = [super init] ;
if (self != nil) {
[self addObserver:self
   forKeyPath:@fileURL
  options:NSKeyValueObservingOptionNew
  context:NULL] ;
}
 
return self ;
 }
 
 - (void)dealloc {
[self removeObserver:self
  forKeyPath:@fileURL] ;
 
...;
[super dealloc];
 }
 
 
 ___
 
 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:
 http://lists.apple.com/mailman/options/cocoa-dev/cocoadev%40mikeabdullah.net
 
 This email sent to cocoa...@mikeabdullah.net

___

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

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


Re: -[NSDocument fileURL] is observable (KVO). Documented?

2010-06-01 Thread Kyle Sluder
On Tue, Jun 1, 2010 at 2:15 PM, Mike Abdullah cocoa...@mikeabdullah.net wrote:
 By default Cocoa classes use automatic KVO. So long as Cocoa always changes 
 the URL by calling -setFileURL: you will get proper notifications.

This is certainly not the case for a great deal of Cocoa classes,
particularly those which wrap Core Foundation types (NSPrintInfo,
anyone?).

The official word is if it's not explicitly documented as
KVO-compliant, don't treat it as such.

--Kyle Sluder
___

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

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


Re: -[NSDocument fileURL] is observable (KVO). Documented?

2010-06-01 Thread Kyle Sluder
To clarify: Mike is of course correct that any class that doesn't have
an override of +automaticallyNotifiesObserversForKey: which returns no
for a given key, and that always sets values of that key in a
KVC-compliant manner, will generate KVO notifications for that key.
And there are many Cocoa classes that have not bothered to override
+automaticallyNotifiesObservesrForKey:. But one should *not* develop
the expectation that most, or even a substantial portion, of Cocoa is
KVO-compliant, because it is not.

--Kyle Sluder

On Tue, Jun 1, 2010 at 2:15 PM, Mike Abdullah cocoa...@mikeabdullah.net wrote:
 By default Cocoa classes use automatic KVO. So long as Cocoa always changes 
 the URL by calling -setFileURL: you will get proper notifications.

 On 1 Jun 2010, at 22:02, Jerry Krinock wrote:

 There is no mention in -[NSDocument fileURL] documentation, nor in 10.5 or 
 10.6 release notes, that this property is observable using KVO.  But when I 
 added some code to do this, created a document, and renamed the document in 
 Finder while the document was open, my observer logged a hit.

 Is there some underlying or other documentation I don't know about?

 Jerry Krinock


 - (void)observeValueForKeyPath:(NSString*)keyPath
                      ofObject:(id)object
                        change:(NSDictionary*)change
                       context:(void*)context {
    NSLog(@2796: keyPath %@ observed:\n%@, keyPath, change) ;
 }

 - (id)init {
    self = [super init] ;
    if (self != nil) {
        [self addObserver:self
               forKeyPath:@fileURL
                  options:NSKeyValueObservingOptionNew
                  context:NULL] ;
    }

    return self ;
 }

 - (void)dealloc {
    [self removeObserver:self
              forKeyPath:@fileURL] ;

    ...;
    [super dealloc];
 }


 ___

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

 This email sent to cocoa...@mikeabdullah.net

 ___

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

 This email sent to kyle.slu...@gmail.com

___

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

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


Re: -[NSDocument fileURL] is observable (KVO). Documented?

2010-06-01 Thread Mike Abdullah
Precisely my point, but much better put!

In this specific case I think you should be OK since -setFileURL: is there for 
overriding, and AppKit bypassing it would rather miss that goal. Theoretically 
though, Apple could fairly happily turn off KVO-support, perhaps for 
performance reasons.

I'd advise subclassing to add your own notification posting code.

On 1 Jun 2010, at 22:35, Kyle Sluder wrote:

 To clarify: Mike is of course correct that any class that doesn't have
 an override of +automaticallyNotifiesObserversForKey: which returns no
 for a given key, and that always sets values of that key in a
 KVC-compliant manner, will generate KVO notifications for that key.
 And there are many Cocoa classes that have not bothered to override
 +automaticallyNotifiesObservesrForKey:. But one should *not* develop
 the expectation that most, or even a substantial portion, of Cocoa is
 KVO-compliant, because it is not.
 
 --Kyle Sluder
 
 On Tue, Jun 1, 2010 at 2:15 PM, Mike Abdullah cocoa...@mikeabdullah.net 
 wrote:
 By default Cocoa classes use automatic KVO. So long as Cocoa always changes 
 the URL by calling -setFileURL: you will get proper notifications.
 
 On 1 Jun 2010, at 22:02, Jerry Krinock wrote:
 
 There is no mention in -[NSDocument fileURL] documentation, nor in 10.5 or 
 10.6 release notes, that this property is observable using KVO.  But when I 
 added some code to do this, created a document, and renamed the document in 
 Finder while the document was open, my observer logged a hit.
 
 Is there some underlying or other documentation I don't know about?
 
 Jerry Krinock
 
 
 - (void)observeValueForKeyPath:(NSString*)keyPath
  ofObject:(id)object
change:(NSDictionary*)change
   context:(void*)context {
NSLog(@2796: keyPath %@ observed:\n%@, keyPath, change) ;
 }
 
 - (id)init {
self = [super init] ;
if (self != nil) {
[self addObserver:self
   forKeyPath:@fileURL
  options:NSKeyValueObservingOptionNew
  context:NULL] ;
}
 
return self ;
 }
 
 - (void)dealloc {
[self removeObserver:self
  forKeyPath:@fileURL] ;
 
...;
[super dealloc];
 }
 
 
 ___
 
 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:
 http://lists.apple.com/mailman/options/cocoa-dev/cocoadev%40mikeabdullah.net
 
 This email sent to cocoa...@mikeabdullah.net
 
 ___
 
 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:
 http://lists.apple.com/mailman/options/cocoa-dev/kyle.sluder%40gmail.com
 
 This email sent to kyle.slu...@gmail.com
 

___

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

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


Re: -[NSDocument fileURL] is observable (KVO). Documented?

2010-06-01 Thread Jerry Krinock

On 2010 Jun 01, at 15:07, Mike Abdullah wrote:

 I'd advise subclassing to add your own notification posting code.

Yuck.  Unless someone knows a better way, that means setting up either a kqueue 
or FSEvents thingy for the document to watch its own path.  Does anyone know an 
easier way?  Because of the way that a document window's title changes 
instantly when its file is moved in Finder, apparently Apple has this already 
built in to NSDocument.  Does anyone know how to hook into that, ahead of 
setFileURL:?

___

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

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


Re: -[NSDocument fileURL] is observable (KVO). Documented?

2010-06-01 Thread Quincey Morris
On Jun 1, 2010, at 15:25, Jerry Krinock wrote:

 Yuck.  Unless someone knows a better way, that means setting up either a 
 kqueue or FSEvents thingy for the document to watch its own path.  Does 
 anyone know an easier way?  Because of the way that a document window's title 
 changes instantly when its file is moved in Finder, apparently Apple has this 
 already built in to NSDocument.  Does anyone know how to hook into that, 
 ahead of setFileURL:?

A bit of lateral thinking:

Take a look at -[NSWindowController windowTitleForDocumentDisplayName:]. 
However the document chooses to manage its URL, it seems likely that this 
method is going to be called whenever it does change. You could use this 
invocation as a signal that your code should go check the URL.


___

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

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


Re: -[NSDocument fileURL] is observable (KVO). Documented?

2010-06-01 Thread Scott Anguish
Kyle gave the long answer.

But, if it isn’t documented, don’t count on it (although there is some backfill 
required there).

Also, being KVO compliant doesn’t necessarily mean you can simply bind to it, 
as you can’t be sure that the result will be returned on the main thread.

KVO compliance documentation is in place where it is known (typically in new 
classes) and will be updated in older classes as possible/info is available.


On Jun 1, 2010, at 5:15 PM, Mike Abdullah wrote:

 By default Cocoa classes use automatic KVO. So long as Cocoa always changes 
 the URL by calling -setFileURL: you will get proper notifications.
 
 On 1 Jun 2010, at 22:02, Jerry Krinock wrote:
 
 There is no mention in -[NSDocument fileURL] documentation, nor in 10.5 or 
 10.6 release notes, that this property is observable using KVO.  But when I 
 added some code to do this, created a document, and renamed the document in 
 Finder while the document was open, my observer logged a hit.
 
 Is there some underlying or other documentation I don't know about?
 
 Jerry Krinock
 
 
 - (void)observeValueForKeyPath:(NSString*)keyPath
 ofObject:(id)object
   change:(NSDictionary*)change
  context:(void*)context {
   NSLog(@2796: keyPath %@ observed:\n%@, keyPath, change) ;
 }
 
 - (id)init {
   self = [super init] ;
   if (self != nil) {
   [self addObserver:self
  forKeyPath:@fileURL
 options:NSKeyValueObservingOptionNew
 context:NULL] ;
   }
 
   return self ;
 }
 
 - (void)dealloc {
   [self removeObserver:self
 forKeyPath:@fileURL] ;
 
   ...;
   [super dealloc];
 }
 
 
 ___
 
 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:
 http://lists.apple.com/mailman/options/cocoa-dev/cocoadev%40mikeabdullah.net
 
 This email sent to cocoa...@mikeabdullah.net
 
 ___
 
 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:
 http://lists.apple.com/mailman/options/cocoa-dev/scott%40cocoadoc.com
 
 This email sent to sc...@cocoadoc.com

___

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

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