public static void IconBarMouseDown(AbstractMargin iconBar, Point mousepos, MouseButtons mouseButtons) { try { if (mouseButtons != MouseButtons.Left) { return; } Rectangle viewRect = iconBar.TextArea.TextView.DrawingPosition; //Point logicPos = iconBar.TextArea.TextView.GetLogicalPosition(0, mousepos.Y - viewRect.Top); ICSharpCode.TextEditor.TextLocation logicPos = iconBar.TextArea.TextView.GetLogicalPosition(0, mousepos.Y - viewRect.Top); if (logicPos.Y >= 0 && logicPos.Y < iconBar.TextArea.Document.TotalNumberOfLines) { string s = iconBar.TextArea.MotherTextEditorControl.FileName; if (s == null) { s = TextAreaHelper.GetFileNameByTextArea(iconBar.TextArea); } ToggleBreakpointAt(iconBar.TextArea.Document, s, logicPos.Y); iconBar.TextArea.Refresh(iconBar); } } catch (System.Exception e) { } }
private static string GetPopupHintText(TextArea textArea, ToolTipRequestEventArgs e) { ICSharpCode.TextEditor.TextLocation logicPos = e.LogicalPosition; IDocument doc = textArea.Document; LineSegment seg = doc.GetLineSegment(logicPos.Y); string FileName = textArea.MotherTextEditorControl.FileName; PascalABCCompiler.Parsers.KeywordKind keyw = PascalABCCompiler.Parsers.KeywordKind.None; if (logicPos.X > seg.Length - 1) { return(null); } //string expr = FindFullExpression(doc.TextContent, seg.Offset + logicPos.X,e.LogicalPosition.Line,e.LogicalPosition.Column); string expr_without_brackets = null; string expr = CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.FindExpressionFromAnyPosition(seg.Offset + logicPos.X, doc.TextContent, e.LogicalPosition.Line, e.LogicalPosition.Column, out keyw, out expr_without_brackets); if (expr == null) { expr = expr_without_brackets; } if (expr_without_brackets == null) { return(null); } List <PascalABCCompiler.Errors.Error> Errors = new List <PascalABCCompiler.Errors.Error>(); PascalABCCompiler.SyntaxTree.expression tree = WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.StandartCompiler.ParsersController.GetExpression("test" + Path.GetExtension(FileName), expr, Errors, new List <PascalABCCompiler.Errors.CompilerWarning>()); bool header = false; if (tree == null || Errors.Count > 0) { Errors.Clear(); tree = WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.StandartCompiler.ParsersController.GetExpression("test" + Path.GetExtension(FileName), expr_without_brackets, Errors, new List <PascalABCCompiler.Errors.CompilerWarning>()); header = true; if (tree == null || Errors.Count > 0) { return(null); } } else { Errors.Clear(); PascalABCCompiler.SyntaxTree.expression tree2 = WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.StandartCompiler.ParsersController.GetExpression("test" + Path.GetExtension(FileName), expr_without_brackets, Errors, new List <PascalABCCompiler.Errors.CompilerWarning>()); //header = true; if (tree2 == null || Errors.Count > 0) { return(null); } //if (tree is PascalABCCompiler.SyntaxTree.new_expr && (tree as PascalABCCompiler.SyntaxTree.new_expr).params_list == null) // tree = tree2; } CodeCompletion.DomConverter dconv = (CodeCompletion.DomConverter)CodeCompletion.CodeCompletionController.comp_modules[FileName]; if (dconv == null) { return(null); } return(dconv.GetDescription(tree, FileName, expr_without_brackets, WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.StandartCompiler.ParsersController, e.LogicalPosition.Line, e.LogicalPosition.Column, keyw, header)); }
public static ascx_SourceCodeEditor setSelectionText(this ascx_SourceCodeEditor codeEditor, Location startLocation, Location endLocation) { return((ascx_SourceCodeEditor)codeEditor.invokeOnThread(() => { var start = new ICSharpCode.TextEditor.TextLocation(startLocation.X - 1, startLocation.Y - 1); var end = new ICSharpCode.TextEditor.TextLocation(endLocation.X - 1, endLocation.Y - 1); var selection = new ICSharpCode.TextEditor.Document.DefaultSelection(codeEditor.document(), start, end); codeEditor.textArea().SelectionManager.SetSelection(selection); codeEditor.caret_Line(start.Line); codeEditor.caret_Column(start.Column); return codeEditor; })); }
public static void IconBarMouseDown(AbstractMargin iconBar, Point mousepos, MouseButtons mouseButtons) { try { if (mouseButtons != MouseButtons.Left) { if (mouseButtons == MouseButtons.Right) { iconBar.TextArea.MotherTextEditorControl.ContextMenuStrip = null; Rectangle viewRect = iconBar.TextArea.TextView.DrawingPosition; ICSharpCode.TextEditor.TextLocation logicPos = iconBar.TextArea.TextView.GetLogicalPosition(0, mousepos.Y - viewRect.Top); if (logicPos.Y >= 0 && logicPos.Y < iconBar.TextArea.Document.TotalNumberOfLines) { cur_bookmark = IsOnBreakpoint(iconBar.TextArea.Document, logicPos.Y); if (cur_bookmark != null) { iconBar.TextArea.MotherTextEditorControl.ContextMenuStrip = VisualPABCSingleton.MainForm.BreakpointMenuStrip; } } } return; } else { Rectangle viewRect = iconBar.TextArea.TextView.DrawingPosition; //Point logicPos = iconBar.TextArea.TextView.GetLogicalPosition(0, mousepos.Y - viewRect.Top); ICSharpCode.TextEditor.TextLocation logicPos = iconBar.TextArea.TextView.GetLogicalPosition(0, mousepos.Y - viewRect.Top); if (logicPos.Y >= 0 && logicPos.Y < iconBar.TextArea.Document.TotalNumberOfLines) { string s = iconBar.TextArea.MotherTextEditorControl.FileName; if (s == null) { s = TextAreaHelper.GetFileNameByTextArea(iconBar.TextArea); } ToggleBreakpointAt(iconBar.TextArea.Document, s, logicPos.Y); iconBar.TextArea.Refresh(iconBar); } } } catch (System.Exception e) { } }
public void InsertAfterCurrentMethod() { IOutputAstVisitor outputVisitor = this.GetOutputVisitor(); using (SpecialNodesInserter.Install(this.specialsList, outputVisitor)) { string code = "\r\n\r\n" + GenerateCode(this.extractedMethod, true); code = code.TrimEnd('\r', '\n', ' ', '\t'); Dom.IMember p = GetParentMember(this.textEditor, this.currentSelection.StartPosition.Line + 1, this.currentSelection.StartPosition.Column + 1); TextLocation loc = new ICSharpCode.TextEditor.TextLocation( p.BodyRegion.EndColumn - 1, p.BodyRegion.EndLine - 1); int offset = textEditor.Document.PositionToOffset(loc); textEditor.Document.Insert(offset, code); } }
public static ascx_SourceCodeEditor setSelectionText(this ascx_SourceCodeEditor codeEditor, Location startLocation, Location endLocation) { return (ascx_SourceCodeEditor)codeEditor.invokeOnThread(() => { var start = new ICSharpCode.TextEditor.TextLocation(startLocation.X - 1, startLocation.Y - 1); var end = new ICSharpCode.TextEditor.TextLocation(endLocation.X - 1, endLocation.Y - 1); var selection = new ICSharpCode.TextEditor.Document.DefaultSelection(codeEditor.document(), start, end); codeEditor.textArea().SelectionManager.SetSelection(selection); codeEditor.caret_Line(start.Line); codeEditor.caret_Column(start.Column); return codeEditor; }); }
public Bookmark CreateBookmark(IDocument document, ICSharpCode.TextEditor.TextLocation location) { return(new BreakpointBookmark(document, location, EditorForm)); }
public BreakpointBookmark(IDocument document, ICSharpCode.TextEditor.TextLocation location, AbstractEditorForm editorForm) : base(document, location) { EditorForm = editorForm; }
private static void makeWordUnderline(object sender, MouseEventArgs e) { try { TextArea textArea = (TextArea)sender; if (gotoInProgress || textArea.SelectionManager.SelectionCollection.Count > 0) { return; } if (Control.ModifierKeys != Keys.Control && textArea.TextView.Cursor == Cursors.IBeam) { return; } //System.Threading.Thread.Sleep(10); //if (textArea != curTextArea) return; var markers = textArea.Document.MarkerStrategy.GetMarkers(0, textArea.Document.TextContent.Length); List <TextMarker> textMarkers = new List <TextMarker>(); foreach (var marker in markers) { if (marker is TextMarker && marker.TextMarkerType == TextMarkerType.Underlined) { textMarkers.Add(marker as TextMarker); } } if (textMarkers.Count > 0 && Control.ModifierKeys != Keys.Control) { textArea.TextView.Cursor = Cursors.IBeam; foreach (var textMarker in textMarkers) { textArea.Document.MarkerStrategy.RemoveMarker(textMarker); } textArea.Refresh(); } if (Control.ModifierKeys != Keys.Control) { textArea.TextView.Cursor = Cursors.IBeam; textArea.Refresh(); } if (Control.ModifierKeys == Keys.Control) { ICSharpCode.TextEditor.TextLocation logicPos = textArea.TextView.GetLogicalPosition(Math.Max(0, e.X - textArea.TextView.DrawingPosition.X), e.Y - textArea.TextView.DrawingPosition.Y); IDocument doc = textArea.Document; logicPos = textArea.Caret.ValidatePosition(logicPos); LineSegment seg = doc.GetLineSegment(logicPos.Y); if (logicPos.X <= seg.Length - 1) { foreach (TextWord tw in seg.Words) { if (tw.Offset <= logicPos.Column && tw.Offset + tw.Length >= logicPos.Column && isIdentifier(tw.Word)) { if (textArea.Document.MarkerStrategy.GetMarkers(seg.Offset + tw.Offset).Count == 0) { foreach (var textMarker in textMarkers) { textArea.Document.MarkerStrategy.RemoveMarker(textMarker); } textArea.Document.MarkerStrategy.AddMarker(new TextMarker(seg.Offset + tw.Offset, tw.Length, TextMarkerType.Underlined, Color.Blue)); textArea.TextView.Cursor = Cursors.Hand; textArea.Refresh(); break; } } } } else { foreach (var textMarker in textMarkers) { textArea.Document.MarkerStrategy.RemoveMarker(textMarker); } textArea.TextView.Cursor = Cursors.IBeam; textArea.Refresh(); } } } catch { } }
private void OnMouseDown(object sender, MouseEventArgs e) { textArea.mousepos = e.Location; Point mousepos = e.Location; if (dodragdrop) { return; } if (doubleclick) { doubleclick = false; return; } if (textArea.TextView.DrawingPosition.Contains(mousepos.X, mousepos.Y)) { gotmousedown = true; textArea.SelectionManager.selectFrom.where = WhereFrom.TArea; button = e.Button; // double-click if (button == MouseButtons.Left && e.Clicks == 2) { int deltaX = Math.Abs(lastmousedownpos.X - e.X); int deltaY = Math.Abs(lastmousedownpos.Y - e.Y); if (deltaX <= SystemInformation.DoubleClickSize.Width && deltaY <= SystemInformation.DoubleClickSize.Height) { DoubleClickSelectionExtend(); lastmousedownpos = new Point(e.X, e.Y); if (textArea.SelectionManager.selectFrom.where == WhereFrom.Gutter) { if (!minSelection.IsEmpty && !maxSelection.IsEmpty && textArea.SelectionManager.SelectionCollection.Count > 0) { textArea.SelectionManager.SelectionCollection[0].StartPosition = minSelection; textArea.SelectionManager.SelectionCollection[0].EndPosition = maxSelection; textArea.SelectionManager.SelectionStart = minSelection; minSelection = TextLocation.Empty; maxSelection = TextLocation.Empty; } } return; } } minSelection = TextLocation.Empty; maxSelection = TextLocation.Empty; lastmousedownpos = mousedownpos = new Point(e.X, e.Y); if (button == MouseButtons.Left) { FoldMarker marker = textArea.TextView.GetFoldMarkerFromPosition(mousepos.X - textArea.TextView.DrawingPosition.X, mousepos.Y - textArea.TextView.DrawingPosition.Y); if (marker != null && marker.IsFolded) { if (textArea.SelectionManager.HasSomethingSelected) { clickedOnSelectedText = true; } TextLocation startLocation = new TextLocation(marker.StartColumn, marker.StartLine); TextLocation endLocation = new TextLocation(marker.EndColumn, marker.EndLine); textArea.SelectionManager.SetSelection(new DefaultSelection(textArea.TextView.Document, startLocation, endLocation)); textArea.Caret.Position = startLocation; textArea.SetDesiredColumn(); textArea.Focus(); return; } if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) { ExtendSelectionToMouse(); } else { TextLocation realmousepos = textArea.TextView.GetLogicalPosition(mousepos.X - textArea.TextView.DrawingPosition.X, mousepos.Y - textArea.TextView.DrawingPosition.Y); clickedOnSelectedText = false; int offset = textArea.Document.PositionToOffset(realmousepos); if (textArea.SelectionManager.HasSomethingSelected && textArea.SelectionManager.IsSelected(offset)) { clickedOnSelectedText = true; } else { textArea.SelectionManager.ClearSelection(); if (mousepos.Y > 0 && mousepos.Y < textArea.TextView.DrawingPosition.Height) { TextLocation pos = new TextLocation(); pos.Y = Math.Min(textArea.Document.TotalNumberOfLines - 1, realmousepos.Y); pos.X = realmousepos.X; textArea.Caret.Position = pos; textArea.SetDesiredColumn(); } } } } else if (button == MouseButtons.Right) { // Rightclick sets the cursor to the click position unless // the previous selection was clicked TextLocation realmousepos = textArea.TextView.GetLogicalPosition(mousepos.X - textArea.TextView.DrawingPosition.X, mousepos.Y - textArea.TextView.DrawingPosition.Y); int offset = textArea.Document.PositionToOffset(realmousepos); if (!textArea.SelectionManager.HasSomethingSelected || !textArea.SelectionManager.IsSelected(offset)) { textArea.SelectionManager.ClearSelection(); if (mousepos.Y > 0 && mousepos.Y < textArea.TextView.DrawingPosition.Height) { TextLocation pos = new TextLocation(); pos.Y = Math.Min(textArea.Document.TotalNumberOfLines - 1, realmousepos.Y); pos.X = realmousepos.X; textArea.Caret.Position = pos; textArea.SetDesiredColumn(); } } } } textArea.Focus(); }
private void ExtendSelectionToMouse() { Point mousepos = textArea.mousepos; TextLocation realmousepos = textArea.TextView.GetLogicalPosition(Math.Max(0, mousepos.X - textArea.TextView.DrawingPosition.X), mousepos.Y - textArea.TextView.DrawingPosition.Y); //int y = realmousepos.Y; realmousepos = textArea.Caret.ValidatePosition(realmousepos); TextLocation oldPos = textArea.Caret.Position; if (oldPos == realmousepos && textArea.SelectionManager.selectFrom.where != WhereFrom.Gutter) { return; } // the selection is from the gutter if (textArea.SelectionManager.selectFrom.where == WhereFrom.Gutter) { if (realmousepos.Y < textArea.SelectionManager.SelectionStart.Y) { // the selection has moved above the startpoint textArea.Caret.Position = new TextLocation(0, realmousepos.Y); } else { // the selection has moved below the startpoint textArea.Caret.Position = textArea.SelectionManager.NextValidPosition(realmousepos.Y); } } else { textArea.Caret.Position = realmousepos; } // moves selection across whole words for double-click initiated selection if (!minSelection.IsEmpty && textArea.SelectionManager.SelectionCollection.Count > 0 && textArea.SelectionManager.selectFrom.where == WhereFrom.TArea) { // Extend selection when selection was started with double-click //ISelection selection = textArea.SelectionManager.SelectionCollection[0]; TextLocation min = textArea.SelectionManager.GreaterEqPos(minSelection, maxSelection) ? maxSelection : minSelection; TextLocation max = textArea.SelectionManager.GreaterEqPos(minSelection, maxSelection) ? minSelection : maxSelection; if (textArea.SelectionManager.GreaterEqPos(max, realmousepos) && textArea.SelectionManager.GreaterEqPos(realmousepos, min)) { textArea.SelectionManager.SetSelection(min, max); } else if (textArea.SelectionManager.GreaterEqPos(max, realmousepos)) { int moff = textArea.Document.PositionToOffset(realmousepos); min = textArea.Document.OffsetToPosition(FindWordStart(textArea.Document, moff)); textArea.SelectionManager.SetSelection(min, max); } else { int moff = textArea.Document.PositionToOffset(realmousepos); max = textArea.Document.OffsetToPosition(FindWordEnd(textArea.Document, moff)); textArea.SelectionManager.SetSelection(min, max); } } else { textArea.SelectionManager.ExtendSelection(oldPos, textArea.Caret.Position); } textArea.SetDesiredColumn(); }
public void InsertAfterCurrentMethod() { IOutputAstVisitor outputVisitor = this.GetOutputVisitor(); using (SpecialNodesInserter.Install(this.specialsList, outputVisitor)) { string code = "\r\n\r\n" + GenerateCode(this.extractedMethod, true); code = code.TrimEnd('\r', '\n', ' ', '\t'); Dom.IMember p = GetParentMember(this.textEditor, this.currentSelection.StartPosition.Line + 1, this.currentSelection.StartPosition.Column + 1); TextLocation loc = new ICSharpCode.TextEditor.TextLocation( p.BodyRegion.EndColumn - 1, p.BodyRegion.EndLine - 1); int offset = textEditor.Document.PositionToOffset(loc); textEditor.Document.Insert(offset, code); } }
public ToolTipRequestEventArgs(Point mousePosition, TextLocation logicalPosition, bool inDocument) { this.mousePosition = mousePosition; this.logicalPosition = logicalPosition; this.inDocument = inDocument; }
public void HandleMouseDown(Point mousepos, MouseButtons mouseButtons) { TextLocation selectionStartPos; TextArea.SelectionManager.WhereFrom = SelSource.Gutter; int realline = TextArea.GetLogicalLine(mousepos.Y); bool isRect = (Control.ModifierKeys & Keys.Alt) != 0; if (realline >= 0 && realline < TextArea.Document.TotalNumberOfLines) { // shift-select if ((Control.ModifierKeys & Keys.Shift) != 0) { if (!TextArea.SelectionManager.HasSomethingSelected && realline != TextArea.Caret.Position.Y) { if (realline >= TextArea.Caret.Position.Y) { // at or below starting selection, place the cursor on the next line // nothing is selected so make a new selection from cursor selectionStartPos = TextArea.Caret.Position; // whole line selection - start of line to start of next line if (realline < TextArea.Document.TotalNumberOfLines - 1) { TextArea.SelectionManager.SetSelection(selectionStartPos, new TextLocation(0, realline + 1), isRect); TextArea.Caret.Position = new TextLocation(0, realline + 1); } else { TextArea.SelectionManager.SetSelection(selectionStartPos, new TextLocation(TextArea.Document.GetLineSegment(realline).Length + 1, realline), isRect); TextArea.Caret.Position = new TextLocation(TextArea.Document.GetLineSegment(realline).Length + 1, realline); } } else { // prior lines to starting selection, place the cursor on the same line as the new selection // nothing is selected so make a new selection from cursor selectionStartPos = TextArea.Caret.Position; // whole line selection - start of line to start of next line TextArea.SelectionManager.SetSelection(selectionStartPos, new TextLocation(0, realline + 1), isRect); // textArea.SelectionManager.SetSelection(selectionStartPos, new TextLocation(selectionStartPos.X, selectionStartPos.Y), isRect); // textArea.SelectionManager.ExtendSelection(new TextLocation(selectionStartPos.X, selectionStartPos.Y), new TextLocation(0, realline), false); TextArea.Caret.Position = new TextLocation(0, realline); } } else { // let MouseMove handle a shift-click in a gutter MouseEventArgs e = new MouseEventArgs(mouseButtons, 1, mousepos.X, mousepos.Y, 0); TextArea.RaiseMouseMove(e); } } else // this is a new selection with no shift-key { // sync the textareamousehandler mouse location // (fixes problem with clicking out into a menu then back to the gutter whilst there is a selection) TextArea.MousePos = mousepos; selectionStartPos = new TextLocation(0, realline); //textArea.SelectionManager.ClearSelection(); // whole line selection - start of line to start of next line if (realline < TextArea.Document.TotalNumberOfLines - 1) { TextArea.SelectionManager.SetSelection(selectionStartPos, new TextLocation(selectionStartPos.X, selectionStartPos.Y + 1), isRect); TextArea.Caret.Position = new TextLocation(selectionStartPos.X, selectionStartPos.Y + 1); } else { TextArea.SelectionManager.SetSelection(new TextLocation(0, realline), new TextLocation(TextArea.Document.GetLineSegment(realline).Length + 1, selectionStartPos.Y), isRect); TextArea.Caret.Position = new TextLocation(TextArea.Document.GetLineSegment(realline).Length + 1, selectionStartPos.Y); } } } }