• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Validate before save in Doc Style App?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Validate before save in Doc Style App? (From: Todd Freese <email@hidden>)

  • Prev by Date: Re: Alert sheet question
  • Next by Date: Re: Prevent default alert when quitting app w/ many unsaved docs
  • Previous by thread: Validate before save in Doc Style App?
  • Next by thread: one document at a time
  • Index(es):
    • Date
    • Thread