Re: NSSavePanel mishandling extensions
Re: NSSavePanel mishandling extensions
- Subject: Re: NSSavePanel mishandling extensions
- From: Corbin Dunn <email@hidden>
- Date: Wed, 03 Dec 2008 13:10:07 -0800
Have you tried:
[savePanel setRequiredFileType:@"txt"];
[savePanel setAllowsOtherFileTypes:YES];
This is what TextEdit does. Does TextEdit work in a way similar to
what you want to do?
-corbin
Le Dec 3, 2008 à 12:58 PM, Russ a écrit :
I have a NSSavePanel set up for the user to select a file name to
store a file. The user can store it in several different formats. I
have a NSPopUpButton configured to allow the user to select the
desired format; upon a change, it calls the setRequiredFileType
function with that single file type.
But the panel does not seem to pay attention to any of this, it
never displays or returns a file name with a file extension. The
state of the Show extension checkbox does not matter. I've checked
that the popup delegate is getting called and setting the required
filetype to the string with no dot.
I would implement a bit of the desired functionality myself, but
NSSavePanel's -filename function is labeled such that it should only
be called after the dialog has completed, and there appears to be no
way to change the filename once the panel has started (ie to show
the correct extension).
How is NSSavePanel supposed to work? I could try groping around in
the panel to locate the NSTextView or NSTextField for the file name,
but that is crass and prone to problems later if not sooner.
Do I HAVE to implement the delegate methods (isValidFilename?) to
check the file extension for it if I supply an accessory view? In a
spot where there is only a single valid file type, my code doesn't
do the setAccessoryView and then the extension is showing up OK.
It's using the same file extension array in both cases. The only
change as far as the panel is concerned is whether or not an
accessory view is set --- the behavior changes even if I don't
change the popup button. There are no calls sent to the
NSSavePanel -- the behavior has changed just based on the presence
of the accessory view. (A bunch of calls get made to the popup
button, but that doesn't do anything to the save panel---it only
does the setRequiredFileType when the user changes the popup.)
If all else fails, I guess I'll have to prevent the panel from
showing the Show Extensions box (never an extension visible), and
tack on the correct extension manually upon completion. But that
will mess up the existing-file checks I'd guess, so I'll have to
waste some more time to replicate that too. It does not check a user-
supplied extension against the specified one either. And the cocoa
version will have to be less functional than the carbon version.
_______________________________________________
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