public bool HandleKey(NSTextView view, NSEvent evt) { bool handled = false; try { if (m_database != null) { NSRange range = view.selectedRange(); NSString chars = evt.characters(); if (range.length == 0 && chars.length() == 1 && chars[0] == '.') { view.insertText(NSString.Create('.')); Unused.Value = DoComplete(this.DoCompleteDot, view, range); handled = true; } else if (range.length == 0 && chars.length() == 1 && chars[0] == '\t') { handled = DoCompleteTab(view, evt, range); } if (!handled) { var annotation = m_boss.Get<IArgsAnnotation>(); handled = annotation.HandleKey(view, evt); } } } catch (Exception e) { Log.WriteLine(TraceLevel.Error, "Errors", "Autocomplete failed:"); Log.WriteLine(TraceLevel.Error, "Errors", e.ToString()); NSString title = NSString.Create("Auto-complete failed."); NSString message = NSString.Create(e.Message); Unused.Value = Functions.NSRunAlertPanel(title, message); } return handled; }
public new void keyDown(NSEvent evt) { NSString chars = evt.characters(); // TODO: Would be nice to also complete for '.' and ','. This should insert // the punctuation and, for '.', start a new completion. if (chars.Equals("\t") || chars.Equals("\r") || chars.Equals(" ") || chars.Equals("(")) { DoComplete(false, selectedRow()); } else if (evt.keyCode() == Constants.EnterKey) { DoComplete(true, selectedRow()); } else if (chars.Equals(Constants.Escape)) { m_text = null; window().windowController().Call("hide"); } else if (chars.length() == 1 && (char.IsLetterOrDigit(chars[0]) || chars[0] == '_')) { m_completed += chars[0]; int count = DoMatchName(); if (count > 0) { reloadData(); } else if (m_completed.Length == 1) { // It's rather confusing to have completed text without any indication // that there is completed text so if the user's completed text is completely // bogus we'll reset it. m_completed = string.Empty; } } else if (chars.Equals(Constants.Delete)) { if (m_completed.Length > 0) { m_completed = m_completed.Remove(m_completed.Length - 1); DoMatchName(); reloadData(); } else Functions.NSBeep(); } else if (chars.length() == 1 && chars[0] == ' ') { DoMatchName(); // just select the best match } else { Unused.Value = SuperCall(NSTableView.Class, "keyDown:", evt); } }