public override NSMenu menuForEvent(NSEvent @event) { if (menu == null) return base.menuForEvent(@event); // NSLog(@"menuForEvent:"); // Find which row is under the cursor this.window().makeFirstResponder(this); NSPoint menuPoint = this.convertPoint(@event.locationInWindow()) fromView(null); int row = this.rowAtPoint(menuPoint); if (row > -1) { bool currentRowIsSelected = this.selectedRowIndexes().containsIndex(row); if (!currentRowIsSelected) this.selectRowIndexes(NSIndexSet.indexSetWithIndex(row)) byExtendingSelection(false); } else { this.deselectAll(null); } if (this.numberOfSelectedRows() <= 0) { // No rows are selected, so the table should be displayed with all items disabled NSMenu tableViewMenu = this.menu().copy(); for (int i = 0; i < tableViewMenu.numberOfItems; i++) tableViewMenu.itemAtIndex(i).setEnabled(false); return tableViewMenu; } else return this.menu(); }
public new NSMenu menuForEvent(NSEvent evt) { // If the item clicked on is not selected then select it. NSPoint baseLoc = evt.locationInWindow(); NSPoint viewLoc = convertPointFromBase(baseLoc); int row = rowAtPoint(viewLoc); if (row >= 0) { if (!isRowSelected(row)) { var indexes = NSIndexSet.indexSetWithIndex((uint) row); selectRowIndexes_byExtendingSelection(indexes, false); } } NSMenu menu = SuperCall(NSOutlineView.Class, "menuForEvent:", evt).To<NSMenu>(); return menu; }
private int DoMouseEventToIndex(NSTextView view, NSEvent evt) { NSPoint baseLoc = evt.locationInWindow(); NSPoint viewLoc = view.convertPointFromBase(baseLoc); return (int) view.characterIndexForInsertionAtPoint(viewLoc); }
// Note that the preferred way to do this (as of 10.5) is to attach a menu to the // table and bind the menu delegate to a controller. Then the controller can // define menuNeedsUpdate and use that to adjust the selection or change the // menu items based on the selection. public new NSMenu menuForEvent(NSEvent evt) { NSMenu menu = NSMenu.Alloc().initWithTitle(NSString.Empty); menu.autorelease(); // Make the window the key window (handleSccs expects that it // is either the main or the key window). window().makeKeyAndOrderFront(this); // If the item clicked on is not selected then select it. NSPoint baseLoc = evt.locationInWindow(); NSPoint viewLoc = convertPointFromBase(baseLoc); int row = rowAtPoint(viewLoc); if (row >= 0) { if (!isRowSelected(row)) { var indexes = NSIndexSet.indexSetWithIndex((uint) row); selectRowIndexes_byExtendingSelection(indexes, false); } } // Find the items which are selected. var paths = new List<string>(); foreach (uint index in selectedRowIndexes()) { TableItem item = (TableItem) (itemAtRow((int) index)); paths.Add(item.Path); } // Build the menu. foreach (string path in paths) { if (System.IO.File.Exists(path)) { Unused.Value = menu.addItemWithTitle_action_keyEquivalent( NSString.Create("Open as Binary"), "openBinaries:", NSString.Empty); break; } } Dictionary<string, string[]> commands = Sccs.GetCommands(paths); foreach (var entry in commands) { if (entry.Value.Length > 0) { if (menu.numberOfItems() > 0) menu.addItem(NSMenuItem.separatorItem()); var cmds = new List<string>(entry.Value); cmds.Sort(); foreach (string command in cmds) { Unused.Value = menu.addItemWithTitle_action_keyEquivalent( NSString.Create(command), "handleSccs:", NSString.Empty); } } } return menu; }
public new void mouseDown(NSEvent evt) { NSPoint originalPoint = convertPoint_fromView(evt.locationInWindow(), null); if (m_selection.size != NSSize.Zero) { setNeedsDisplayInRect(m_selection); m_selection = NSRect.Empty; } do { evt = window().nextEventMatchingMask(Enums.NSLeftMouseDraggedMask | Enums.NSLeftMouseUpMask); autoscroll(evt); NSPoint currentPoint = convertPoint_fromView(evt.locationInWindow(), null); NSRect oldSelection = m_selection; m_selection = DoCreateSelectionRect(originalPoint, currentPoint); setNeedsDisplayInRect(m_selection.Union(oldSelection)); } while (evt.type() == Enums.NSLeftMouseDragged); DoInvariant(); }