internal protected override void MouseHover(MarginMouseEventArgs args) { base.MouseHover(args); if (!args.TriggersContextMenu() && args.Button == PointerButton.Left) { // DocumentLocation loc = editor.Document.LogicalToVisualLocation (editor.GetTextEditorData (), editor.Caret.Location); int lineNumber = args.LineNumber >= DocumentLocation.MinLine ? args.LineNumber : editor.Document.LineCount; editor.Caret.PreserveSelection = true; editor.Caret.Location = new DocumentLocation(lineNumber, DocumentLocation.MinColumn); editor.MainSelection = new Selection(anchorLocation, editor.Caret.Location); editor.Caret.PreserveSelection = false; } }
void OnIconButtonPress (object s, MarginMouseEventArgs args) { if (args.TriggersContextMenu ()) { TextEditor.Caret.Line = args.LineNumber; TextEditor.Caret.Column = 1; IdeApp.CommandService.ShowContextMenu (WorkbenchWindow.ExtensionContext, "/MonoDevelop/SourceEditor2/IconContextMenu/Editor"); } else if (args.Button == 1) { if (!string.IsNullOrEmpty (this.Document.FileName)) { if (args.LineSegment != null) DebuggingService.Breakpoints.Toggle (this.Document.FileName, args.LineNumber); } } }
protected internal override void MousePressed (MarginMouseEventArgs args) { base.MousePressed (args); if (args.TriggersContextMenu ()) return; InSelectionDrag = false; inDrag = false; Selection selection = textEditor.MainSelection; int oldOffset = textEditor.Caret.Offset; string link = GetLink != null ? GetLink (args) : null; if (!String.IsNullOrEmpty (link)) { textEditor.FireLinkEvent (link, args.Button, args.ModifierState); return; } if (args.Button == 1) { if (!CalculateClickLocation (args.X, args.Y, out clickLocation)) return; DocumentLine line = Document.GetLine (clickLocation.Line); bool isHandled = false; if (line != null) { foreach (TextLineMarker marker in line.Markers) { if (marker is IActionTextLineMarker) { isHandled |= ((IActionTextLineMarker)marker).MousePressed (textEditor, args); if (isHandled) break; } } foreach (var marker in Document.GetTextSegmentMarkersAt (line).Where (m => m.IsVisible)) { if (marker is IActionTextLineMarker) { isHandled |= ((IActionTextLineMarker)marker).MousePressed (textEditor, args); if (isHandled) break; } } } if (isHandled) return; int offset = Document.LocationToOffset (clickLocation); if (offset < 0) { textEditor.RunAction (CaretMoveActions.ToDocumentEnd); return; } if (args.Button == 2 && !selection.IsEmpty && selection.Contains (Document.OffsetToLocation (offset))) { textEditor.ClearSelection (); return; } if (args.Type == EventType.TwoButtonPress) { var data = textEditor.GetTextEditorData (); mouseWordStart = data.FindCurrentWordStart (offset); mouseWordEnd = data.FindCurrentWordEnd (offset); Caret.Offset = mouseWordEnd; textEditor.MainSelection = new Selection (textEditor.Document.OffsetToLocation (mouseWordStart), textEditor.Document.OffsetToLocation (mouseWordEnd)); InSelectionDrag = true; mouseSelectionMode = MouseSelectionMode.Word; // folding marker int lineNr = args.LineNumber; foreach (var shownFolding in GetFoldRectangles (lineNr)) { if (shownFolding.Item1.Contains ((int)(args.X + this.XOffset), (int)args.Y)) { shownFolding.Item2.IsFolded = false; return; } } return; } else if (args.Type == EventType.ThreeButtonPress) { int lineNr = Document.OffsetToLineNumber (offset); textEditor.SetSelectLines (lineNr, lineNr); var range = textEditor.SelectionRange; mouseWordStart = range.Offset; mouseWordEnd = range.EndOffset; InSelectionDrag = true; mouseSelectionMode = MouseSelectionMode.WholeLine; return; } mouseSelectionMode = MouseSelectionMode.SingleChar; if (textEditor.IsSomethingSelected && textEditor.SelectionRange.Offset <= offset && offset < textEditor.SelectionRange.EndOffset && clickLocation != textEditor.Caret.Location) { inDrag = true; } else { if ((args.ModifierState & Gdk.ModifierType.ShiftMask) == ModifierType.ShiftMask) { InSelectionDrag = true; Caret.PreserveSelection = true; if (!textEditor.IsSomethingSelected) { textEditor.MainSelection = new Selection (Caret.Location, clickLocation); Caret.Location = clickLocation; } else { Caret.Location = clickLocation; textEditor.ExtendSelectionTo (clickLocation); } Caret.PreserveSelection = false; } else { textEditor.ClearSelection (); Caret.Location = clickLocation; InSelectionDrag = true; textEditor.SetSelection (clickLocation, clickLocation); } textEditor.RequestResetCaretBlink (); } } DocumentLocation docLocation = PointToLocation (args.X, args.Y); if (docLocation.Line < DocumentLocation.MinLine || docLocation.Column < DocumentLocation.MinColumn) return; // disable middle click on windows. if (!Platform.IsWindows && args.Button == 2 && this.textEditor.CanEdit (docLocation.Line)) { TextSegment selectionRange = TextSegment.Invalid; int offset = Document.LocationToOffset (docLocation); if (!selection.IsEmpty) selectionRange = selection.GetSelectionRange (this.textEditor.GetTextEditorData ()); var oldVersion = textEditor.Document.Version; bool autoScroll = textEditor.Caret.AutoScrollToCaret; textEditor.Caret.AutoScrollToCaret = false; if (!selection.IsEmpty && selectionRange.Contains (offset)) { textEditor.ClearSelection (); textEditor.Caret.Offset = selectionRange.EndOffset; return; } ClipboardActions.PasteFromPrimary (textEditor.GetTextEditorData (), offset); textEditor.Caret.Offset = oldOffset; if (!selectionRange.IsInvalid) textEditor.SelectionRange = new TextSegment (oldVersion.MoveOffsetTo (Document.Version, selectionRange.Offset), selectionRange.Length); if (autoScroll) textEditor.Caret.ActivateAutoScrollWithoutMove (); } }
void OnIconButtonPress (object s, MarginMouseEventArgs args) { if (args.LineNumber < Mono.TextEditor.DocumentLocation.MinLine) return; if (args.TriggersContextMenu ()) { if (TextEditor.Caret.Line != args.LineNumber) { TextEditor.Caret.Line = args.LineNumber; TextEditor.Caret.Column = 1; } IdeApp.CommandService.ShowContextMenu ( TextEditor, args.RawEvent as Gdk.EventButton, WorkbenchWindow.ExtensionContext ?? AddinManager.AddinEngine, "/MonoDevelop/SourceEditor2/IconContextMenu/Editor"); } else if (args.Button == 1) { if (!string.IsNullOrEmpty (Document.FileName)) { if (args.LineSegment != null) { int column = TextEditor.Caret.Line == args.LineNumber ? TextEditor.Caret.Column : 1; lock (breakpoints) breakpoints.Toggle (Document.FileName, args.LineNumber, column); } } } }
protected internal override void MousePressed (MarginMouseEventArgs args) { base.MousePressed (args); if (args.TriggersContextMenu ()) return; inSelectionDrag = false; inDrag = false; Selection selection = textEditor.MainSelection; int anchor = selection != null ? selection.GetAnchorOffset (this.textEditor.GetTextEditorData ()) : -1; int oldOffset = textEditor.Caret.Offset; string link = GetLink != null ? GetLink (args) : null; if (!String.IsNullOrEmpty (link)) { textEditor.FireLinkEvent (link, args.Button, args.ModifierState); return; } if (args.Button == 1) { VisualLocationTranslator trans = new VisualLocationTranslator (this); clickLocation = trans.PointToLocation (args.X, args.Y); if (clickLocation.Line < DocumentLocation.MinLine || clickLocation.Column < DocumentLocation.MinColumn) return; LineSegment line = Document.GetLine (clickLocation.Line); bool isHandled = false; if (line != null) { foreach (TextMarker marker in line.Markers) { if (marker is IActionTextMarker) { isHandled |= ((IActionTextMarker)marker).MousePressed (this.textEditor, args); if (isHandled) break; } } } if (isHandled) return; if (line != null && clickLocation.Column >= line.Length + 1 && GetWidth (Document.GetTextAt (line.SegmentIncludingDelimiter) + "-") < args.X) { clickLocation = new DocumentLocation (clickLocation.Line, line.Length + 1); if (textEditor.GetTextEditorData ().HasIndentationTracker && textEditor.Options.IndentStyle == IndentStyle.Virtual) { int indentationColumn = this.textEditor.GetTextEditorData ().GetVirtualIndentationColumn (clickLocation); if (indentationColumn > clickLocation.Column) clickLocation = new DocumentLocation (clickLocation.Line, indentationColumn); } } int offset = Document.LocationToOffset (clickLocation); if (offset < 0) { textEditor.RunAction (CaretMoveActions.ToDocumentEnd); return; } if (args.Button == 2 && selection != null && selection.Contains (Document.OffsetToLocation (offset))) { textEditor.ClearSelection (); return; } if (args.Type == EventType.TwoButtonPress) { var data = textEditor.GetTextEditorData (); mouseWordStart = data.FindCurrentWordStart (offset); mouseWordEnd = data.FindCurrentWordEnd (offset); Caret.Offset = mouseWordEnd; textEditor.MainSelection = new Selection (textEditor.Document.OffsetToLocation (mouseWordStart), textEditor.Document.OffsetToLocation (mouseWordEnd)); inSelectionDrag = true; mouseSelectionMode = MouseSelectionMode.Word; return; } else if (args.Type == EventType.ThreeButtonPress) { int lineNr = Document.OffsetToLineNumber (offset); textEditor.SetSelectLines (lineNr, lineNr); inSelectionDrag = true; mouseSelectionMode = MouseSelectionMode.WholeLine; return; } mouseSelectionMode = MouseSelectionMode.SingleChar; if (textEditor.IsSomethingSelected && textEditor.SelectionRange.Offset <= offset && offset < textEditor.SelectionRange.EndOffset && clickLocation != textEditor.Caret.Location) { inDrag = true; } else { if ((args.ModifierState & Gdk.ModifierType.ShiftMask) == ModifierType.ShiftMask) { inSelectionDrag = true; Caret.PreserveSelection = true; if (!textEditor.IsSomethingSelected) { textEditor.MainSelection = new Selection (Caret.Location, clickLocation); Caret.Location = clickLocation; } else { Caret.Location = clickLocation; textEditor.ExtendSelectionTo (clickLocation); } Caret.PreserveSelection = false; } else { inSelectionDrag = false; textEditor.ClearSelection (); Caret.Location = clickLocation; } textEditor.RequestResetCaretBlink (); } } DocumentLocation docLocation = PointToLocation (args.X, args.Y); if (docLocation.Line < DocumentLocation.MinLine || docLocation.Column < DocumentLocation.MinColumn) return; // disable middle click on windows. if (!Platform.IsWindows && args.Button == 2 && this.textEditor.CanEdit (docLocation.Line)) { TextSegment selectionRange = TextSegment.Invalid; int offset = Document.LocationToOffset (docLocation); if (selection != null) selectionRange = selection.GetSelectionRange (this.textEditor.GetTextEditorData ()); bool autoScroll = textEditor.Caret.AutoScrollToCaret; textEditor.Caret.AutoScrollToCaret = false; int length = ClipboardActions.PasteFromPrimary (textEditor.GetTextEditorData (), offset); textEditor.Caret.Offset = oldOffset; if (selection != null) { if (offset < selectionRange.EndOffset) { oldOffset += length; anchor += length; selection = new Selection (Document.OffsetToLocation (selectionRange.Offset + length), Document.OffsetToLocation (selectionRange.Offset + length + selectionRange.Length)); } textEditor.MainSelection = selection; } if (autoScroll) textEditor.Caret.ActivateAutoScrollWithoutMove (); } }
internal protected override void MouseHover (MarginMouseEventArgs args) { base.MouseHover (args); if (!args.TriggersContextMenu () && args.Button == 1) { // DocumentLocation loc = editor.Document.LogicalToVisualLocation (editor.GetTextEditorData (), editor.Caret.Location); int lineNumber = args.LineNumber >= DocumentLocation.MinLine ? args.LineNumber : editor.Document.LineCount; editor.Caret.PreserveSelection = true; editor.Caret.Location = new DocumentLocation (lineNumber, DocumentLocation.MinColumn); editor.MainSelection = new Selection (anchorLocation, editor.Caret.Location); editor.Caret.PreserveSelection = false; } }
void OnIconButtonPress (object s, MarginMouseEventArgs args) { if (args.LineNumber < DocumentLocation.MinLine) return; if (args.TriggersContextMenu ()) { if (TextEditor.Caret.Line != args.LineNumber) { TextEditor.Caret.Line = args.LineNumber; TextEditor.Caret.Column = 1; } IdeApp.CommandService.ShowContextMenu (TextEditor, args.RawEvent as Gdk.EventButton, "/MonoDevelop/SourceEditor2/IconContextMenu/Editor"); } else if (args.Button == 1) { if (!string.IsNullOrEmpty (this.Document.FileName)) { if (args.LineSegment != null) { int column = TextEditor.Caret.Line == args.LineNumber ? TextEditor.Caret.Column : 1; DebuggingService.Breakpoints.Toggle (this.Document.FileName, args.LineNumber, column); } } } }