Re: Updating the trash icon without NSWorkspace
Re: Updating the trash icon without NSWorkspace
- Subject: Re: Updating the trash icon without NSWorkspace
- From: Jean-Daniel Dupas <email@hidden>
- Date: Mon, 4 Feb 2008 12:14:14 +0100
Or even better, if your software requires Mac OS X.5, you can use the
new FSMoveObjectToTrashSync() or FSPathMoveObjectToTrashSync()
functions (it's not an obj-c API, but it does what you want).
NSString *moveToTrash(NSString *file) {
char *outPath = NULL;
NSString *newPath = nil;
OSStatus err = FSPathMoveObjectToTrashSync([file
fileSystemRepresentation], &outpath, kFSFileOperationDefaultOptions);
if (noErr == err) {
newPath = [(NSString
*)CFStringCreateWithFileSystemRepresentation(NULL, outPath)
autorelease];
free(outPath);
}
return newPath;
}
(coded in Mail and not tested).
Le 4 févr. 08 à 11:57, Mike Abdullah a écrit :
I'm not sure this is the best approach, but you could continue to
use NSWorkspace and a combination of Aliases of FSRef:
1. Create an FSRef to the file. (or an Alias, but I think for your
case an FSRef is better)
2. Use NSWorkspace to move it to the trash.
At undo-time, FSRef should be able to locate the file within the
trash regardless of its new filename and you can then move it back
out.
Mike.
On 4 Feb 2008, at 10:04, Lachlan Cotter wrote:
Hi Cocoabuilders,
I know there have been similar threads on here before, but they
don't address my particular issue.
I'm using NSFileManager methods to move files into the trash. As
has been mentioned by others, this doesn't update the trash icon in
the doc.
I know I could use the NSWorkspace method performFileOperation… but
the catch is I want to be able to undo the move, which means I
would need to know the path to which the file was moved. However
NSWorkspace may rename the file to prevent collisions. If this is
the case, I wont have any way to find the new path to the file
(other than guessing).
There are probably tricks that could be used to get this to work,
but I wonder if there isn't a simple notification that can be
raised to cause the trash icon to update?
In any case, I would also need to update it when taking files out
of the trash, in which case NSWorkspace is no help.
Who manages this icon? Is it the Finder? or the Doc? Is there an
API that can help here?
Thanks for your help.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden