New document creation

  • My goal is to have my application present a dialog before allowing the user
    to create a new document.  I have it working almost fine by setting up an
    application delegate and using applicationShouldOpenUntitledFile...it
    returns YES or NO depending on whether my dialog gets the right answer.

    That, much to my surprise, doesn't handle the case where the user chooses
    "New" from the file menu.  (Since it's the same semantic action, why
    wouldn't the same method get a vote?)  Using the debugger, I find that the
    point where these functions converge is [NSDocumentController newDocument],
    so this sounds like a reasonable place to intervene.  The documentation
    however recommends both for and against subclassing NSDocumentController,
    leaving me wondering what's best.

    Is there some kind document controller delegate to handle a
    "controllerShouldCreateNewDocument" kind of invocation?

    If I do create a sub-class of NSDocumentController, how to I get the
    application to use it instead of the defalult?

    Is it better to ignore this, move down the call chain, and have "MyDocument"
    do the checking and turn showWindows into a no-op ([self close]) if
    necessary?
  • *This message was transferred with a trial version of CommuniGate(tm) Pro*
    Here's what I suggest..

    Connect the "New" menu item to a method on your application controller
    class... that method presents whatever UI you want to appear and once
    the user completes the UI and clicks ok you then call
    [[NSDocumentController sharedDocumentController]
    openUntitledDocumentOfType...]

    No need to subclass NSDocumentController and by using the above
    technique it's easy to  make the "new document" panel non-modal.

    - Chris

    On Tuesday, January 23, 2001, at 05:27  PM, Phillip Mills wrote:

    > *This message was transferred with a trial version of CommuniGate(tm)
    > Pro*
    > My goal is to have my application present a dialog before allowing the
    > user
    > to create a new document.  I have it working almost fine by setting up
    > an
    > application delegate and using applicationShouldOpenUntitledFile...it
    > returns YES or NO depending on whether my dialog gets the right answer.
    >
    > That, much to my surprise, doesn't handle the case where the user
    > chooses
    > "New" from the file menu.  (Since it's the same semantic action, why
    > wouldn't the same method get a vote?)  Using the debugger, I find that
    > the
    > point where these functions converge is [NSDocumentController
    > newDocument],
    > so this sounds like a reasonable place to intervene.  The documentation
    > however recommends both for and against subclassing
    > NSDocumentController,
    > leaving me wondering what's best.
    >
    > Is there some kind document controller delegate to handle a
    > "controllerShouldCreateNewDocument" kind of invocation?
    >
    > If I do create a sub-class of NSDocumentController, how to I get the
    > application to use it instead of the defalult?
    >
    > Is it better to ignore this, move down the call chain, and have
    > "MyDocument"
    > do the checking and turn showWindows into a no-op ([self close]) if
    > necessary?
    > _______________________________________________
    > MacOSX-dev mailing list
    > <MacOSX-dev...>
    > http://www.omnigroup.com/mailman/listinfo/macosx-dev