NSPopUpButtonCell prevents selection update of NSArrayController

  • I have an NSArrayController that has in the last column an
    NSPopUpButtonCell, for a master-detail scenario.

    I have used bindings to set it all up and it works.

    However, I want to hide some of the MenuItems of the PopUpMenu
    depending on the row I am in. For example, according to the type of
    the object bound to the row, there are different choices in the pop-up
    menu. I can do this using the menu:updateItem:atIndex:shouldCancel:
    method.

    Here is the bug: the selection of the NSArrayController isn't updated
    until *after* the pop-up menu has *closed*. So of course when accesing
    selection from within menu:updateItem:atIndex:shouldCancel:, I get the
    wrong data. If I carefully select the row before summoning the menu,
    everything works fine.

    So, I have three paths:

    a) try to somehow intercept the mouse click and deliver it first to
    the NSArrayController, then the pop-up cell
    b) delay the opening/creation of the pop-up menu until the selection
    is updated
    c) bypass the controller and its bindings altogether and do the menu
    column manually.

    I can't find a straightforward way to do any of the above, so please
    help!

    I am very new to Cocoa, so I may have missed something fundamental.
    Please say so.

    Thank you,
    --
    Orestis Markou
    <orestis...>
    http://orestis.gr/
  • If the objects in your array controller have a property which
    specifies the available menu options (say as an array of strings),
    then you can bind the 'contentValues' of the table column to that
    property directly; i.e. bind it to your table view's array controller
    with controller key 'arrangedObjects' and model key path the name of
    your invented options property...

    Cheers,
    dave

    On 15-Nov-07, at 3:33 PM, Orestis Markou wrote:

    > I have an NSArrayController that has in the last column an
    > NSPopUpButtonCell, for a master-detail scenario.
    >
    > I have used bindings to set it all up and it works.
    >
    > However, I want to hide some of the MenuItems of the PopUpMenu
    > depending on the row I am in. For example, according to the type of
    > the object bound to the row, there are different choices in the pop-
    > up menu. I can do this using the
    > menu:updateItem:atIndex:shouldCancel: method.
    >
    > Here is the bug: the selection of the NSArrayController isn't
    > updated until *after* the pop-up menu has *closed*. So of course
    > when accesing selection from within
    > menu:updateItem:atIndex:shouldCancel:, I get the wrong data. If I
    > carefully select the row before summoning the menu, everything works
    > fine.
    >
    > So, I have three paths:
    >
    > a) try to somehow intercept the mouse click and deliver it first to
    > the NSArrayController, then the pop-up cell
    > b) delay the opening/creation of the pop-up menu until the selection
    > is updated
    > c) bypass the controller and its bindings altogether and do the menu
    > column manually.
    >
    > I can't find a straightforward way to do any of the above, so please
    > help!
    >
    > I am very new to Cocoa, so I may have missed something fundamental.
    > Please say so.
    >
    > Thank you,
    > --
    > Orestis Markou
    > <orestis...>
    > http://orestis.gr/
    >
  • That's a nice approach. I haven't thought of that...

    It's a bit contrived, from an OO point of view, but it will save me a
    lot of trouble.

    Thanks!
    --
    Orestis Markou

    On 16 Î?οε 2007, at 1:57 ΠΜ, David Spooner wrote:

    >
    > If the objects in your array controller have a property which
    > specifies the available menu options (say as an array of strings),
    > then you can bind the 'contentValues' of the table column to that
    > property directly; i.e. bind it to your table view's array
    > controller with controller key 'arrangedObjects' and model key path
    > the name of your invented options property...
    >
    > Cheers,
    > dave
    >
    > On 15-Nov-07, at 3:33 PM, Orestis Markou wrote:
    >
    >> I have an NSArrayController that has in the last column an
    >> NSPopUpButtonCell, for a master-detail scenario.
    >>
    >> I have used bindings to set it all up and it works.
    >>
    >> However, I want to hide some of the MenuItems of the PopUpMenu
    >> depending on the row I am in. For example, according to the type of
    >> the object bound to the row, there are different choices in the pop-
    >> up menu. I can do this using the
    >> menu:updateItem:atIndex:shouldCancel: method.
    >>
    >> Here is the bug: the selection of the NSArrayController isn't
    >> updated until *after* the pop-up menu has *closed*. So of course
    >> when accesing selection from within
    >> menu:updateItem:atIndex:shouldCancel:, I get the wrong data. If I
    >> carefully select the row before summoning the menu, everything
    >> works fine.
    >>
    >> So, I have three paths:
    >>
    >> a) try to somehow intercept the mouse click and deliver it first to
    >> the NSArrayController, then the pop-up cell
    >> b) delay the opening/creation of the pop-up menu until the
    >> selection is updated
    >> c) bypass the controller and its bindings altogether and do the
    >> menu column manually.
    >>
    >> I can't find a straightforward way to do any of the above, so
    >> please help!
    >>
    >> I am very new to Cocoa, so I may have missed something fundamental.
    >> Please say so.
    >>
    >> Thank you,
    >> --
    >> Orestis Markou
    >> <orestis...>
    >> http://orestis.gr/
    >>
    >
  • On 15-Nov-07, at 5:04 PM, Markou Orestis wrote:

    > That's a nice approach. I haven't thought of that...
    >
    > It's a bit contrived, from an OO point of view, but it will save me
    > a lot of trouble.

    I beg to differ.  Yes the menu options are being associated with the
    model objects, seeming mixing interface-level code with the model-
    level.  But the association is quite loose -- the defining methods can
    be added in categories of the model classes in separate files and even
    in separate frameworks entirely.  So there is really no 'pollution' of
    the model at all...

    > Thanks!
    > --
    > Orestis Markou
    >

    You're welcome.

    dave

    >
    >
    >
    >
    > On 16 Î?οε 2007, at 1:57 ΠΜ, David Spooner wrote:
    >
    >>
    >> If the objects in your array controller have a property which
    >> specifies the available menu options (say as an array of strings),
    >> then you can bind the 'contentValues' of the table column to that
    >> property directly; i.e. bind it to your table view's array
    >> controller with controller key 'arrangedObjects' and model key path
    >> the name of your invented options property...
    >>
    >> Cheers,
    >> dave
    >>
    >> On 15-Nov-07, at 3:33 PM, Orestis Markou wrote:
    >>
    >>> I have an NSArrayController that has in the last column an
    >>> NSPopUpButtonCell, for a master-detail scenario.
    >>>
    >>> I have used bindings to set it all up and it works.
    >>>
    >>> However, I want to hide some of the MenuItems of the PopUpMenu
    >>> depending on the row I am in. For example, according to the type
    >>> of the object bound to the row, there are different choices in the
    >>> pop-up menu. I can do this using the
    >>> menu:updateItem:atIndex:shouldCancel: method.
    >>>
    >>> Here is the bug: the selection of the NSArrayController isn't
    >>> updated until *after* the pop-up menu has *closed*. So of course
    >>> when accesing selection from within
    >>> menu:updateItem:atIndex:shouldCancel:, I get the wrong data. If I
    >>> carefully select the row before summoning the menu, everything
    >>> works fine.
    >>>
    >>> So, I have three paths:
    >>>
    >>> a) try to somehow intercept the mouse click and deliver it first
    >>> to the NSArrayController, then the pop-up cell
    >>> b) delay the opening/creation of the pop-up menu until the
    >>> selection is updated
    >>> c) bypass the controller and its bindings altogether and do the
    >>> menu column manually.
    >>>
    >>> I can't find a straightforward way to do any of the above, so
    >>> please help!
    >>>
    >>> I am very new to Cocoa, so I may have missed something
    >>> fundamental. Please say so.
    >>>
    >>> Thank you,
    >>> --
    >>> Orestis Markou
    >>> <orestis...>
    >>> http://orestis.gr/
    >>>
    >>
    >
    >
previous month november 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    
Go to today