• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Contextual Menus for an NSOutlineView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Contextual Menus for an NSOutlineView


  • Subject: Re: Contextual Menus for an NSOutlineView
  • From: Max Horn <email@hidden>
  • Date: Thu, 22 Nov 2001 16:31:05 +0100

The way I solved this in the end was to use a subclass of NSOutlineView, which (besides other things like more Finder like cell editing, tooltips on a per-item base etc.) allows the delegate to provide a context menu for each item. IMHO that is a better solution than to e.g. subclass NSTableColumn.

To do this, your subclass must implement menuForEvent:, and the code will look something like this:


- (NSMenu *)menuForEvent:(NSEvent *)theEvent
{
int rowIndex;

rowIndex = [self rowAtPoint:[self convertPoint:[theEvent locationInWindow] fromView:nil]];

if (rowIndex >= 0)
{
// There seems to be a bug in AppKit; selectRow is supposed to
// abort editing, but it doesn't, thus we do it manually.
[self abortEditing];

item = [self itemAtRow:rowIndex];
if (item)
{
id delegate = [self delegate];
if ([delegate respondsToSelector:@selector(outlineView:shouldSelectItem:)] && [delegate outlineView:self shouldSelectItem:item])
[self selectRow:rowIndex byExtendingSelection:NO];

if ([delegate respondsToSelector:@selector(outlineView:contextMenuForItem:)])
return [delegate outlineView:self contextMenuForItem:item];
}
}
else // click in lala land
{
[self deselectAll:self];
return [self menu];
}
return nil;
}


Then in you delegate, provide this method:

- (NSMenu *)outlineView:(NSOutlineView *)outlineView contextMenuForItem:(id)item;




Cheers,

Max
--
-----------------------------------------------
Max Horn
Software Developer

email: <mailto:email@hidden>
phone: (+49) 6151-494890


References: 
 >Contextual Menus for an NSOutlineView (From: Justin Wood <email@hidden>)

  • Prev by Date: Re: Toolbar Icons area 32x32
  • Next by Date: Dynamically creating a class
  • Previous by thread: Re: Contextual Menus for an NSOutlineView
  • Next by thread: Dynamically creating a class
  • Index(es):
    • Date
    • Thread