Menu synchronization

  • I'm working on a multi-document application where one of the
    menus (a submenu) is changed as things (lens images in this case) are
    added to the document. With more than one documents open, I would
    like the menu to correspond to the top or key document window. There
    must be a standard or accepted way to manage this.

          I finally figured out a kludge that works using the notification
    NSWindowDidBecomeKeyNotification but, since the notification goes to
    all instances of the Document (one for each open window), I had to
    make sure that the window in question corresponded to its proper
    Document.

          Could someone point me to some sample code or documentation that
    shows the proper way to handle this.

        Thanks, Jim
  • On 29 Oct 2006, at 21:33, James Pengra wrote:

    > I'm working on a multi-document application where one of the
    > menus (a submenu) is changed as things (lens images in this case)
    > are added to the document. With more than one documents open, I
    > would like the menu to correspond to the top or key document
    > window. There must be a standard or accepted way to manage this.

    In my app I make sure the affected menus are correct when the
    document's validateMenuItem is called. This way you'll always get the
    menu that is appropriate for the active document. Something like this:

    - (BOOL) validateMenuItem: (NSMenuItem *) item {
    [self updateViewMenu];

    // menu validation code
    }

    As long as the updating code executes fast enough this should be
    allright. Most menus are not long enough to generate a noticeable lag
    here.

    HTH,
    António

    -----------------------------------------------------------
    Don't believe everything you think
    -----------------------------------------------------------
  • If you register your document for the windowDidBecomeKeyNotification
    there is the parameter "object:". If you pass nil here, the
    notification will be passed to all documents whenever a window
    becomes key. If you pass for every document [[[self
    windowControllers] objectAtIndex:0] window] the notification will
    only be sent to a document when its own window becomes key.

    Cheers, Patrick

    On 29-Oct-06, at 16:33 PM, James Pengra wrote:

    > I'm working on a multi-document application where one of the
    > menus (a submenu) is changed as things (lens images in this case)
    > are added to the document. With more than one documents open, I
    > would like the menu to correspond to the top or key document
    > window. There must be a standard or accepted way to manage this.
    >
    > I finally figured out a kludge that works using the
    > notification NSWindowDidBecomeKeyNotification but, since the
    > notification goes to all instances of the Document (one for each
    > open window), I had to make sure that the window in question
    > corresponded to its proper Document.
    >
    > Could someone point me to some sample code or documentation
    > that shows the proper way to handle this.
    >
    > Thanks, Jim
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/meirmans%
    > 40sympatico.ca
    >
    > This email sent to <meirmans...>
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