protected void txtEntry_WidgetEvent(object o, Gtk.WidgetEventArgs args) { // Did the user type "@"? if (args.Event.Type == EventType.KeyPress) { EventKey eventKey = (EventKey)args.Event; if (eventKey.Key == Gdk.Key.at) { // Prevent the editor from typing the "@" key args.RetVal = true; // The user typed "@", so run the chooser for @-mentions using (var window = new UserChooserWindow()) { // Find the coordinates of the text editor int editorX; int editorY; txtEntry.GdkWindow.GetOrigin(out editorX, out editorY); // If the CC input box is empty, position the chooser on top of the input box. // Otherwise position it just below the input box, so the existing text is not hidden. window.SetPosition(WindowPosition.None); if (string.IsNullOrWhiteSpace(txtEntry.Text)) { window.Move(editorX, editorY); } else { int editorW; int editorH; txtEntry.GdkWindow.GetSize(out editorW, out editorH); window.Move(editorX, editorY + editorH); } Utilities.RunWindowAsDialog(window); // Did the user select something? (If not, fall through and let the // "@" key be typed normally.) if (window.ChosenUser != null) { // Insert the alias for the user that was chosen if (txtEntry.Text.Length > 0 && !txtEntry.Text.EndsWith(" ")) { txtEntry.Text += " "; } txtEntry.Text += "@" + window.ChosenUser.Alias; txtEntry.Position = txtEntry.Text.Length; } } } } }
protected void txtBody_WidgetEvent(object o, WidgetEventArgs args) { if (!txtBody.Editable) { return; } // Did the user type "@"? if (args.Event.Type == EventType.KeyPress) { EventKey eventKey = (EventKey)args.Event; if (eventKey.Key == Gdk.Key.at) { // The user typed "@", so run the chooser for @-mentions using (var window = new UserChooserWindow()) { // Find the coordinates of the text editor int editorX; int editorY; txtBody.GdkWindow.GetOrigin(out editorX, out editorY); // Find the location of the cursor within the editor TextIter iter = txtBody.Buffer.GetIterAtOffset(txtBody.Buffer.CursorPosition); int cursorY; int lineHeight; txtBody.GetLineYrange(iter, out cursorY, out lineHeight); // Position the window immediately below the line that the cursor is on, // but aligned to the left of the editor frame window.SetPosition(WindowPosition.None); window.Move(editorX, editorY + cursorY + lineHeight); Utilities.RunWindowAsDialog(window); // Did the user select something? (If not, fall through and let the // "@" key be typed normally.) if (window.ChosenUser != null) { // Prevent the editor from typing the "@" key args.RetVal = true; // If we're in the middle of typing a word, insert a space if (iter.EndsWord() || iter.InsideWord()) { txtBody.Buffer.InsertAtCursor(" "); } // Insert the alias for the user that was chosen txtBody.Buffer.InsertAtCursor("@" + window.ChosenUser.Alias + " "); } } } } }