public LinkEventArgs (string link, uint button, Gdk.ModifierType modifierState) { this.Link = link; this.Button = button; this.ModifierState = modifierState; }
public BindingAttribute (Gdk.Key key, Gdk.ModifierType mod, string handler, params object[] parms) { this.key = key; this.mod = mod; this.handler = handler; this.parms = parms; }
void HandleKeyPressEvent (object o, Gtk.KeyPressEventArgs args) { keyHandled = false; keyChar = (char)args.Event.Key; keyValue = args.Event.KeyValue; modifier = args.Event.State; key = args.Event.Key; if ((args.Event.Key == Gdk.Key.Down || args.Event.Key == Gdk.Key.Up)) { keyChar = '\0'; } if (list != null) args.RetVal = keyHandled = CompletionWindowManager.PreProcessKeyEvent (KeyDescriptor.FromGtk (key, keyChar, modifier)); }
protected override bool ProcessViewModelClicked(IViewModel viewModel, int x, int y, int cellWidth, Gdk.ModifierType state) { if (viewModel is EventTypeTimelineVM && state.HasFlag(Gdk.ModifierType.None)) { var vm = (EventTypeTimelineVM)viewModel; if (vm.Model is SubstitutionEventType) { return(false); } if (PlaysCellRenderer.ClickedPlayButton(x, y, cellWidth)) { vm.LoadEventType(); pathClicked = null; return(true); } } return(false); }
/// <summary>Populate the context menu from the descriptions passed in.</summary> /// <param name="menuDescriptions">Menu descriptions for each menu item.</param> public void PopulateContextMenu(List <MenuDescriptionArgs> menuDescriptions) { ClearPopup(); foreach (MenuDescriptionArgs Description in menuDescriptions) { MenuItem item; if (Description.ShowCheckbox) { CheckMenuItem checkItem = new CheckMenuItem(Description.Name); checkItem.Active = Description.Checked; item = checkItem; } else if (!String.IsNullOrEmpty(Description.ResourceNameForImage) && hasResource(Description.ResourceNameForImage)) { ImageMenuItem imageItem = new ImageMenuItem(Description.Name); imageItem.Image = new Gtk.Image(null, Description.ResourceNameForImage); item = imageItem; } else { item = new MenuItem(Description.Name); } if (!String.IsNullOrEmpty(Description.ShortcutKey)) { string keyName = String.Empty; Gdk.ModifierType modifier = Gdk.ModifierType.None; string[] keyNames = Description.ShortcutKey.Split(new Char[] { '+' }); foreach (string name in keyNames) { if (name == "Ctrl") { modifier |= Gdk.ModifierType.ControlMask; } else if (name == "Shift") { modifier |= Gdk.ModifierType.ShiftMask; } else if (name == "Alt") { modifier |= Gdk.ModifierType.Mod1Mask; } else if (name == "Del") { keyName = "Delete"; } else { keyName = name; } } try { Gdk.Key accelKey = (Gdk.Key)Enum.Parse(typeof(Gdk.Key), keyName, false); item.AddAccelerator("activate", accel, (uint)accelKey, modifier, AccelFlags.Visible); } catch { } } item.Activated += Description.OnClick; Popup.Append(item); } if (Popup.AttachWidget == null) { Popup.AttachToWidget(treeview1, null); } Popup.ShowAll(); }
protected override void HandleKeypress(Gdk.Key key, uint unicodeKey, Gdk.ModifierType modifier) { // Reset on Esc, Ctrl-C, Ctrl-[ if (key == Gdk.Key.Escape) { if (currentMacro != null) { // Record Escapes into the macro since it actually does something ViMacro.KeySet toAdd = new ViMacro.KeySet(); toAdd.Key = key; toAdd.Modifiers = modifier; toAdd.UnicodeKey = unicodeKey; currentMacro.KeysPressed.Enqueue(toAdd); } Reset(string.Empty); return; } else if (((key == Gdk.Key.c || key == Gdk.Key.bracketleft) && (modifier & Gdk.ModifierType.ControlMask) != 0)) { Reset(string.Empty); if (currentMacro != null) { // Otherwise remove the macro from the pool macros.Remove(currentMacro.MacroCharacter); currentMacro = null; } return; } else if (currentMacro != null && !((char)unicodeKey == 'q' && modifier == Gdk.ModifierType.None)) { ViMacro.KeySet toAdd = new ViMacro.KeySet(); toAdd.Key = key; toAdd.Modifiers = modifier; toAdd.UnicodeKey = unicodeKey; currentMacro.KeysPressed.Enqueue(toAdd); } Action <TextEditorData> action = null; bool lineAction = false; switch (state) { case State.Unknown: Reset(string.Empty); goto case State.Normal; case State.Normal: if (((modifier & (Gdk.ModifierType.ControlMask)) == 0)) { if (key == Gdk.Key.Delete) { unicodeKey = 'x'; } switch ((char)unicodeKey) { case '?': case '/': case ':': state = State.Command; commandBuffer.Append((char)unicodeKey); Status = commandBuffer.ToString(); return; case 'A': RunAction(CaretMoveActions.LineEnd); goto case 'i'; case 'I': RunAction(CaretMoveActions.LineFirstNonWhitespace); goto case 'i'; case 'a': //use CaretMoveActions so that we can move past last character on line end RunAction(CaretMoveActions.Right); goto case 'i'; case 'i': Caret.Mode = CaretMode.Insert; Status = "-- INSERT --"; state = State.Insert; return; case 'R': Caret.Mode = CaretMode.Underscore; Status = "-- REPLACE --"; state = State.Replace; return; case 'V': Status = "-- VISUAL LINE --"; Data.SetSelectLines(Caret.Line, Caret.Line); state = State.VisualLine; return; case 'v': Status = "-- VISUAL --"; state = State.Visual; RunAction(ViActions.VisualSelectionFromMoveAction(ViActions.Right)); return; case 'd': Status = "d"; state = State.Delete; return; case 'y': Status = "y"; state = State.Yank; return; case 'Y': state = State.Yank; HandleKeypress(Gdk.Key.y, (int)'y', Gdk.ModifierType.None); return; case 'O': RunAction(ViActions.NewLineAbove); goto case 'i'; case 'o': RunAction(ViActions.NewLineBelow); goto case 'i'; case 'r': Caret.Mode = CaretMode.Underscore; Status = "-- REPLACE --"; state = State.WriteChar; return; case 'c': Caret.Mode = CaretMode.Insert; Status = "c"; state = State.Change; return; case 'x': if (Data.Caret.Column == Data.Document.GetLine(Data.Caret.Line).Length + 1) { return; } Status = string.Empty; if (!Data.IsSomethingSelected) { RunActions(SelectionActions.FromMoveAction(CaretMoveActions.Right), ClipboardActions.Cut); } else { RunAction(ClipboardActions.Cut); } ViActions.RetreatFromLineEnd(Data); return; case 'X': if (Data.Caret.Column == DocumentLocation.MinColumn) { return; } Status = string.Empty; if (!Data.IsSomethingSelected && 0 < Caret.Offset) { RunActions(SelectionActions.FromMoveAction(CaretMoveActions.Left), ClipboardActions.Cut); } else { RunAction(ClipboardActions.Cut); } return; case 'D': RunActions(SelectionActions.FromMoveAction(CaretMoveActions.LineEnd), ClipboardActions.Cut); return; case 'C': RunActions(SelectionActions.FromMoveAction(CaretMoveActions.LineEnd), ClipboardActions.Cut); goto case 'i'; case '>': Status = ">"; state = State.Indent; return; case '<': Status = "<"; state = State.Unindent; return; case 'n': Search(); return; case 'N': searchBackward = !searchBackward; Search(); searchBackward = !searchBackward; return; case 'p': PasteAfter(false); return; case 'P': PasteBefore(false); return; case 's': if (!Data.IsSomethingSelected) { RunAction(SelectionActions.FromMoveAction(CaretMoveActions.Right)); } RunAction(ClipboardActions.Cut); goto case 'i'; case 'S': if (!Data.IsSomethingSelected) { RunAction(SelectionActions.LineActionFromMoveAction(CaretMoveActions.LineEnd)); } else { Data.SetSelectLines(Data.MainSelection.Anchor.Line, Data.Caret.Line); } RunAction(ClipboardActions.Cut); goto case 'i'; case 'g': Status = "g"; state = State.G; return; case 'H': Caret.Line = System.Math.Max(DocumentLocation.MinLine, Editor.PointToLocation(0, Editor.LineHeight - 1).Line); return; case 'J': RunAction(ViActions.Join); return; case 'L': int line = Editor.PointToLocation(0, Editor.Allocation.Height - Editor.LineHeight * 2 - 2).Line; if (line < DocumentLocation.MinLine) { line = Document.LineCount; } Caret.Line = line; return; case 'M': line = Editor.PointToLocation(0, Editor.Allocation.Height / 2).Line; if (line < DocumentLocation.MinLine) { line = Document.LineCount; } Caret.Line = line; return; case '~': RunAction(ViActions.ToggleCase); return; case 'z': Status = "z"; state = State.Fold; return; case 'm': Status = "m"; state = State.Mark; return; case '`': Status = "`"; state = State.GoToMark; return; case '@': Status = "@"; state = State.PlayMacro; return; case 'q': if (currentMacro == null) { Status = "q"; state = State.NameMacro; return; } currentMacro = null; Reset("Macro Recorded"); return; case '*': SearchWordAtCaret(); return; } } action = ViActionMaps.GetNavCharAction((char)unicodeKey); if (action == null) { action = ViActionMaps.GetDirectionKeyAction(key, modifier); } if (action == null) { action = ViActionMaps.GetCommandCharAction((char)unicodeKey); } if (action != null) { RunAction(action); } //undo/redo may leave MD with a selection mode without activating visual mode CheckVisualMode(); return; case State.Delete: if (((modifier & (Gdk.ModifierType.ShiftMask | Gdk.ModifierType.ControlMask)) == 0 && unicodeKey == 'd')) { action = SelectionActions.LineActionFromMoveAction(CaretMoveActions.LineEnd); lineAction = true; } else { action = ViActionMaps.GetNavCharAction((char)unicodeKey); if (action == null) { action = ViActionMaps.GetDirectionKeyAction(key, modifier); } if (action != null) { action = SelectionActions.FromMoveAction(action); } } if (action != null) { if (lineAction) { RunActions(action, ClipboardActions.Cut, CaretMoveActions.LineFirstNonWhitespace); } else { RunActions(action, ClipboardActions.Cut); } Reset(""); } else { Reset("Unrecognised motion"); } return; case State.Yank: int offset = Caret.Offset; if (((modifier & (Gdk.ModifierType.ShiftMask | Gdk.ModifierType.ControlMask)) == 0 && unicodeKey == 'y')) { action = SelectionActions.LineActionFromMoveAction(CaretMoveActions.LineEnd); lineAction = true; } else { action = ViActionMaps.GetNavCharAction((char)unicodeKey); if (action == null) { action = ViActionMaps.GetDirectionKeyAction(key, modifier); } if (action != null) { action = SelectionActions.FromMoveAction(action); } } if (action != null) { RunAction(action); if (Data.IsSomethingSelected && !lineAction) { offset = Data.SelectionRange.Offset; } RunAction(ClipboardActions.Copy); Reset(string.Empty); } else { Reset("Unrecognised motion"); } Caret.Offset = offset; return; case State.Change: //copied from delete action if (((modifier & (Gdk.ModifierType.ShiftMask | Gdk.ModifierType.ControlMask)) == 0 && unicodeKey == 'c')) { action = SelectionActions.LineActionFromMoveAction(CaretMoveActions.LineEnd); lineAction = true; } else { action = ViActionMaps.GetEditObjectCharAction((char)unicodeKey); if (action == null) { action = ViActionMaps.GetDirectionKeyAction(key, modifier); } if (action != null) { action = SelectionActions.FromMoveAction(action); } } if (action != null) { if (lineAction) { RunActions(action, ClipboardActions.Cut, ViActions.NewLineAbove); } else { RunActions(action, ClipboardActions.Cut); } Status = "-- INSERT --"; state = State.Insert; Caret.Mode = CaretMode.Insert; } else { Reset("Unrecognised motion"); } return; case State.Insert: case State.Replace: action = GetInsertAction(key, modifier); if (action != null) { RunAction(action); } else if (unicodeKey != 0) { InsertCharacter(unicodeKey); } return; case State.VisualLine: if (key == Gdk.Key.Delete) { unicodeKey = 'x'; } switch ((char)unicodeKey) { case 'p': PasteAfter(true); return; case 'P': PasteBefore(true); return; } action = ViActionMaps.GetNavCharAction((char)unicodeKey); if (action == null) { action = ViActionMaps.GetDirectionKeyAction(key, modifier); } if (action == null) { action = ViActionMaps.GetCommandCharAction((char)unicodeKey); } if (action != null) { RunAction(SelectionActions.LineActionFromMoveAction(action)); return; } ApplyActionToSelection(modifier, unicodeKey); return; case State.Visual: if (key == Gdk.Key.Delete) { unicodeKey = 'x'; } switch ((char)unicodeKey) { case 'p': PasteAfter(false); return; case 'P': PasteBefore(false); return; } action = ViActionMaps.GetNavCharAction((char)unicodeKey); if (action == null) { action = ViActionMaps.GetDirectionKeyAction(key, modifier); } if (action == null) { action = ViActionMaps.GetCommandCharAction((char)unicodeKey); } if (action != null) { RunAction(ViActions.VisualSelectionFromMoveAction(action)); return; } ApplyActionToSelection(modifier, unicodeKey); return; case State.Command: switch (key) { case Gdk.Key.Return: case Gdk.Key.KP_Enter: Status = RunExCommand(commandBuffer.ToString()); commandBuffer.Length = 0; state = State.Normal; break; case Gdk.Key.BackSpace: case Gdk.Key.Delete: case Gdk.Key.KP_Delete: if (0 < commandBuffer.Length) { commandBuffer.Remove(commandBuffer.Length - 1, 1); Status = commandBuffer.ToString(); if (0 == commandBuffer.Length) { Reset(Status); } } break; default: if (unicodeKey != 0) { commandBuffer.Append((char)unicodeKey); Status = commandBuffer.ToString(); } break; } return; case State.WriteChar: if (unicodeKey != 0) { RunAction(SelectionActions.StartSelection); int roffset = Data.SelectionRange.Offset; InsertCharacter((char)unicodeKey); Reset(string.Empty); Caret.Offset = roffset; } else { Reset("Keystroke was not a character"); } return; case State.Indent: if (((modifier & (Gdk.ModifierType.ControlMask)) == 0 && unicodeKey == '>')) { RunAction(MiscActions.IndentSelection); Reset(""); return; } action = ViActionMaps.GetNavCharAction((char)unicodeKey); if (action == null) { action = ViActionMaps.GetDirectionKeyAction(key, modifier); } if (action != null) { RunActions(SelectionActions.FromMoveAction(action), MiscActions.IndentSelection); Reset(""); } else { Reset("Unrecognised motion"); } return; case State.Unindent: if (((modifier & (Gdk.ModifierType.ControlMask)) == 0 && ((char)unicodeKey) == '<')) { RunAction(MiscActions.RemoveIndentSelection); Reset(""); return; } action = ViActionMaps.GetNavCharAction((char)unicodeKey); if (action == null) { action = ViActionMaps.GetDirectionKeyAction(key, modifier); } if (action != null) { RunActions(SelectionActions.FromMoveAction(action), MiscActions.RemoveIndentSelection); Reset(""); } else { Reset("Unrecognised motion"); } return; case State.G: if (((modifier & (Gdk.ModifierType.ControlMask)) == 0)) { switch ((char)unicodeKey) { case 'g': Caret.Offset = 0; Reset(""); return; } } Reset("Unknown command"); return; case State.Mark: { char k = (char)unicodeKey; ViMark mark = null; if (!char.IsLetterOrDigit(k)) { Reset("Invalid Mark"); return; } if (marks.ContainsKey(k)) { mark = marks [k]; } else { mark = new ViMark(k); marks [k] = mark; } RunAction(mark.SaveMark); Reset(""); return; } case State.NameMacro: { char k = (char)unicodeKey; if (!char.IsLetterOrDigit(k)) { Reset("Invalid Macro Name"); return; } currentMacro = new ViMacro(k); currentMacro.KeysPressed = new Queue <ViMacro.KeySet> (); macros [k] = currentMacro; Reset(""); return; } case State.PlayMacro: { char k = (char)unicodeKey; if (k == '@') { k = macros_lastplayed; } if (macros.ContainsKey(k)) { Reset(""); macros_lastplayed = k; // FIXME play nice when playing macros from inside macros? ViMacro macroToPlay = macros [k]; foreach (ViMacro.KeySet keySet in macroToPlay.KeysPressed) { HandleKeypress(keySet.Key, keySet.UnicodeKey, keySet.Modifiers); // FIXME stop on errors? essential with multipliers and nowrapscan } /* Once all the keys have been played back, quickly exit. */ return; } else { Reset("Invalid Macro Name '" + k + "'"); return; } } case State.GoToMark: { char k = (char)unicodeKey; if (marks.ContainsKey(k)) { RunAction(marks [k].LoadMark); Reset(""); } else { Reset("Unknown Mark"); } return; } case State.Fold: if (((modifier & (Gdk.ModifierType.ControlMask)) == 0)) { switch ((char)unicodeKey) { case 'A': // Recursive fold toggle action = FoldActions.ToggleFoldRecursive; break; case 'C': // Recursive fold close action = FoldActions.CloseFoldRecursive; break; case 'M': // Close all folds action = FoldActions.CloseAllFolds; break; case 'O': // Recursive fold open action = FoldActions.OpenFoldRecursive; break; case 'R': // Expand all folds action = FoldActions.OpenAllFolds; break; case 'a': // Fold toggle action = FoldActions.ToggleFold; break; case 'c': // Fold close action = FoldActions.CloseFold; break; case 'o': // Fold open action = FoldActions.OpenFold; break; default: Reset("Unknown command"); break; } if (null != action) { RunAction(action); Reset(string.Empty); } } return; } }
public void GetPointer(out int x, out int y, out Gdk.ModifierType mod) { Gdk.Screen screen; GetPointer(out screen, out x, out y, out mod); }
public override Gtk.Window ShowTooltipWindow(MonoTextEditor editor, Gtk.Window tipWindow, int offset, Gdk.ModifierType modifierState, int mouseX, int mouseY, MonoDevelop.Ide.Editor.TooltipItem item) { var wrappedEditor = WrapEditor(editor); if (wrappedEditor == null) { return(tipWindow); } provider.ShowTooltipWindow(wrappedEditor, tipWindow, item, modifierState.ToXwtValue(), mouseX, mouseY); return(tipWindow); }
public override Gtk.Window CreateTooltipWindow(MonoTextEditor Editor, int offset, Gdk.ModifierType modifierState, TooltipItem item) { TextLink link = item.Item as TextLink; if (link == null || string.IsNullOrEmpty(link.Tooltip)) { return(null); } TooltipWindow window = new TooltipWindow(); window.Markup = link.Tooltip; return(window); }
public override void InsertCompletionText(CompletionListWindow window, ref KeyActions ka, Gdk.Key closeChar, char keyChar, Gdk.ModifierType modifier) { if (customCompletionText == null) { if (Node != null && !string.IsNullOrEmpty(Node.Name)) { base.InsertCompletionText(window, ref ka, closeChar, keyChar, modifier); } return; } Ide.Gui.Document guiDoc = null; var ed = window.CompletionWidget as SourceEditor.SourceEditorView; foreach (var gdoc in Ide.IdeApp.Workbench.Documents) { if (gdoc.Editor.Document == ed.Document) { guiDoc = gdoc; break; } } if (guiDoc == null) { return; } var f = new Formatting.DCodeFormatter(); var insertionOffset = window.CodeCompletionContext.TriggerOffset; ed.Document.Insert(insertionOffset, customCompletionText, ICSharpCode.NRefactory.Editor.AnchorMovementType.AfterInsertion); guiDoc.UpdateParseDocument(); f.OnTheFlyFormat(guiDoc, insertionOffset, insertionOffset + customCompletionText.Length); }
protected override bool OnKeyPressEvent (Gdk.EventKey evt) { uint keyval; int effectiveGroup, level; Gdk.ModifierType consumedMods, mask; if (!Gtk.Accelerator.Valid (evt.KeyValue, evt.State)) return base.OnKeyPressEvent (evt); // We know this will succeed, since we're already here... Gdk.Keymap.Default.TranslateKeyboardState (evt.HardwareKeycode, evt.State, evt.Group, out keyval, out effectiveGroup, out level, out consumedMods); mask = evt.State & Accelerator.AcceleratorModifierMask & ~consumedMods; if (evt.Key != Gdk.Key.Escape || mask != 0) { Keyval = keyval; Mask = mask; this.Respond (0); } return false; }
public LinkEventArgs(string link, uint button, Gdk.ModifierType modifierState) { this.Link = link; this.Button = button; this.ModifierState = modifierState; }
public Keystroke(Gdk.Key key, uint unicodeKey, Gdk.ModifierType modifier) { m_key = key; m_unicodeKey = unicodeKey; m_modifier = modifier; }
public static void PostProcessKeyEvent(KeyActions ka, Gdk.Key key, char keyChar, Gdk.ModifierType modifier) { if (wnd == null) { return; } wnd.PostProcessKeyEvent(ka, key, keyChar, modifier); }
void HandleCommandManagerKeyPressed (object sender, KeyPressArgs e) { uint unicode = Gdk.Keyval.ToUnicode (e.KeyValue); if (pendingText != null) { if (pendingModifiers != e.Modifiers || unicode == 0) { CompleteStringEvent (pendingText.ToString (), pendingModifiers); } else { pendingText.Append ((char)unicode); return; } // If text event has been completed, then we need to reset the pending events if (unicode != 0) { pendingText = new StringBuilder (); pendingText.Append ((char)unicode); pendingModifiers = e.Modifiers; } else { // Don't have a unicode key, so just issue a standard key event events.Add (new KeyPressEvent { Key = e.Key, Modifiers = e.Modifiers }); pendingText = null; pendingModifiers = Gdk.ModifierType.None; } } else { if (unicode == 0) { events.Add (new KeyPressEvent () { Key = e.Key, Modifiers = e.Modifiers }); return; } pendingText = new StringBuilder (); pendingText.Append ((char)unicode); pendingModifiers = e.Modifiers; } }
void CompleteStringEvent (string s, Gdk.ModifierType modifiers) { events.Add (new StringEvent { Text = pendingText.ToString (), Modifiers = pendingModifiers }); pendingText = null; pendingModifiers = Gdk.ModifierType.None; }
public override void ParseXML (XElement element) { foreach (var e in element.Elements ()) { if (e.Name == "text") { Text = e.Value; } else if (e.Name == "modifier") { Modifiers = (Gdk.ModifierType)Enum.Parse (typeof(Gdk.ModifierType), e.Value); } } }
void OnKeyPressEvent (object s, Gtk.KeyPressEventArgs args) { Gdk.EventKey evt = args.Event; if (!editing || !Gtk.Accelerator.Valid (evt.KeyValue, evt.State)) return; uint keyval; int effectiveGroup, level; Gdk.ModifierType consumedMods, mask; // We know this will succeed, since we're already here... Gdk.Keymap.Default.TranslateKeyboardState (evt.HardwareKeycode, evt.State, evt.Group, out keyval, out effectiveGroup, out level, out consumedMods); mask = evt.State & AcceleratorModifierMask & ~consumedMods; if (evt.Key != Gdk.Key.Escape || mask != 0) { this.keyval = keyval; this.mask = mask; } clearButton.Sensitive = true; Ungrab (evt.Time); EmitAccelChanged (); args.RetVal = true; }
void Grab (Gdk.Window window, uint time) { if (editing) return; grabWindow = new GrabDialog (); editing = true; entry.Text = Catalog.GetString ("Press a key..."); grabWindow.TransientFor = this.Toplevel as Gtk.Window; grabWindow.Run (); this.keyval = grabWindow.Keyval; this.mask = grabWindow.Mask; Ungrab (time); EmitAccelChanged (); }
protected override bool ProcessKeyPressEvent (Gtk.KeyPressEventArgs args) { keyHandled = false; keyChar = (char) args.Event.Key; keyValue = args.Event.KeyValue; modifier = args.Event.State; key = args.Event.Key; if ((args.Event.Key == Gdk.Key.Down || args.Event.Key == Gdk.Key.Up)) { keyChar = '\0'; } if (currentCompletionData != null) { if ((keyHandled = CompletionWindowManager.PreProcessKeyEvent (key, keyChar, modifier))) return true; } return base.ProcessKeyPressEvent (args); }
public MarginMouseEventArgs(MonoTextEditor editor, Gdk.EventType type, uint button, double x, double y, Gdk.ModifierType modifierState) { this.Editor = editor; this.Type = type; this.Button = button; this.X = x; this.Y = y; this.ModifierState = modifierState; }
TooltipInformation CreateTooltip(ToolTipData data, int offset, Ambience ambience, Gdk.ModifierType modifierState) { ResolveResult result = data.Result; var doc = IdeApp.Workbench.ActiveDocument; if (doc == null) { return(null); } bool createFooter = (modifierState & Gdk.ModifierType.Mod1Mask) != 0; var file = doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile; if (file == null) { return(null); } try { if (result is AliasNamespaceResolveResult) { var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location); var sig = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions()); sig.BreakLineAfterReturnType = false; return(sig.GetAliasedNamespaceTooltip((AliasNamespaceResolveResult)result)); } if (result is AliasTypeResolveResult) { var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location); var sig = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions()); sig.BreakLineAfterReturnType = false; return(sig.GetAliasedTypeTooltip((AliasTypeResolveResult)result)); } if (data.Node is TypeOfExpression) { var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location); var sig = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions()); sig.BreakLineAfterReturnType = false; return(sig.GetTypeOfTooltip((TypeOfExpression)data.Node, result as TypeOfResolveResult)); } if (data.Node is PrimitiveType && data.Node.Parent is Constraint) { var t = (PrimitiveType)data.Node; if (t.Keyword == "class" || t.Keyword == "new" || t.Keyword == "struct") { var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location); var sig = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions()); sig.BreakLineAfterReturnType = false; return(sig.GetConstraintTooltip(t.Keyword)); } return(null); } if (data.Node is ExternAliasDeclaration) { var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location); var sig = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions()); sig.BreakLineAfterReturnType = false; return(sig.GetExternAliasTooltip((ExternAliasDeclaration)data.Node, doc.Project as DotNetProject)); } if (result == null && data.Node is CSharpTokenNode) { var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location); var sig = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions()); sig.BreakLineAfterReturnType = false; return(sig.GetKeywordTooltip(data.Node)); } if (data.Node is PrimitiveType && ((PrimitiveType)data.Node).KnownTypeCode == KnownTypeCode.Void) { var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location); var sig = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions()); sig.BreakLineAfterReturnType = false; return(sig.GetKeywordTooltip("void", null)); } if (data.Node is NullReferenceExpression) { var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location); var sig = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions()); sig.BreakLineAfterReturnType = false; return(sig.GetKeywordTooltip("null", null)); } if (result is UnknownIdentifierResolveResult) { return(new TooltipInformation() { SignatureMarkup = string.Format("error CS0103: The name `{0}' does not exist in the current context", ((UnknownIdentifierResolveResult)result).Identifier) }); } else if (result is UnknownMemberResolveResult) { var ur = (UnknownMemberResolveResult)result; if (ur.TargetType.Kind != TypeKind.Unknown) { return(new TooltipInformation() { SignatureMarkup = string.Format("error CS0117: `{0}' does not contain a definition for `{1}'", ur.TargetType.FullName, ur.MemberName) }); } } else if (result.IsError) { return(new TooltipInformation() { SignatureMarkup = "Unknown resolve error." }); } if (result is LocalResolveResult) { var lr = (LocalResolveResult)result; var tooltipInfo = new TooltipInformation(); var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location); var sig = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions()); sig.BreakLineAfterReturnType = false; tooltipInfo.SignatureMarkup = sig.GetLocalVariableMarkup(lr.Variable); return(tooltipInfo); } else if (result is MethodGroupResolveResult) { var mrr = (MethodGroupResolveResult)result; var allMethods = new List <IMethod> (mrr.Methods); foreach (var l in mrr.GetExtensionMethods()) { allMethods.AddRange(l); } var method = allMethods.FirstOrDefault(); if (method != null) { return(MemberCompletionData.CreateTooltipInformation( doc.Compilation, file, doc.Editor, doc.GetFormattingPolicy(), method, false, createFooter)); } } else if (result is CSharpInvocationResolveResult) { var invocationResult = (CSharpInvocationResolveResult)result; var member = (IMember)invocationResult.ReducedMethod ?? invocationResult.Member; return(MemberCompletionData.CreateTooltipInformation( doc.Compilation, file, doc.Editor, doc.GetFormattingPolicy(), member, false, createFooter)); } else if (result is MemberResolveResult) { var member = ((MemberResolveResult)result).Member; return(MemberCompletionData.CreateTooltipInformation( doc.Compilation, file, doc.Editor, doc.GetFormattingPolicy(), member, false, createFooter)); } else if (result is NamespaceResolveResult) { var tooltipInfo = new TooltipInformation(); var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location); var sig = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions()); sig.BreakLineAfterReturnType = false; try { tooltipInfo.SignatureMarkup = sig.GetMarkup(((NamespaceResolveResult)result).Namespace); } catch (Exception e) { LoggingService.LogError("Got exception while creating markup for :" + ((NamespaceResolveResult)result).Namespace, e); return(new TooltipInformation()); } return(tooltipInfo); } else if (result is OperatorResolveResult) { var or = result as OperatorResolveResult; var tooltipInfo = new TooltipInformation(); var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location); var sig = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions()); sig.BreakLineAfterReturnType = false; try { tooltipInfo.SignatureMarkup = sig.GetMarkup(or.UserDefinedOperatorMethod); } catch (Exception e) { LoggingService.LogError("Got exception while creating markup for :" + ((NamespaceResolveResult)result).Namespace, e); return(new TooltipInformation()); } return(tooltipInfo); } else { return(MemberCompletionData.CreateTooltipInformation( doc.Compilation, file, doc.Editor, doc.GetFormattingPolicy(), result.Type, false, createFooter)); } } catch (Exception e) { LoggingService.LogError("Error while creating tooltip.", e); return(null); } return(null); }
/// <summary> /// Used for canonicalizing bindings after parsing them /// </summary> static string AccelFromKey(Gdk.Key key, Gdk.ModifierType modifier) { bool complete; return(AccelFromKey(key, modifier, out complete)); }
protected override void HandleKeypress(Gdk.Key key, uint unicodeKey, Gdk.ModifierType modifier) { var wnd = window; if (wnd != null) { ListWindowKeyAction action = wnd.ProcessKey(key, modifier); if ((action & ListWindowKeyAction.Complete) == ListWindowKeyAction.Complete) { CompleteWindow(); } if ((action & ListWindowKeyAction.CloseWindow) == ListWindowKeyAction.CloseWindow) { closedLink = (TextLink)wnd.DataProvider; DestroyWindow(); } if ((action & ListWindowKeyAction.Complete) == ListWindowKeyAction.Complete) { GotoNextLink(closedLink); } if ((action & ListWindowKeyAction.Ignore) == ListWindowKeyAction.Ignore) { return; } } int caretOffset = Editor.Caret.Offset - baseOffset; TextLink link = links.Find(l => l.Links.Any(s => s.Offset <= caretOffset && caretOffset <= s.EndOffset)); switch (key) { case Gdk.Key.BackSpace: if (link != null && caretOffset == link.PrimaryLink.Offset) { return; } goto default; case Gdk.Key.space: if (link == null || !link.IsIdentifier) { goto default; } return; case Gdk.Key.Delete: if (link != null && caretOffset == link.PrimaryLink.EndOffset) { return; } goto default; case Gdk.Key.Tab: if ((modifier & Gdk.ModifierType.ControlMask) != 0) { if (link != null && !link.IsIdentifier) { goto default; } } if ((modifier & Gdk.ModifierType.ShiftMask) == 0) { GotoNextLink(link); } else { GotoPreviousLink(link); } return; case Gdk.Key.Escape: case Gdk.Key.Return: case Gdk.Key.KP_Enter: if ((modifier & Gdk.ModifierType.ControlMask) != 0) { if (link != null && !link.IsIdentifier) { goto default; } } if (wnd != null) { CompleteWindow(); } else { ExitTextLinkMode(); } if (key == Gdk.Key.Escape) { OnCancel(EventArgs.Empty); } return; default: wasReplaced = false; base.HandleKeypress(key, unicodeKey, modifier); if (wasReplaced && link == null) { resetCaret = false; ExitTextLinkMode(); } break; } /* if (link != null) * UpdateTextLink (link); * UpdateTextLinks (); * Editor.Document.CommitUpdateAll ();*/ }
static bool BindingToKeysPartial(string binding, out uint modeKey, out Gdk.ModifierType modeModifier, out uint key, out Gdk.ModifierType modifier) { int i = 0; modeModifier = Gdk.ModifierType.None; modeKey = 0; modifier = Gdk.ModifierType.None; key = 0; if (binding == null || binding == String.Empty) { return(false); } if (!AccelToKeyPartial(binding, ref i, out key, out modifier)) { return(false); } if (i == binding.Length) { // no mode in this binding, we're done return(true); } if (binding[i] != '|') { // bad format return(false); } modeModifier = modifier; modeKey = key; i++; return(AccelToKeyPartial(binding, ref i, out key, out modifier) && i == binding.Length); }
/// <summary>Populate the main menu tool strip.</summary> /// <param name="menuDescriptions">Descriptions for each item.</param> public void Populate(List <MenuDescriptionArgs> menuDescriptions) { menu.Clear(); foreach (MenuDescriptionArgs description in menuDescriptions) { MenuItem item; if (description.ShowCheckbox) { CheckMenuItem checkItem = new CheckMenuItem(description.Name); checkItem.Active = description.Checked; item = checkItem; } else { ManifestResourceInfo info = Assembly.GetExecutingAssembly().GetManifestResourceInfo(description.ResourceNameForImage); if (info != null) { MenuItem imageItem = WidgetExtensions.CreateImageMenuItem(description.Name, new Gtk.Image(null, description.ResourceNameForImage)); item = imageItem; } else { item = new MenuItem(description.Name); } } if (!String.IsNullOrEmpty(description.ShortcutKey)) { string keyName = String.Empty; Gdk.ModifierType modifier = Gdk.ModifierType.None; string[] keyNames = description.ShortcutKey.Split(new Char[] { '+' }); foreach (string name in keyNames) { if (name == "Ctrl") { modifier |= Gdk.ModifierType.ControlMask; } else if (name == "Shift") { modifier |= Gdk.ModifierType.ShiftMask; } else if (name == "Alt") { modifier |= Gdk.ModifierType.Mod1Mask; } else if (name == "Del") { keyName = "Delete"; } else { keyName = name; } } try { Gdk.Key accelKey = (Gdk.Key)Enum.Parse(typeof(Gdk.Key), keyName, false); item.AddAccelerator("activate", Accelerators, (uint)accelKey, modifier, AccelFlags.Visible); } catch { } } item.Activated += description.OnClick; if (description.FollowsSeparator && (menu.Children.Length > 0)) { menu.Append(new SeparatorMenuItem()); } menu.Append(item); } menu.ShowAll(); }
public static bool BindingToKeys(string binding, out uint modeKey, out Gdk.ModifierType modeModifier, out uint key, out Gdk.ModifierType modifier) { if (BindingToKeysPartial(binding, out modeKey, out modeModifier, out key, out modifier)) { return(true); } modeModifier = modifier = Gdk.ModifierType.None; modeKey = key = 0; return(false); }
public override void InsertCompletionText(CompletionListWindow window, ref KeyActions ka, Gdk.Key closeChar, char keyChar, Gdk.ModifierType modifier) { string text; var dialog = new MonoDevelop.Ide.Projects.ProjectFileSelectorDialog(proj, "", pattern); try { if (MessageService.RunCustomDialog(dialog) != (int)Gtk.ResponseType.Ok || dialog.SelectedFile == null) { return; } text = pathFunc(dialog.SelectedFile); } finally { dialog.Destroy(); dialog.Dispose(); } window.CompletionWidget.SetCompletionText(window.CodeCompletionContext, "", text); }
// NOTE: changes in this should be mirrored in to Mono.TextEditor/Platform.cs public static void MapRawKeys(Gdk.EventKey evt, out Gdk.Key key, out Gdk.ModifierType mod) { mod = evt.State; key = evt.Key; uint keyval; int effectiveGroup, level; Gdk.ModifierType consumedModifiers; keymap.TranslateKeyboardState(evt.HardwareKeycode, evt.State, evt.Group, out keyval, out effectiveGroup, out level, out consumedModifiers); key = (Gdk.Key)keyval; mod = evt.State & ~consumedModifiers; if (isX11) { //this is a workaround for a common X mapping issue //where the alt key is mapped to the meta key when the shift modifier is active if (key.Equals(Gdk.Key.Meta_L) || key.Equals(Gdk.Key.Meta_R)) { key = Gdk.Key.Alt_L; } } //HACK: the MAC GTK+ port currently does some horrible, un-GTK-ish key mappings // so we work around them by playing some tricks to remap and decompose modifiers. // We also decompose keys to the root physical key so that the Mac command // combinations appear as expected, e.g. shift-{ is treated as shift-[. if (isMac && !isX11) { // Mac GTK+ maps the command key to the Mod1 modifier, which usually means alt/ // We map this instead to meta, because the Mac GTK+ has mapped the cmd key // to the meta key (yay inconsistency!). IMO super would have been saner. if ((mod & Gdk.ModifierType.Mod1Mask) != 0) { mod ^= Gdk.ModifierType.Mod1Mask; mod |= Gdk.ModifierType.MetaMask; } // If Mod5 is active it *might* mean that opt/alt is active, // so we can unset this and map it back to the normal modifier. if ((mod & Gdk.ModifierType.Mod5Mask) != 0) { mod ^= Gdk.ModifierType.Mod5Mask; mod |= Gdk.ModifierType.Mod1Mask; } // When opt modifier is active, we need to decompose this to make the command appear correct for Mac. // In addition, we can only inspect whether the opt/alt key is pressed by examining // the key's "group", because the Mac GTK+ treats opt as a group modifier and does // not expose it as an actual GDK modifier. if (evt.Group == (byte)1) { mod |= Gdk.ModifierType.Mod1Mask; key = GetGroupZeroKey(key, evt); } } //fix shift-tab weirdness. There isn't a nice name for untab, so make it shift-tab if (key == Gdk.Key.ISO_Left_Tab) { key = Gdk.Key.Tab; mod |= Gdk.ModifierType.ShiftMask; } }
public override Gtk.Window CreateTooltipWindow(MonoTextEditor editor, int offset, Gdk.ModifierType modifierState, MonoDevelop.Ide.Editor.TooltipItem item) { var wrappedEditor = WrapEditor(editor); if (wrappedEditor == null) { return(null); } var control = provider.CreateTooltipWindow(wrappedEditor, IdeApp.Workbench.ActiveDocument, item, offset, modifierState.ToXwtValue()); if (control == null) { return(null); } return((Gtk.Window)control); }
/// <summary> /// Creates an item with the specified sub items. And the current /// Condition status for this item. /// </summary> public override object CreateInstance() { IEditAction editAction = (IEditAction)base.CreateInstance(); if (editAction == null) { return(null); } // basically, we want to take a string like: // Control|J and turn it into the value to trigger the edit action // in GTK+ lingo that is a Gdk.Key and Gdk.ModifierType // we assume the order is Modifier|Modifier|Key Gdk.Key key = Gdk.Key.VoidSymbol; Gdk.ModifierType state = Gdk.ModifierType.None; for (int i = 0; i < keys.Length; i++) { string[] keydescr = keys[i].Split('|'); // the last keydescr is the Gdk.Key key = (Gdk.Key)Enum.Parse(typeof(Gdk.Key), keydescr[keydescr.Length - 1]); // the rest, if any, are modifiers for (int j = 0; j < keydescr.Length - 1; j++) { // FIXME: newer gdk's have more values here switch (keydescr[j]) { // ignore the buttons case "Button1": case "Button2": case "Button3": case "Button4": case "Button5": break; case "Control": state |= Gdk.ModifierType.ControlMask; break; // Caps Lock or Shift Lock case "Lock": state |= Gdk.ModifierType.LockMask; break; // this is normally Alt case "Alt": case "Mod1": state |= Gdk.ModifierType.Mod1Mask; break; case "Mod2": state |= Gdk.ModifierType.Mod2Mask; break; case "Mod3": state |= Gdk.ModifierType.Mod3Mask; break; case "Mod4": state |= Gdk.ModifierType.Mod4Mask; break; case "Mod5": state |= Gdk.ModifierType.Mod5Mask; break; // all the modifiers case "Modifier": state |= Gdk.ModifierType.ModifierMask; break; // ignore internal to GTK+ case "Release": break; case "Shift": state |= Gdk.ModifierType.ShiftMask; break; default: break; } } } editAction.Key = key; editAction.State = state; return(editAction); }
protected virtual void OnSetDragSource(Gdk.ModifierType modifierType, Gtk.TargetEntry[] table, Gdk.DragAction actions) { Gtk.Drag.SourceSet(EventsRootWidget, modifierType, table, actions); }
[GLib.ConnectBefore] // Otherwise this is handled internally, and we won't see it private void OnKeyPress(object sender, KeyPressEventArgs e) { try { e.RetVal = false; char keyChar = (char)Gdk.Keyval.ToUnicode(e.Event.KeyValue); Gdk.ModifierType ctlModifier = !APSIM.Shared.Utilities.ProcessUtilities.CurrentOS.IsMac ? Gdk.ModifierType.ControlMask //Mac window manager already uses control-scroll, so use command //Command might be either meta or mod1, depending on GTK version : (Gdk.ModifierType.MetaMask | Gdk.ModifierType.Mod1Mask); bool controlSpace = IsControlSpace(e.Event); bool controlShiftSpace = IsControlShiftSpace(e.Event); string textBeforePeriod = GetWordBeforePosition(textEditor.Caret.Offset); double x; // unused, but needed as an out parameter. if (e.Event.Key == Gdk.Key.F3) { if (string.IsNullOrEmpty(findForm.LookFor)) { findForm.ShowFor(textEditor, false); } else { findForm.FindNext(true, (e.Event.State & Gdk.ModifierType.ShiftMask) == 0, string.Format("Search text «{0}» not found.", findForm.LookFor)); } e.RetVal = true; } // If the text before the period is not a number and the user pressed either one of the intellisense characters or control-space: else if (!double.TryParse(textBeforePeriod.Replace(".", ""), out x) && (IntelliSenseChars.Contains(keyChar.ToString()) || controlSpace || controlShiftSpace)) { // If the user entered a period, we need to take that into account when generating intellisense options. // To do this, we insert a period manually and stop the Gtk signal from propagating further. e.RetVal = true; if (keyChar == '.') { textEditor.InsertAtCaret(keyChar.ToString()); // Process all events in the main loop, so that the period is inserted into the text editor. while (GLib.MainContext.Iteration()) { ; } } NeedContextItemsArgs args = new NeedContextItemsArgs { Coordinates = GetPositionOfCursor(), Code = textEditor.Text, Offset = this.Offset, ControlSpace = controlSpace, ControlShiftSpace = controlShiftSpace, LineNo = textEditor.Caret.Line, ColNo = textEditor.Caret.Column - 1 }; ContextItemsNeeded?.Invoke(this, args); } else if ((e.Event.State & ctlModifier) != 0) { switch (e.Event.Key) { case Gdk.Key.Key_0: textEditor.Options.ZoomReset(); e.RetVal = true; break; case Gdk.Key.KP_Add: case Gdk.Key.plus: textEditor.Options.ZoomIn(); e.RetVal = true; break; case Gdk.Key.KP_Subtract: case Gdk.Key.minus: textEditor.Options.ZoomOut(); e.RetVal = true; break; } } } catch (Exception err) { ShowError(err); } }
protected virtual Action <TextEditorData> GetInsertAction(Gdk.Key key, Gdk.ModifierType modifier) { return(ViActionMaps.GetInsertKeyAction(key, modifier) ?? ViActionMaps.GetDirectionKeyAction(key, modifier)); }
public void SetAccel(uint accelerator_key, Gdk.ModifierType accelerator_mods) { gtk_accel_label_set_accel(Handle, accelerator_key, (int)accelerator_mods); }
protected override void HandleKeypress(Gdk.Key key, uint unicodeKey, Gdk.ModifierType modifier) { ViEditor.ProcessKey(modifier, key, (char)unicodeKey); }
public static Gdk.EventKey CreateKeyEvent(uint keyval, Gdk.ModifierType state, Gdk.EventType eventType, Gdk.Window win) { return(CreateKeyEvent(keyval, -1, state, eventType, win)); }
public override bool KeyPress(Gdk.Key key, char keyChar, Gdk.ModifierType modifier) { bool skipFormatting = StateTracker.Engine.IsInsideOrdinaryCommentOrString || StateTracker.Engine.IsInsidePreprocessorDirective; cursorPositionBeforeKeyPress = textEditorData.Caret.Offset; bool isSomethingSelected = textEditorData.IsSomethingSelected; if (key == Gdk.Key.BackSpace && textEditorData.Caret.Offset == lastInsertedSemicolon) { textEditorData.Document.Undo(); lastInsertedSemicolon = -1; return(false); } lastInsertedSemicolon = -1; if (keyChar == ';' && !(textEditorData.CurrentMode is TextLinkEditMode) && !DoInsertTemplate() && !isSomethingSelected && PropertyService.Get( "SmartSemicolonPlacement", false )) { bool retval = base.KeyPress(key, keyChar, modifier); DocumentLine curLine = textEditorData.Document.GetLine(textEditorData.Caret.Line); string text = textEditorData.Document.GetTextAt(curLine); if (text.EndsWith(";") || text.Trim().StartsWith("for")) { return(retval); } int guessedOffset = GuessSemicolonInsertionOffset(textEditorData, curLine); if (guessedOffset != textEditorData.Caret.Offset) { using (var undo = textEditorData.OpenUndoGroup()) { textEditorData.Remove(textEditorData.Caret.Offset - 1, 1); textEditorData.Caret.Offset = guessedOffset; lastInsertedSemicolon = textEditorData.Caret.Offset + 1; retval = base.KeyPress(key, keyChar, modifier); } } return(retval); } if (key == Gdk.Key.Tab) { stateTracker.UpdateEngine(); if (stateTracker.Engine.IsInsideStringLiteral) { var lexer = new CSharpCompletionEngineBase.MiniLexer(textEditorData.Document.GetTextAt(0, textEditorData.Caret.Offset)); lexer.Parse(); if (lexer.IsInString) { textEditorData.InsertAtCaret("\\t"); return(false); } } } if (key == Gdk.Key.Tab && DefaultSourceEditorOptions.Instance.TabIsReindent && !CompletionWindowManager.IsVisible && !(textEditorData.CurrentMode is TextLinkEditMode) && !DoInsertTemplate() && !isSomethingSelected) { int cursor = textEditorData.Caret.Offset; if (stateTracker.Engine.IsInsideVerbatimString) { // insert normal tab inside @" ... " if (textEditorData.IsSomethingSelected) { textEditorData.SelectedText = "\t"; } else { textEditorData.Insert(cursor, "\t"); textEditorData.Caret.Offset++; } textEditorData.Document.CommitLineUpdate(textEditorData.Caret.Line); } else if (cursor >= 1) { if (textEditorData.Caret.Column > 1) { int delta = cursor - this.cursorPositionBeforeKeyPress; if (delta < 2 && delta > 0) { textEditorData.Remove(cursor - delta, delta); textEditorData.Caret.Offset = cursor - delta; textEditorData.Document.CommitLineUpdate(textEditorData.Caret.Line); } } stateTracker.UpdateEngine(); DoReSmartIndent(); } return(false); } //do the smart indent if (textEditorData.Options.IndentStyle == IndentStyle.Smart || textEditorData.Options.IndentStyle == IndentStyle.Virtual) { bool retval; //capture some of the current state int oldBufLen = textEditorData.Length; int oldLine = textEditorData.Caret.Line + 1; bool hadSelection = textEditorData.IsSomethingSelected; bool reIndent = false; //pass through to the base class, which actually inserts the character //and calls HandleCodeCompletion etc to handles completion using (var undo = textEditorData.OpenUndoGroup()) { DoPreInsertionSmartIndent(key); } retval = base.KeyPress(key, keyChar, modifier); using (var undo = textEditorData.OpenUndoGroup()) { //handle inserted characters if (textEditorData.Caret.Offset <= 0 || textEditorData.IsSomethingSelected) { return(retval); } lastCharInserted = TranslateKeyCharForIndenter(key, keyChar, textEditorData.GetCharAt(textEditorData.Caret.Offset - 1)); if (lastCharInserted == '\0') { return(retval); } stateTracker.UpdateEngine(); if (key == Gdk.Key.Return && modifier == Gdk.ModifierType.ControlMask) { FixLineStart(textEditorData, stateTracker, textEditorData.Caret.Line + 1); } else { if (!(oldLine == textEditorData.Caret.Line + 1 && lastCharInserted == '\n') && (oldBufLen != textEditorData.Length || lastCharInserted != '\0')) { DoPostInsertionSmartIndent(lastCharInserted, hadSelection, out reIndent); } } //reindent the line after the insertion, if needed //N.B. if the engine says we need to reindent, make sure that it's because a char was //inserted rather than just updating the stack due to moving around stateTracker.UpdateEngine(); bool automaticReindent = (stateTracker.Engine.NeedsReindent && lastCharInserted != '\0'); if (reIndent || automaticReindent) { DoReSmartIndent(); } if (!skipFormatting && keyChar == '}') { RunFormatter(new DocumentLocation(textEditorData.Caret.Location.Line, textEditorData.Caret.Location.Column - 1)); } } stateTracker.UpdateEngine(); lastCharInserted = '\0'; return(retval); } if (textEditorData.Options.IndentStyle == IndentStyle.Auto && DefaultSourceEditorOptions.Instance.TabIsReindent && key == Gdk.Key.Tab) { bool retval = base.KeyPress(key, keyChar, modifier); DoReSmartIndent(); return(retval); } //pass through to the base class, which actually inserts the character //and calls HandleCodeCompletion etc to handles completion var result = base.KeyPress(key, keyChar, modifier); if (!skipFormatting && keyChar == '}') { RunFormatter(new DocumentLocation(textEditorData.Caret.Location.Line, textEditorData.Caret.Location.Column - 1)); } return(result); }
public static Gdk.EventKey CreateKeyEventFromKeyCode(ushort keyCode, Gdk.ModifierType state, Gdk.EventType eventType, Gdk.Window win) { return(CreateKeyEvent(0, keyCode, state, eventType, win)); }
void OnEditKeyPress (object sender, KeyPressEventArgs args) { keyHandled = false; keyChar = (char) args.Event.Key; keyValue = args.Event.KeyValue; modifier = args.Event.State; key = args.Event.Key; if ((args.Event.Key == Gdk.Key.Down || args.Event.Key == Gdk.Key.Up)) { keyChar = '\0'; } if (currentCompletionData != null) args.RetVal = keyHandled = CompletionWindowManager.PreProcessKeyEvent (key, keyChar, modifier); }
public override bool KeyPress(Gdk.Key key, char keyChar, Gdk.ModifierType modifier) { if (keyChar != '/') { return(base.KeyPress(key, keyChar, modifier)); } var line = textEditorData.Document.GetLine(textEditorData.Caret.Line); string text = textEditorData.Document.GetTextAt(line.Offset, line.Length); if (!text.EndsWith("//")) { return(base.KeyPress(key, keyChar, modifier)); } // check if there is doc comment above or below. var l = line.PreviousLine; while (l != null && l.Length == 0) { l = l.PreviousLine; } if (l != null && textEditorData.GetTextAt(l).TrimStart().StartsWith("///")) { return(base.KeyPress(key, keyChar, modifier)); } l = line.NextLine; while (l != null && l.Length == 0) { l = l.NextLine; } if (l != null && textEditorData.GetTextAt(l).TrimStart().StartsWith("///")) { return(base.KeyPress(key, keyChar, modifier)); } var member = GetMemberToDocument(); if (member == null) { return(base.KeyPress(key, keyChar, modifier)); } string documentation = GenerateDocumentation(member, textEditorData.Document.GetLineIndent(line)); if (string.IsNullOrEmpty(documentation)) { return(base.KeyPress(key, keyChar, modifier)); } string documentationEmpty = GenerateEmptyDocumentation(member, textEditorData.Document.GetLineIndent(line)); int offset = textEditorData.Caret.Offset; int insertedLength; // Insert key (3rd undo step) textEditorData.Insert(offset, "/"); using (var undo = textEditorData.OpenUndoGroup()) { insertedLength = textEditorData.Replace(offset, 1, documentationEmpty); // important to set the caret position here for the undo step textEditorData.Caret.Offset = offset + insertedLength; } using (var undo = textEditorData.OpenUndoGroup()) { insertedLength = textEditorData.Replace(offset, insertedLength, documentation); if (SelectSummary(offset, insertedLength, documentation) == false) { textEditorData.Caret.Offset = offset + insertedLength; } } return(false); }
protected override Gtk.Window CreateTooltipWindow(Mono.TextEditor.TextEditor editor, int offset, Gdk.ModifierType modifierState, TooltipItem item) { var doc = IdeApp.Workbench.ActiveDocument; if (doc == null) { return(null); } var titem = (ToolTipData)item.Item; var tooltipInformation = CreateTooltip(titem, offset, null, modifierState); if (tooltipInformation == null || string.IsNullOrEmpty(tooltipInformation.SignatureMarkup)) { return(null); } var result = new TooltipInformationWindow(); result.ShowArrow = true; result.AddOverload(tooltipInformation); result.RepositionWindow(); return(result); }
static void MainMenuPosition(Gtk.Menu menu, out int x, out int y, out bool push_in) { Gdk.ModifierType mod = new Gdk.ModifierType(); icon.Screen.RootWindow.GetPointer(out x, out y, out mod); y = menu.Screen.Height - 190; push_in = true; }