Re: Validate before save in Doc Style App?
Re: Validate before save in Doc Style App?
- Subject: Re: Validate before save in Doc Style App?
- From: "Louis C. Sacha" <email@hidden>
- Date: Fri, 17 Dec 2004 15:55:53 -0800
Hello...
There isn't any single method to override or implement that would
allow you to do this, so you would probably want to override the
action methods for the save related menu items in your NSDocument
subclass. The action for the "Save" menu item is saveDocument:, for
"Save As..." it is saveDocumentAs:, and for "Save To..." it is
saveDocumentTo:. You can write a method that does the actual
validation and call that same method from each of the overridden
action methods.
So, for example, your saveDocument: method could look something like
- (void)saveDocument:(id)sender
{
if ([self documentIsValid]) {[super saveDocument:sender];}
else {return;}
}
The saveDocumentAs: and saveDocumentTo: method would follow the same
pattern, calling the validation method and then invoking the super
class implementation if the document passes validation. Then the
validation method would go something like
- (BOOL)documentIsValid
{
BOOL isValid = TRUE;
/* ... do whatever validation you need to do ... */
if (isValid) {return TRUE;}
else
{
/* provide feedback to user regarding why save failed
w/ alert sheet, beep, etc ... */
return FALSE;
}
}
Hope that helps,
Louis
In my doc-style application, I need to validate some things before I
save out to a file. Is there a method I can override that would
allow me to do some validation before the save panel is presented? I
would need to able to cancel the save operation and return to the
document if it fails the validation.
Thanks in advance,
Todd Freese
The Filmworkers Club - Chicago
_______________________________________________
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