long /*int*/ menuForEvent(long /*int*/ id, long /*int*/ sel, long /*int*/ theEvent) { if (id != headerView.id) { /* * Feature in Cocoa: Table views do not change the selection when the user * right-clicks or control-clicks on an NSTableView or its subclasses. Fix is to select the * clicked-on row ourselves. */ NSEvent event = new NSEvent(theEvent); NSTableView table = (NSTableView)view; // get the current selections for the table view. NSIndexSet selectedRowIndexes = table.selectedRowIndexes(); // select the row that was clicked before showing the menu for the event NSPoint mousePoint = view.convertPoint_fromView_(event.locationInWindow(), null); long /*int*/ row = table.rowAtPoint(mousePoint); // figure out if the row that was just clicked on is currently selected if (selectedRowIndexes.containsIndex(row) == false) { NSIndexSet set = (NSIndexSet)new NSIndexSet().alloc(); set = set.initWithIndex(row); table.selectRowIndexes (set, false); set.release(); } // else that row is currently selected, so don't change anything. } return super.menuForEvent(id, sel, theEvent); }
long /*int*/ menuForEvent(long /*int*/ id, long /*int*/ sel, long /*int*/ theEvent) { if (id != headerView.id) { /* * Feature in Cocoa: Table views do not change the selection when the user * right-clicks or control-clicks on an NSTableView or its subclasses. Fix is to select the * clicked-on row ourselves. */ NSEvent event = new NSEvent(theEvent); NSOutlineView tree = (NSOutlineView)view; // get the current selections for the outline view. NSIndexSet selectedRowIndexes = tree.selectedRowIndexes(); // select the row that was clicked before showing the menu for the event NSPoint mousePoint = view.convertPoint_fromView_(event.locationInWindow(), null); long /*int*/ row = tree.rowAtPoint(mousePoint); // figure out if the row that was just clicked on is currently selected if (selectedRowIndexes.containsIndex(row) == false) { NSIndexSet set = (NSIndexSet)new NSIndexSet().alloc(); set = set.initWithIndex(row); tree.selectRowIndexes (set, false); set.release(); } // else that row is currently selected, so don't change anything. } return super.menuForEvent(id, sel, theEvent); }