Re: Can I set "no extension" as a document file type? [solved]
Re: Can I set "no extension" as a document file type? [solved]
- Subject: Re: Can I set "no extension" as a document file type? [solved]
- From: Jerry Krinock <email@hidden>
- Date: Wed, 27 Sep 2006 16:12:30 -0700
- Thread-topic: Can I set "no extension" as a document file type? [solved]
on 06/09/27 13:49, Stephen Deken at email@hidden wrote:
>> Anyone know a way to enable ONLY files with NO extension?
>
> Assign the open panel a delegate. Add the method
> -[panel:shouldShowFilename:] to the delegate, and look for a period in
> the filename. If it has one, return NO. Otherwise, return YES.
>
> This will not associate the document with your application in the
> Finder, but I assume that's beyond the scope of what you're trying to
> accomplish.
That's correct, and your answer works. The documentation for
panel:shouldShowFilename: confirms that this is indeed its intended use.
Looking at how redundant is the code I implemented, I'd say: The fact that
NSOpenPanel interprets an extension of "" to mean "any file" is a bug, and
the code below is the workaround.
Thanks, Stephen.
Jerry
I presume that my NSDocumentController may create a new NSOpenPanel whenever
the user clicks "Open", so I put this code in my over-ride of
NSDocumentController and made itself the delegate...
// If, in order to enable opening of files which have
// no file extension, HFS Creator Code and no HFS Type code,
// I put the empty string "" as the extension of an allowed
// Document Type in Target > Properties, then ANY file
// regardless of extension, is enabled in the Open panel.
// The following override, and the next delegate method,
// are to work around this and DISable all files
// except those which have one of the extensions which we allow.
// Note that the NSArray extensions is saved as an instance
// variable. I tried using -[NSOpenPanel allowedFileTypes]
// in both methods (sending to openPanel and sender,
// respectively, but I always got nil returned. Oh, well.
- (int)runModalOpenPanel:(NSOpenPanel *)openPanel
forTypes:(NSArray *)extensions {
[openPanel setDelegate:self] ;
[self setAllowedExtensions:extensions] ;
return [super runModalOpenPanel:openPanel forTypes:extensions] ;
}
// Delegate methods:
- (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename {
NSString* extension = [filename pathExtension] ;
return [[self allowedExtensions] containsObject:extension] ;
}
_______________________________________________
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