On Aug 7, 2012, at 10:55 PM, Graham Cox <graham....@bigpond.com> wrote:

> 
> 
> According to the release notes for 10.7, NSTableView should now support 
> contextual menus at the individual cell level:
> 
>> NSTableView/NSOutlineView - Contextual menu support
>> 
>> NSTableView and NSOutlineView now have better contextual menu support. 
>> Please see the DragNDropOutlineView demo application for an example of how 
>> to properly do contextual menus with a TableView.
>> 
>> The key thing to note is that clickedRow and clickedColumn will now both be 
>> valid when a contextual menu is popped up. In addition, one can dynamically 
>> set the popup menu for a particular cell/column in the delegate method 
>> willDisplayCell:. NSTableView handles this by properly overriding 
>> menuForEvent:, setting the clickedRow/clickedColumn, and calling [NSCell 
>> menuForEvent:inRect:ofView] to find the correct menu. If no menu was 
>> returned, the menu for the NSTableView will be used. If one right clicks on 
>> a selection of items, all the items are highlighted. One should check to see 
>> if clickedRow is one of the selected rows, and if it is then do the menu 
>> operation on all the selected rows. The clickedRow and clickedColumn 
>> properties will still be valid when the action is sent from the NSMenuItem.
>> 
> 
> 
> But when I implement the method in my custom cell, though it's being called 
> correctly,  -clickedRow and -clickedColumn are returning -1. As a result I 
> can't tell which row I right-clicked, so I can't process the menu further. 
> Has this change been revoked in 10.8 (which I'm using at the moment)?

No it hasn't changed, but the clicked row is set *after* you return a menu. 
That way your menu validation code can use it. I think the DragNDropOutlineView 
demo shows how to do this.

corbin


> 
> Code:
> 
> - (NSMenu*)           menuForEvent:(NSEvent *)event inRect:(NSRect)cellFrame 
> ofView:(NSView *)view
> {
>       NSMenu* menu = nil;
>       
>       if([view respondsToSelector:@selector(delegate)])
>       {
>               id tvDelegate = [(id)view delegate];
>               
>               if([view isKindOfClass:[NSTableView class]] && [tvDelegate 
> respondsToSelector:@selector(contextualMenuForTableView:tableColumn:row:)])
>               {
>                       NSTableView*    tv = (NSTableView*) view;
>                       NSInteger               row, column;
>                       
>                       row = [tv clickedRow];
>                       column = [tv clickedColumn];
> 
> 
> 
> 
> --Graham
> 
> 
> 
> 
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/corbind%40apple.com
> 
> This email sent to corb...@apple.com


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to