• 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 in a NSTableView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Contextual menus in a NSTableView


  • Subject: Re: Contextual menus in a NSTableView
  • From: Brian France <email@hidden>
  • Date: Thu, 20 Dec 2001 19:27:12 -0800

I added this to a subclass of NSTableView. It selects the row and also allows the creating right click menus (context menus) for cells. The delegate must respond to tableView:contextMenuForRow:col: for the menu part to work. I got this from the mailing list archive where somebody did it for NSOutlineView. Sorry I don't remember who it was, but the NSOutlineView context menu idea rocks to! (just wish I could get rid of the compile warnings)

Brian

----

- (NSMenu *)menuForEvent:(NSEvent *)theEvent
{
int rowIndex = [self rowAtPoint:[self convertPoint:[theEvent locationInWindow] fromView:nil]];
int colIndex = [self columnAtPoint:[self convertPoint:[theEvent locationInWindow] fromView:nil]];

if ( rowIndex >= 0 && colIndex >= 0 )
{
id delegate = [self delegate];

// 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];

if ( [delegate respondsToSelector:@selector(tableView:shouldSelectRow:)] )
{
if ( [delegate tableView:self shouldSelectRow:rowIndex] )
{
[self selectRow:rowIndex byExtendingSelection:NO];
}
}
else
{
[self selectRow:rowIndex byExtendingSelection:NO];
}

if ( [delegate respondsToSelector:@selector(tableView:contextMenuForRow:col:)] )
{
return [delegate tableView:self contextMenuForRow:rowIndex col:colIndex];
}
}
else // click in lala land
{
[self deselectAll:self];
return [self menu];
}

return nil;
}




At 6:02 PM +0100 12/20/01, Stiphane Sudre wrote:
Is it not problematic that when you control click on a line, this line is not selected ?

I've just discovered this little inconsistency between the traditional Mac OS behavior (which can be seen in the Finder in Icon mode since the list mode is buggy) and this behavior.

In fact, I'm sure it's a more complex topic since it depends on whether you consider the contextual menu to be the one of the selected row(s) or the one of the TableView.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


--


References: 
 >Contextual menus in a NSTableView (From: Stéphane Sudre <email@hidden>)

  • Prev by Date: Re: Contextual menus in a NSTableView
  • Next by Date: Re: CriticalAlert
  • Previous by thread: Re: Contextual menus in a NSTableView
  • Next by thread: resizing images in NSTextView
  • Index(es):
    • Date
    • Thread