0
votes

I have a Cocoa document based picture editing application. As usual, my application has both File -> Save menu and File -> Save As menu.

File -> Save menu is linked to saveDocument: in NSDocument subclass

File -> Save As menu is linked to saveDocumentAs: in NSDocument subclass

In both cases, on a successful save, I want to present a NSAlert sheet to user saying that the save was successful and this sheet also presents the user with an option to upload the document to Facebook etc.

How do I know, that the document got saved succesfully?

I understand that in case of File -> Save As I can create a new action method mySaveDocument: and invoke

saveDocumentWithDelegate:didSaveSelector:contextInfo:

from mySaveDocument: but what should I do for File -> Save As ?

1
How many mainstream Mac OS X applications do you know that pop up a sheet to tell you a file has been successfully saved? Answer: none, and with good reason. It wouldbe better to put your "Do you want to upload to Facebook?" question on the save panel itself and then just do it without any more prompting if the save works. Interrupt the user's workflow only to tell them if something went wrong.JeremyP

1 Answers

1
votes

In your NSDocument subclass, override:

- (BOOL)saveToURL:(NSURL *)absoluteURL
           ofType:(NSString *)typeName
 forSaveOperation:(NSSaveOperationType)saveOperation
            error:(NSError **)outError
{
    BOOL success = [super saveToURL:absoluteURL
                             ofType:typeName
                   forSaveOperation:saveOperation
                              error:outError];

    if (success) {
        …
    }

    return success;
}

This method is called whenever a document is saved.

For more information on what happens when a document is saved, read the Message Flow in the Document Architecture page of the Document-Based Applications Overview document.