• 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: Right way to implement contextual menu in table/outline view?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Right way to implement contextual menu in table/outline view?


  • Subject: Re: Right way to implement contextual menu in table/outline view?
  • From: Patrick Mau <email@hidden>
  • Date: Tue, 09 Dec 2008 05:00:43 +0100

Hi Graham

On 09.12.2008, at 04:51, Graham Cox wrote:

In my app I have an NSOutlineView. I have contextual menus relating to the overall table, but also relating to an individual item row. I notice that when I right-click on a row, I get a special highlight (blue outline) independent of the selected row. How can I find out what row that was when the menu item's action is called? I need to handle the menu differently depending on whether a specific row was right-clicked or just the general table.


You have to subclass NSTableView and override menuforEven as shown below.

@implementation MyTableView
- (NSMenu *)menuForEvent:(NSEvent *)theEvent
{
NSPoint p = [self convertPoint:[theEvent locationInWindow] fromView:nil];
NSInteger row = [self rowAtPoint:p];


    if (row == -1)
	return nil;

[self selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];

    return [self menu];
}

@end

If you click below the last row, your rownum will be '-1'. The above example does only select the row you clicked on by
setting 'byExtendingSelection' to NO.


Regards
Patrick
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Right way to implement contextual menu in table/outline view? (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Right way to implement contextual menu in table/outline view?
  • Next by Date: Re: Right way to implement contextual menu in table/outline view?
  • Previous by thread: Re: Right way to implement contextual menu in table/outline view?
  • Next by thread: Implementing Delete key event
  • Index(es):
    • Date
    • Thread