• 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: "Can't create new document" alert unwanted
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "Can't create new document" alert unwanted


  • Subject: Re: "Can't create new document" alert unwanted
  • From: "Louis C. Sacha" <email@hidden>
  • Date: Thu, 23 Dec 2004 15:40:58 -0800

Hello...

As far as I know, there is no simple way to change this behavior (or the error dialog that occurs when you return nil from your document's initialization when opening an existing document).


First, you might want to reconsider asking the user for this information in the init method. The init method is called for every instance of your document, and there isn't really a reliable way (from within init) to determine if the document will represent a new document that is being created or an existing document that is being opened. Generally, your init method should only contain the basic setup of every document instance, and shouldn't really include any interaction with the user.


Instead, if you can, you might want to implement your document class so that you can leave that information empty until the document has been fully created and loaded, and then put up a sheet when the document's window(s) are displayed that asks the user for the details in cases (like a new document) where the information has not already been provided (or loaded from an existing document that has been opened).


If you still find that you need to disable the standard alert, you could subclass NSDocumentController and override the methods which are responsible for raising the dialogs. If I remember correctly, it is actually the menu action methods newDocument: and openDocument: that raise these alerts. You would need to provide your own implementation of these methods or whichever methods raise the alert (although you would basically just be calling other existing methods to do the work). You would need to set up your application to use your subclass for the application's shared instance .<http://developer.apple.com/documentation/Cocoa/Conceptual/Documents/Tasks/SubclassController.html>



Another way to bypass the default alert is to return some sort of proxy object instead of returning nil. To create this "null document" class, you could start with a subclass of NSDocument, and override the showWindows method to close the document.


- (void)showWindows
// overrides standard version to close document when the document controller attempts to display it
{
[self close];
}


You might also want to implement some sort of timer that closes the document after a certain amount of time if it is not displayed, to handle the case where a document is opened without actually being displayed to the user (for example in 10.2? or earlier, when a document could be opened and printed without actually displaying the document to the user).

You would then return an instance of this "null document" class instead returning nil. Using this way to avoid the extra alert can have some side effects, for example documents that fail to open might still be added to the recent documents list.


Hope that helps,

	Louis



Dear all,

In a newly created Cocoa project I have added code to the
-(id)init method of MyDocument. It is suggested there that I
should

  // Add your subclass-specific initialization here.
  // If an error occurs here, send a [self release] message
  // and return nil.

So I did. I ask the user some details, and if she aborts,
I return nil. Then however, an alert appears saying

   NEW
   Can't create new document.

Clearly, when the user aborts, there is no need to show
such a beast anymore. How can I get rid of it?

Thanks a lot,
Kaspar

P.S. This question has been asked before, see

  http://lists.apple.com/archives/cocoa-dev/2002/Dec/msg00294.html

but nobody seems to have answered.

_______________________________________________
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: 
 >"Can't create new document" alert unwanted (From: Kaspar Fischer <email@hidden>)

  • Prev by Date: NSData writeToFile
  • Next by Date: Is drawRect really where setShowsFirstResponder should be called?
  • Previous by thread: "Can't create new document" alert unwanted
  • Next by thread: Trouble with mouseMoved and custom views
  • Index(es):
    • Date
    • Thread