NSTableView w/Contextual Menu
NSTableView w/Contextual Menu
- Subject: NSTableView w/Contextual Menu
- From: Brian Amerige <email@hidden>
- Date: Thu, 17 Aug 2006 11:34:04 -0400
I've looked through all the archives on this exact issue, and
followed them point by point, but something still isn't working.
I've subclassed 'NSTableView', 'SpecialTableView', in select the row
as well when right clicking.
An outlet ( 'IBOutlet NSMenu *tableContextualMenu') is in
'SpecialTableView.h'.
I've created a menu inside IB, and connected it to my TableView's
menu outlet. The following is a method from 'SpecialTableView.m':
- (NSMenu *)menuForEvent:(NSEvent *)theEvent
{
int row = [self rowAtPoint:[self convertPoint:[theEvent
locationInWindow] fromView:nil]];
if( row != -1 )
{
NSLog(@"Temp Feedback -Contextual Click on row..");
[self selectRow:row byExtendingSelection:NO];
return menu;
}
else
{
NSLog(@"Temp Feedback -Contextual Click on empty row..");
[self deselectAll:nil];
return menu;
}
[[self window] makeFirstResponder:self];
NSPoint menuPoint = [self convertPoint:[theEvent locationInWindow]
fromView:nil];
int row2 = [self rowAtPoint:menuPoint];
BOOL currentRowIsSelected = [[self selectedRowIndexes]
containsIndex:row2];
if (!currentRowIsSelected)
{
[self selectRow:row byExtendingSelection:NO];
}
if ([self numberOfSelectedRows] <=0)
{
NSMenu* tableViewMenu = [[self menu] copy];
int i;
for (i=0; i<[tableViewMenu numberOfItems]; i++)
{
[[tableViewMenu itemAtIndex:i] setEnabled:NO];
}
return [tableViewMenu autorelease];
}
else
{
return menu;
}
}
Really appreciate any help,
Brian.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden