Skip navigation.
 
mlRe: Consistent Contextual Menu in NSTableview
FROM : Nate Weaver
DATE : Mon Apr 21 22:37:09 2008

I would probably override -menuForEvent: instead of -rightMouseDown: .

Leopard also has a bit nicer contextual menu handing for table/outline 
views: If you right-click a row that's not currently selected it 
highlights just an outline and doesn't change the selection (you can 
use -clickedRow to get that row from within your action method(s)).

On Apr 21, 2008, at 11:59 AM, Steve Cronin wrote:
> Folks;
>
> I'm having some difficulty getting consistent contextual menu 
> behavior in NSTableView.
>
> In the Finder and iTunes (what I feel most users are familiar with) 
> if a row is selected but the user causes a contextual menu on a 
> different row then row selection changes.
> (I don't want to start a UI flame about 'correctness') I'm only 
> interested in consistency!!
>
> NOTE: the contextual menu can appear by a right mouse click, a two-
> fingered tap, and a control-click which appear to be detected as 
> different events (see below)
>
> The base NSTableView class does NOT change the selection when a 
> contextual click occurs on a row
> If I sub-class and add:
> - (void)rightMouseDown:(NSEvent *)theEvent {
>     [self selectRow:[self rowAtPoint:[self convertPoint:[theEvent 
> locationInWindow] fromView:nil]] byExtendingSelection:NO];
>     [super rightMouseDown:theEvent];
> }
>
> I get half-way home.  Now the right mouse click and the two-fingered 
> tap will alter the selection.
>
> BUT
>
> the control-click does not.
>
> The Cocoa adage, "if you are working too hard, you probably are" 
> keeps rummaging around my brain....
>
> What is the preferred means to efficiently make consistent 
> contextual menu behavior like Finder and iTunes?
>
> Thanks,
> Steve

Related mailsAuthorDate
mlConsistent Contextual Menu in NSTableview Steve Cronin Apr 21, 18:59
mlRe: Consistent Contextual Menu in NSTableview Nate Weaver Apr 21, 22:37
mlRe: Consistent Contextual Menu in NSTableview Corbin Dunn Apr 22, 17:51