Re: When am I no longer the pasteboard owner?
Re: When am I no longer the pasteboard owner?
- Subject: Re: When am I no longer the pasteboard owner?
- From: Jim Correia <email@hidden>
- Date: Wed, 10 May 2006 20:49:21 -0400
On May 10, 2006, at 8:37 PM, John C. Randolph wrote:
The owner of the pasteboard has to exist as long as there's a
possibility of something asking for the pasteboard contents. You
can't count on -pasteboard:provideDataForType: only being sent once.
I realize that. (Presumably once it has asked for a given type, it
won't ask for that same type again, but there is nothing in the
documentation that guarantees.)
What I am asking is how do I determine that I will never be sent a
message again, so the pasteboard owner can release whatever rich data
it may have cached in order to provided the other types? [1]
It appears that -pasteboardChangedOwner: is only sent when the owner
hasn't already provided all of the types it has declared. If it has
provided all of the types, or if the pasteboard is released (see
example below using a transient pasteboard) without anyone ever
requesting the types, the message isn't set.
@implementation ApplicationController
- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
NSPasteboard *pboard = [NSPasteboard pasteboardWithUniqueName];
[pboard declareTypes: [NSArray arrayWithObject: NSStringPboardType]
owner: self];
[pboard releaseGlobally];
}
- (void)pasteboard:(NSPasteboard *)sender provideDataForType:
(NSString *)type
{
NSLog(@"%s", __PRETTY_FUNCTION__);
}
- (void)pasteboardChangedOwner:(NSPasteboard *)sender
{
NSLog(@"%s", __PRETTY_FUNCTION__);
}
@end
[1] In this particular case I'm putting the URI representation of
NSManagedObjectIDs on the pasteboard so I can avoid pre-calculating
all the possible representations.
In order to provide the data when sent -
pasteboard:provideDataForType: I also need a managed object context
(preferably the same one which was used to "write" the data so we get
the unsaved changes from that context.) My global pasteboard provider
needs to know which MOC to use, and when it is safe to release that
MOC because it won't be asked to provide that data ever again.
Is NSPasteboard set up to handle this situation (where auxiliary data
is needed to do the conversion?) If so, how? It is clear that I can
put a TIFF on the pasteboard and declare a bunch of other image
formats and set the owner to some object which will read the TIFF and
generate a JPEG. But if that object also needs an additional piece of
information to do the conversion, how does it know for how long to
retain the information? Forever really isn't acceptable :-)
Thanks,
Jim
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden