Extra call to validateMenuItem before triggering action; new in Leopard?

  • I'm seeing new behavior in my app under Leopard that's breaking things and
    forcing me to work around it; is this intended?  (Or old behavior I was
    sometimes missing?)
    I have a menu associated with the header of an outline view, and I use
    validateMenuItem to enable commands based on the column that was
    right-clicked on to bring up the menu; therefore, the validation involves
    using the mouse location to determine which column was under the cursor when
    the mouseDown occurred.

    The behavior that I'm seeing now is that validate... is called on the
    initial mouseDown, and I correctly enable the items as I had done before.
    But now I'm seeing a second call to validateMenuItem on the selection of
    the menu item, and my problem is that the mouse location (of the selected
    menu item) is no longer within the header view or any of its columns, do my
    validate... method returns NO, and the action is never triggered.

    My planned workaround is to add a state to the menu item (via its
    representedObject) to indicate that it has been validated, and use that to
    return YES on the second invocation.  (My action handler will clear the
    state.)

    But if the 2nd call to validateMenuItem prior to the action is new and
    intended behavior in Leopard, I'd like to know what the purpose is so I can
    code appropriately.

    TIA,

    Doug Knowles
  • On Dec 9, 2007, at 8:06 AM, Doug Knowles wrote:

    >
    >
    > But if the 2nd call to validateMenuItem prior to the action is new and
    > intended behavior in Leopard, I'd like to know what the purpose is
    > so I can
    > code appropriately.

    Hi Doug,

    The second validate is to allow programmatic calls to
    performActionForItemAtIndex: to work correctly with auto-validation.
    It should not be invoked in the case you are seeing, but apparently
    it is.

    Have you considered using the clickedColumn method of NSTableView to
    avoid having to do your own mouse tracking?

    -Peter
  • On Dec 10, 2007 10:56 PM, Peter Ammon <pammon...> wrote:

    > Have you considered using the clickedColumn method of NSTableView to
    > avoid having to do your own mouse tracking?

    No, because I completely missed its existence!  :-}  Soon to be corrected.

    Thanks!

    Doug K;
previous month december 2007 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