FwUp: Customizing NSSavePanel behavior - solution(?)
FwUp: Customizing NSSavePanel behavior - solution(?)
- Subject: FwUp: Customizing NSSavePanel behavior - solution(?)
- From: Andrea Perego <email@hidden>
- Date: Wed, 16 Oct 2002 14:02:59 +0200
At 1:46 PM +0200 10/16/02, Andrea Perego wrote:
>
Hi all!
>
The application I'm developing receives chunks of data (nuclear
>
spectra) from an acquisition system. Saving a spectrum implies
>
creating a new document/file or *appending* it to an existing
>
document.
>
NSSavePanel would be perfectly adequate for this purpose but for the
>
fact that, whenever the user chooses an existing file, it shows an
>
alert panel asking permission to *replace* the file.
>
The jurassic pre-OS X toolbox allowed to customize this behavior
>
with ease, since the programmer could provide her/his replacement
>
resource for the aforementioned panel; a look into the AppKit
>
framework brought me to the conclusion that NSSavePanel issues a
>
NSRunAlertPanel() call passing localizable strings for the message
>
("%@ already exists. Do you want to replace it?") and the button
>
titles.
>
I haven't been able to conceive any simple way to override this
>
behavior so far, and having to develop a substitute panel from
>
scratch just to change a couple of words is not something that makes
>
one rejoice...
>
If some of you faced this or a similar problem already, I'd
>
appreciate any hint, suggestion, etc. on the subject.
By playing a little with NSSavePanel delegate methods, I've found a
simple solution, but it's such a dirty hack that I'm almost ashamed
to report it here:
the delegate method
- (NSString *)panel:(id)sender userEnteredFilename:(NSString
*)filename confirmed:(BOOL)okFlag
is called after the user has pressed the save button. The delegate
can modify the filename by returning a different one: if it's a
"dummy" filename, corresponding to a non-existing file, NSSavePanel
will not put on the "...replace it?" dialog.
Of course, the chosen filename must be taken from the delegate method
and not by
sending [savePanel filename] afterwards!
Another example, if not the nicest one, of the power of delegation mechanism!
Andrea Perego
University of Florence - Phys. Dept.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.