Earliest moment to attach a sheet to a document window?

  • I have been trying to put up a warning sheet on an NSDocument window
    at the earliest stage after opening the document and displaying its
    window.

    The call I use (in the end) is:

    [NSApp beginSheet:choiceSheet modalForWindow:[__windowController
    window] modalDelegate:self didEndSelector:nil
    contextInfo:__currentSheetDictionary];

    The sheet itself is loaded from a NIb file and the close button is
    connected to file's owner and sends the endPanel: method.

    But whatever I do and wherever I try to start the sheet, it gets
    displayed before the window is displayed and it free-floats after
    which the window is displayed.

    The close button *does* work end ends in the File's owner in the
    endPanel: method, where my code says:

        // The sender is the button that resides in the sheet, hence
    [sender window] is the sheet itself.
        [NSApp endSheet: [sender window]];
        [[sender window] orderOut: self];

    Which normally works but now does not work as well. The sheet remains
    in sight and I can keep pressing the button ending up in my endPanel:
    method of the nib's owner.

    So, I was wondering, what is the moment that NSApp beginSheet: starts
    working properly in an NSDocument/NSWindowController setup?

    I tried the end of windowControllerDidLoadNib and
    makeWindowControllers (in the document class) and the end of
    windowDidLoad of the window controller class but all these methods
    failed.

    G
  • On 29 okt 2006, at 19.15, Gerben Wierda wrote:

    > I have been trying to put up a warning sheet on an NSDocument
    > window at the earliest stage after opening the document and
    > displaying its window.
    >
    > The call I use (in the end) is:
    >
    > [NSApp beginSheet:choiceSheet modalForWindow:[__windowController
    > window] modalDelegate:self didEndSelector:nil
    > contextInfo:__currentSheetDictionary];
    >
    > The sheet itself is loaded from a NIb file and the close button is
    > connected to file's owner and sends the endPanel: method.
    >
    > But whatever I do and wherever I try to start the sheet, it gets
    > displayed before the window is displayed and it free-floats after
    > which the window is displayed.

    I think that your problem is that while the document window is loaded
    at that time, it's not on screen.
    How about something like this:

    - (void) showWindows
    {
    [super showWindows];

    // Show your sheet here
    }

    j o a r
  • On 29 Oct 2006, at 20:01 , j o a r wrote:

    >
    > On 29 okt 2006, at 19.15, Gerben Wierda wrote:
    >
    >> I have been trying to put up a warning sheet on an NSDocument
    >> window at the earliest stage after opening the document and
    >> displaying its window.
    >>
    >> The call I use (in the end) is:
    >>
    >> [NSApp beginSheet:choiceSheet modalForWindow:[__windowController
    >> window] modalDelegate:self didEndSelector:nil
    >> contextInfo:__currentSheetDictionary];
    >>
    >> The sheet itself is loaded from a NIb file and the close button is
    >> connected to file's owner and sends the endPanel: method.
    >>
    >> But whatever I do and wherever I try to start the sheet, it gets
    >> displayed before the window is displayed and it free-floats after
    >> which the window is displayed.
    >
    > I think that your problem is that while the document window is
    > loaded at that time, it's not on screen.
    > How about something like this:
    >
    > - (void) showWindows
    > {
    > [super showWindows];
    >
    > // Show your sheet here
    > }

    That is better than my solution: calling showWindows from my document
    class (because it will get called twice that way).

    showWindows does not have much documentation. Is this only called at
    the beginning or also at other moments. I'll find out soon enough, I
    guess.

    Thanks,

    G
  • See <http://www.stepwise.com/Articles/2006/eb1/index.html> for an
    ultra simple example that does what you want.

    In particular:
    Add the following code to the -windowControllerDidLoadNib: method:

    [self performSelector:@selector(showCustomSheet:) withObject:
    [aController window] afterDelay:0.0f];
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today