Getting the OutlineView for contextual menu?

  • I have a number of outline views and want to add contextual menu
    support to them. The data sources are set as delegates for the outline
    views and two outline views could use the same data source.

    The problem is I can't find a way to get the outline view I right-
    clicked in when in - (void) menuNeedsUpdate: (NSMenu*) menu
    The menu update method is in the data source.

    Any ideas on how to know which one of the outline views I'm about to
    display the menu for?

    Ken
  • I might be misunderstanding what you're trying to do, but have you
    considering creating the menus in IB and setting the outline views'
    menu outlet to the appropriate menus? Then, the right menu will show
    for each outline without any code on your part. If you need to modify
    either of the menus before they display, you can implement the NSMenu
    delegate method - (void)menuNeedsUpdate:(NSMenu *)menu.

    Wil

    On Dec 21, 2007, at 11:50 AM, Ken Drycksback wrote:

    > I have a number of outline views and want to add contextual menu
    > support to them. The data sources are set as delegates for the
    > outline views and two outline views could use the same data source.
    >
    > The problem is I can't find a way to get the outline view I right-
    > clicked in when in - (void) menuNeedsUpdate: (NSMenu*) menu
    > The menu update method is in the data source.
    >
    > Any ideas on how to know which one of the outline views I'm about to
    > display the menu for?
    >
    > Ken
  • This is what I have done except I have only one menu and hooked up all
    outline views to this menu. Having a separate menu for each is a
    better idea. Don't know what I was thinking there...

    So I need to subclass NSOutlineView then, implement the
    menuNeedsUpdate method in my subclass and set it as the menu's delegate?

    Ken

    On Dec 21, 2007, at 12:04 PM, William Turner wrote:

    > I might be misunderstanding what you're trying to do, but have you
    > considering creating the menus in IB and setting the outline views'
    > menu outlet to the appropriate menus? Then, the right menu will show
    > for each outline without any code on your part. If you need to
    > modify either of the menus before they display, you can implement
    > the NSMenu delegate method - (void)menuNeedsUpdate:(NSMenu *)menu.
    >
    > Wil
    >
    > On Dec 21, 2007, at 11:50 AM, Ken Drycksback wrote:
    >
    >> I have a number of outline views and want to add contextual menu
    >> support to them. The data sources are set as delegates for the
    >> outline views and two outline views could use the same data source.
    >>
    >> The problem is I can't find a way to get the outline view I right-
    >> clicked in when in - (void) menuNeedsUpdate: (NSMenu*) menu
    >> The menu update method is in the data source.
    >>
    >> Any ideas on how to know which one of the outline views I'm about
    >> to display the menu for?
    >>
    >> Ken
    >
    >
    >
  • I'm probably missing something here, because it doesn't seem like you
    should need to subclass the outline view.

    As I understand it (simplified), you have two outline views, and each
    has its own context menu. This part can be done completely in IB. In
    addition, you want to do [something] before either menu is displayed,
    right? Now, you already have a data source/delegate for the outline
    views - why not implement the menu delegate method(s) in the outline
    view delegate as well? I.e. - have one delegate managing both outline
    views and menus.

    Or is there something else you want to do?

    Wil

    On Dec 21, 2007, at 12:52 PM, Ken Drycksback wrote:

    > This is what I have done except I have only one menu and hooked up
    > all outline views to this menu. Having a separate menu for each is a
    > better idea. Don't know what I was thinking there...
    >
    > So I need to subclass NSOutlineView then, implement the
    > menuNeedsUpdate method in my subclass and set it as the menu's
    > delegate?
    >
    > Ken
    >
    >
    > On Dec 21, 2007, at 12:04 PM, William Turner wrote:
    >
    >> I might be misunderstanding what you're trying to do, but have you
    >> considering creating the menus in IB and setting the outline views'
    >> menu outlet to the appropriate menus? Then, the right menu will
    >> show for each outline without any code on your part. If you need to
    >> modify either of the menus before they display, you can implement
    >> the NSMenu delegate method - (void)menuNeedsUpdate:(NSMenu *)menu.
    >>
    >> Wil
    >>
    >> On Dec 21, 2007, at 11:50 AM, Ken Drycksback wrote:
    >>
    >>> I have a number of outline views and want to add contextual menu
    >>> support to them. The data sources are set as delegates for the
    >>> outline views and two outline views could use the same data source.
    >>>
    >>> The problem is I can't find a way to get the outline view I right-
    >>> clicked in when in - (void) menuNeedsUpdate: (NSMenu*) menu
    >>> The menu update method is in the data source.
    >>>
    >>> Any ideas on how to know which one of the outline views I'm about
    >>> to display the menu for?
    >>>
    >>> Ken
    >>
    >>
    >>
    >
  • And I'm no Cocoa expert so maybe I'm missing something here :)
      I fail to see how I can get to the outline view from the data
    source. Note that the data source can be used to serve data to both
    outline views, or to only one, and sometimes none at all. The data
    source for an outline view can be changed at runtime.

    So I see no way of getting to the outline view unless I subclass it
    and then in menuNeedsUpdate I can call [ self clickedRow ] or whatnot.
    I'd rather not subclass it if there's another way tho.

    Ken

    On Dec 21, 2007, at 1:04 PM, William Turner wrote:
    >
    > As I understand it (simplified), you have two outline views, and
    > each has its own context menu. This part can be done completely in
    > IB. In addition, you want to do [something] before either menu is
    > displayed, right? Now, you already have a data source/delegate for
    > the outline views - why not implement the menu delegate method(s) in
    > the outline view delegate as well? I.e. - have one delegate managing
    > both outline views and menus.
    >
    > Or is there something else you want to do?
    >
    > Wil
    >
    > On Dec 21, 2007, at 12:52 PM, Ken Drycksback wrote:
    >
    >> This is what I have done except I have only one menu and hooked up
    >> all outline views to this menu. Having a separate menu for each is
    >> a better idea. Don't know what I was thinking there...
    >>
    >> So I need to subclass NSOutlineView then, implement the
    >> menuNeedsUpdate method in my subclass and set it as the menu's
    >> delegate?
    >>
    >> Ken
    >>
    >>
    >> On Dec 21, 2007, at 12:04 PM, William Turner wrote:
    >>
    >>> I might be misunderstanding what you're trying to do, but have you
    >>> considering creating the menus in IB and setting the outline
    >>> views' menu outlet to the appropriate menus? Then, the right menu
    >>> will show for each outline without any code on your part. If you
    >>> need to modify either of the menus before they display, you can
    >>> implement the NSMenu delegate method - (void)menuNeedsUpdate:
    >>> (NSMenu *)menu.
    >>>
    >>> Wil
    >>>
    >>> On Dec 21, 2007, at 11:50 AM, Ken Drycksback wrote:
    >>>
    >>>> I have a number of outline views and want to add contextual menu
    >>>> support to them. The data sources are set as delegates for the
    >>>> outline views and two outline views could use the same data source.
    >>>>
    >>>> The problem is I can't find a way to get the outline view I right-
    >>>> clicked in when in - (void) menuNeedsUpdate: (NSMenu*) menu
    >>>> The menu update method is in the data source.
    >>>>
    >>>> Any ideas on how to know which one of the outline views I'm about
    >>>> to display the menu for?
    >>>>
    >>>> Ken
    >>>
    >>>
    >>>
    >>
    >
    >
    >
  • On Dec 21, 2007, at 1:23 PM, Ken Drycksback wrote:

    > And I'm no Cocoa expert so maybe I'm missing something here :)
    > I fail to see how I can get to the outline view from the data source.
    You can always add an outlet(s) from your data source to the outline
    views. If the data source for an outline is changing dynamically, you
    can always update the data source outlets at the same time. It's more
    bookkeeping, so it becomes a question of deciding which path will be
    simplest. You may decide that subclassing is the easiest route.

    Hard to say more without a clearer idea of the end goal...

    > Note that the data source can be used to serve data to both outline
    > views, or to only one, and sometimes none at all. The data source
    > for an outline view can be changed at runtime.
    >
    > So I see no way of getting to the outline view unless I subclass it
    > and then in menuNeedsUpdate I can call [ self clickedRow ] or
    > whatnot. I'd rather not subclass it if there's another way tho.
    >
    > Ken
    >
    >
    > On Dec 21, 2007, at 1:04 PM, William Turner wrote:
    >>
    >> As I understand it (simplified), you have two outline views, and
    >> each has its own context menu. This part can be done completely in
    >> IB. In addition, you want to do [something] before either menu is
    >> displayed, right? Now, you already have a data source/delegate for
    >> the outline views - why not implement the menu delegate method(s)
    >> in the outline view delegate as well? I.e. - have one delegate
    >> managing both outline views and menus.
    >>
    >> Or is there something else you want to do?
    >>
    >> Wil
    >>
    >> On Dec 21, 2007, at 12:52 PM, Ken Drycksback wrote:
    >>
    >>> This is what I have done except I have only one menu and hooked up
    >>> all outline views to this menu. Having a separate menu for each is
    >>> a better idea. Don't know what I was thinking there...
    >>>
    >>> So I need to subclass NSOutlineView then, implement the
    >>> menuNeedsUpdate method in my subclass and set it as the menu's
    >>> delegate?
    >>>
    >>> Ken
    >>>
    >>>
    >>> On Dec 21, 2007, at 12:04 PM, William Turner wrote:
    >>>
    >>>> I might be misunderstanding what you're trying to do, but have
    >>>> you considering creating the menus in IB and setting the outline
    >>>> views' menu outlet to the appropriate menus? Then, the right menu
    >>>> will show for each outline without any code on your part. If you
    >>>> need to modify either of the menus before they display, you can
    >>>> implement the NSMenu delegate method - (void)menuNeedsUpdate:
    >>>> (NSMenu *)menu.
    >>>>
    >>>> Wil
    >>>>
    >>>> On Dec 21, 2007, at 11:50 AM, Ken Drycksback wrote:
    >>>>
    >>>>> I have a number of outline views and want to add contextual menu
    >>>>> support to them. The data sources are set as delegates for the
    >>>>> outline views and two outline views could use the same data
    >>>>> source.
    >>>>>
    >>>>> The problem is I can't find a way to get the outline view I
    >>>>> right-clicked in when in - (void) menuNeedsUpdate: (NSMenu*) menu
    >>>>> The menu update method is in the data source.
    >>>>>
    >>>>> Any ideas on how to know which one of the outline views I'm
    >>>>> about to display the menu for?
    >>>>>
    >>>>> Ken
    >>>>
    >>>>
    >>>>
    >>>
    >>
    >>
    >>
    >
  • Subclassing is the simplest route in this case I think and it works
    great so I'll leave it at that. Thanks Wil for pointing me in the
    right direction!

    Ken

    On Dec 21, 2007, at 1:56 PM, William Turner wrote:

    >
    > On Dec 21, 2007, at 1:23 PM, Ken Drycksback wrote:
    >
    >> And I'm no Cocoa expert so maybe I'm missing something here :)
    >> I fail to see how I can get to the outline view from the data
    >> source.
    > You can always add an outlet(s) from your data source to the outline
    > views. If the data source for an outline is changing dynamically,
    > you can always update the data source outlets at the same time. It's
    > more bookkeeping, so it becomes a question of deciding which path
    > will be simplest. You may decide that subclassing is the easiest
    > route.
    >
    > Hard to say more without a clearer idea of the end goal...
    >
    >> Note that the data source can be used to serve data to both outline
    >> views, or to only one, and sometimes none at all. The data source
    >> for an outline view can be changed at runtime.
    >>
    >> So I see no way of getting to the outline view unless I subclass it
    >> and then in menuNeedsUpdate I can call [ self clickedRow ] or
    >> whatnot. I'd rather not subclass it if there's another way tho.
    >>
    >> Ken
    >>
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