Re: NSOpenPanel & NSFileTypeForHFSTypeCode
Re: NSOpenPanel & NSFileTypeForHFSTypeCode
- Subject: Re: NSOpenPanel & NSFileTypeForHFSTypeCode
- From: Chris Heimark <email@hidden>
- Date: Wed, 10 Oct 2007 21:27:21 -0400
I have come close to the desired outcome by setting Panel as follows:
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
[openPanel setTitle:@"Choose Flash Drive Volume"];
[openPanel setMessage:[NSString stringWithFormat:@"Choose target
flash drive..."]];
[openPanel setPrompt:@"Choose"];
[openPanel setCanCreateDirectories:FALSE];
[openPanel setCanChooseFiles:FALSE];
[openPanel setCanChooseDirectories:TRUE];
[openPanel setExtensionHidden:TRUE];
[openPanel setRequiredFileType:nil];
[openPanel setAllowedFileTypes:nil];
[openPanel setAllowsMultipleSelection:FALSE];
[openPanel setDelegate:self];
Coupled with the following delegate setup
// delegate function for NSOpenPanel
- (BOOL)panel:(id)sender isValidFilename:(NSString *)filename{
if ([filename hasPrefix:@"/Volumes/"])
return TRUE;
else
return FALSE;}
// delegate function for NSOpenPanel
- (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename{
BOOL isDir = TRUE;
NSLog (@"OpenPanel: %@:%@", NSHFSTypeOfFile(filename), filename);
if ([[NSFileManager defaultManager] fileExistsAtPath:filename
isDirectory:&isDir] && !isDir)
return TRUE;
else
return FALSE;}
My NSTask / diskutil functionality will be invoked if a /Volume is
selected and then I'll have a familiar interface to file system for
user. Though things do look wonky with many greyed out directories
showing yet unclickable. Note setCanChooseDirectories:TRUE seems to
be necessary or choose button never goes active. Must be as a result
of mount points being directories of sorts...
On Oct 10, 2007, at 7:16 PM, Corbin Dunn wrote:
It's too bad that NSOpenPanel (unlike Nav Serv) can't filter by UTI.
Then you could use kUTTypeVolume aka "public.volume".
This would be the *ideal* way to do it, but it won't work on Tiger.
Have you logged a bug report requesting this feature? Maybe it will
appear in a future OS release, but please do log bugs so we know
you want things like this. Unless the NSOpenPanel developer happens
to be trolling cocoa-dev, they may miss something like this.
thanks,
--corbin
_______________________________________________
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