public AutoCompleteForm(TextView view, TextControl owner, TextBufferLocation location, ITextAutoCompletionList list) { this.InitializeComponent(); this._pickedItem = string.Empty; this._list = list; foreach (TextAutoCompletionItem item in list.Items) { this._itemList.Items.Add(item); } this._view = view; this._nextHandler = this._view.AddCommandHandler(this); this._owner = owner; if (location.ColumnIndex == location.Line.Length) { this._startLocation = location.Clone(); } else { using (TextBufferSpan span = this._view.GetWordSpan(location)) { this._startLocation = span.Start.Clone(); } } this._timer = new Timer(); this._timer.Interval = 500; this._timer.Tick += new EventHandler(this.OnTimerTick); }
protected override void ShowHelp(IServiceProvider provider, TextBufferLocation location) { ITextLanguage codeLanguage = this.GetCodeLanguage(provider); if (codeLanguage != null) { codeLanguage.ShowHelp(provider, location); } }
public TextBufferCommand(int command, TextBufferLocation startLocation, TextBufferLocation endLocation, bool selecting, Point p, int commandVal, object data) : base(typeof(TextBufferCommands), command, new object()) { this._startLocation = startLocation; this._endLocation = endLocation; this._selecting = selecting; this._point = p; this._value = commandVal; this._data = data; }
public TextBufferSpan(TextBufferLocation start, TextBufferLocation end) { if ((start.LineIndex > end.LineIndex) || ((start.LineIndex == end.LineIndex) && (start.ColumnIndex > end.ColumnIndex))) { this._start = end; this._end = start; } else { this._start = start; this._end = end; } }
protected override void ShowHelp(IServiceProvider serviceProvider, TextBufferLocation location) { IClassViewService service = (IClassViewService) serviceProvider.GetService(typeof(IClassViewService)); if (service != null) { using (TextBufferSpan span = ((ITextLanguage) this).GetWordSpan(location, WordType.Current)) { if (span != null) { service.ShowType(span.Text); } } } }
internal TextView(TextControl owner, TextBuffer buffer, TextManager manager) { this._textManager = manager; this._owner = owner; this._buffer = buffer; this._location = this._buffer.CreateTextBufferLocation(); this._location.LocationChanged += new EventHandler(this.OnLocationChanged); this._selectionStart = this._buffer.CreateTextBufferLocation(); this._selectionEnd = this._buffer.CreateTextBufferLocation(); this._buffer.TextBufferChanged += new TextBufferEventHandler(this.OnTextBufferChanged); base.SetStyle(ControlStyles.UserPaint, true); base.SetStyle(ControlStyles.AllPaintingInWmPaint, true); base.SetStyle(ControlStyles.Opaque, true); base.SetStyle(ControlStyles.DoubleBuffer, true); base.SetStyle(ControlStyles.ResizeRedraw, true); this._horizontalScrollBar = new HScrollBar(); this._horizontalScrollBar.Cursor = Cursors.Arrow; this._horizontalScrollBar.Scroll += new ScrollEventHandler(this.OnHorizontalScrollBarScroll); if (this._buffer.MaxLine != null) { this._viewMaxLineLength = this.GetViewIndex(this._buffer.MaxLine, this._buffer.MaxLineLength); } else { this._viewMaxLineLength = 0; } this._horizontalScrollBar.Maximum = this._viewMaxLineLength; this._verticalScrollBar = new VScrollBar(); this._verticalScrollBar.Cursor = Cursors.Arrow; this._verticalScrollBar.Scroll += new ScrollEventHandler(this.OnVerticalScrollBarScroll); this._verticalScrollBar.Maximum = this._buffer.LineCount; this.Cursor = Cursors.IBeam; this._viewTopLineNumber = 0; this._caretWidth = 2; this._insertMode = true; base.Controls.Add(this._verticalScrollBar); base.Controls.Add(this._horizontalScrollBar); this.AddCommandHandler(new PlainTextViewCommandHandler(this, this._buffer)); this.AllowDrop = true; }
private Point ColorizeLine(TextBufferLocation colorLocation) { int lineIndex = colorLocation.LineIndex; int y = colorLocation.LineIndex; if (this.Colorizer != null) { TextLine line = colorLocation.Line; lineIndex = colorLocation.LineIndex; int num3 = 0; int initialColorState = 0; TextLine previous = line; while ((previous.Previous != null) && previous.Previous.AttributesDirty) { previous = previous.Previous; lineIndex--; } initialColorState = (previous.Previous == null) ? 0 : previous.Previous.ColorState; while (previous != line) { char[] data = previous.Data; if (data != null) { previous.SetColorState(this.Colorizer.Colorize(data, previous.Attributes, 0, previous.Length, initialColorState)); previous.SetAttributesDirty(false); initialColorState = previous.ColorState; } else { initialColorState = 0; } previous = previous.Next; num3++; } int colorState = line.ColorState; bool flag = true; while ((previous != null) && flag) { char[] text = previous.Data; colorState = previous.ColorState; previous.SetColorState(this.Colorizer.Colorize(text, previous.Attributes, 0, previous.Length, initialColorState)); previous.SetAttributesDirty(false); flag = colorState != previous.ColorState; initialColorState = previous.ColorState; previous = previous.Next; num3++; } y = lineIndex + num3; } return new Point(lineIndex, y); }
private void Initialize() { this.UndoStack.Clear(); this.RedoStack.Clear(); TextLine line = new TextLine(); this._first = new TextBufferLocation(line, 0, 0, this); this.LocationList.Clear(); this._last = this.CreateTextBufferLocation(); this._lineCount = 1; }
protected override void OnDragEnter(DragEventArgs e) { if (this.TextLanguage.SupportsDataObject(this.ServiceProvider, e.Data)) { this.ShowCaret(false); if (this._owner.DraggingInternal & ((e.KeyState & 8) == 0)) { e.Effect = DragDropEffects.Move; } else { e.Effect = DragDropEffects.Copy; } } else { e.Effect = DragDropEffects.None; } this._preDragLocation = this._buffer.CreateTextBufferLocation(this._location); this._owner.FireDragEnter(e); }
private void InsertText(TextBufferLocation location, ArrayList textList, bool addToUndo) { this.InsertText(location, textList, addToUndo, false); }
private bool InsertChar(TextBufferLocation location, char c, bool addToUndo) { if (!this._undoing) { this.RedoStack.Clear(); } TextLine line = location.Line; int columnIndex = location.ColumnIndex; if (columnIndex == line.Length) { line.Append(c); } else { line.Insert(columnIndex, c); } if (line == this._last.Line) { this._last.ColumnIndex = line.Length; } if (line.Length > this._maxLineLength) { this._maxLineLength = line.Length; this._maxLine = line; } if (addToUndo) { this.AddUndo(1, location.LineIndex, columnIndex, c); } int lineIndex = location.LineIndex; this.OnTextBufferChanged(new TextBufferEventArgs(lineIndex, columnIndex, lineIndex, columnIndex, lineIndex, columnIndex + 1)); location.ColumnIndex++; return true; }
private void TrimTrailingWhitespace(TextBufferLocation location) { this._trimmingWhitespace = true; try { TextLine line = location.Line; int length = line.Length; int num2 = length; while ((num2 > 0) && char.IsWhiteSpace(line[num2 - 1])) { num2--; } if (length != num2) { using (TextBufferLocation location2 = location.Clone()) { location2.ColumnIndex = num2; location.ColumnIndex = length; this._buffer.DeleteText(new TextBufferSpan(location2, location)); } } } finally { this._trimmingWhitespace = false; } }
private void ProcessUndoUnit(UndoUnit unit, TextBufferLocation location) { TextBufferLocation location2 = this.CreateTextBufferLocation(); location2.GotoLine(unit.StartLineNum); location2.ColumnIndex = unit.StartIndex; switch (unit.Command) { case 1: this.DeleteChar(location2, false); break; case 2: this.InsertChar(location2, (char) unit.Data, false); break; case 3: this.InsertText(location2, (ArrayList) unit.Data, false); break; case 4: { TextBufferLocation end = this.CreateTextBufferLocation(); end.GotoLine(unit.EndLineNum); end.ColumnIndex = unit.EndIndex; this.DeleteText(new TextBufferSpan(location2, end), false); end.Dispose(); break; } } if (location != null) { location.SetLine(location2.Line, location2.LineIndex); location.ColumnIndex = location2.ColumnIndex; } location2.Dispose(); }
public void ShowHint(TextBufferLocation hintLocation, string text, string highlightText) { if (this._autoCompleteHint == null) { this._autoCompleteHint = new AutoCompleteLabel(text, highlightText); int x = (((this._fontWidth * (this.GetViewIndex(hintLocation) - this.ViewLeftIndex)) + this.MarginPadding) + this.MarginWidth) + this._lineNumbersWidth; int y = ((hintLocation.LineIndex + 1) - this.ViewTopLineNumber) * this._fontHeight; if ((this._autoCompleteHint.Height + y) > base.Height) { y = (y - this._autoCompleteHint.Height) - this._fontHeight; if (y < 0) { this.HideHint(); return; } } if ((this._autoCompleteHint.Width + x) > base.Width) { x -= this._autoCompleteHint.Width; if (x < 0) { this.HideHint(); return; } } this._autoCompleteHint.Location = new Point(x, y); base.Controls.Add(this._autoCompleteHint); this._autoCompleteHint.Visible = true; } else if (text == this._autoCompleteHint.Text) { this.SetHintHighlightText(highlightText); } }
private int InsertTab(TextBufferLocation location) { if (this._view.ConvertTabsToSpaces) { int num = this._view.TabSize - (location.ColumnIndex % this._view.TabSize); char[] chArray = new char[num]; for (int i = 0; i < num; i++) { chArray[i] = ' '; } ArrayList textList = new ArrayList(); textList.Add(chArray); this._buffer.InsertText(location, textList); return num; } this._buffer.InsertChar(location, '\t'); return 1; }
public TextBufferCommand(int command, TextBufferLocation startLocation, bool selecting, Point p) : this(command, startLocation, null, selecting, p, -1, null) { }
private void InsertText(TextBufferLocation location, ArrayList textList, bool addToUndo, bool loading) { if (!this._undoing) { this.RedoStack.Clear(); } int count = textList.Count; if (count >= 1) { TextLine line = location.Line; int lineIndex = location.LineIndex; int columnIndex = location.ColumnIndex; TextLine next = line; int lineNum = lineIndex; int index = columnIndex; int lineIndexDelta = 0; bool flag = columnIndex < line.Length; for (int i = 0; i < count; i++) { char[] chars = (char[]) textList[i]; int length = chars.Length; int num9 = 0; if (i > 0) { next = next.Next; lineNum++; } if (length > 0) { next.Insert(index, chars, 0, length); if (next == this._last.Line) { this._last.ColumnIndex = next.Length; } num9 = next.Length; if (num9 > this._maxLineLength) { this._maxLineLength = num9; this._maxLine = next; } index += length; } if (i < (count - 1)) { if (flag) { this.SplitLine(next, lineNum, index, true); } else { this.InsertLine(next, lineNum, true); } lineIndexDelta++; index = 0; } } this.FixLocationLineNumbers(lineIndex, lineIndexDelta, next, lineNum, index); this._lineCount += lineIndexDelta; this._last.MoveDown(lineIndexDelta); this._last.ColumnIndex = this._last.Line.Length; if (addToUndo) { this.AddUndo(4, lineIndex, columnIndex, lineNum, index, textList); } if (!loading) { this.OnTextBufferChanged(new TextBufferEventArgs(lineIndex, columnIndex, lineIndex, columnIndex, lineNum, index)); } location.SetLine(next, lineNum); location.ColumnIndex = index; } }
public TextBufferCommand(int command, TextBufferLocation startLocation, TextBufferLocation endLocation, object data) : this(command, startLocation, endLocation, false, Point.Empty, -1, data) { }
public TextBufferCommand(int command, TextBufferLocation startLocation, object data) : this(command, startLocation, null, data) { }
public TextBufferCommand(int command, TextBufferLocation startLocation, TextBufferLocation endLocation) : this(command, startLocation, endLocation, null) { }
private int GetViewIndex(TextBufferLocation location) { return this.GetViewIndex(location.Line, location.ColumnIndex); }
private bool DeleteLine(TextBufferLocation location) { TextLine line = location.Line; if (line == null) { return false; } TextLine previous = line.Previous; TextLine next = line.Next; bool flag = true; if (previous != null) { previous.Next = line.Next; if (next != null) { next.Previous = previous; } else { this._last.SetLine(previous, this._last.LineIndex - 1); this._last.ColumnIndex = this._last.Line.Length; } location.SetLine(previous, location.LineIndex - 1); this._lineCount--; } else if (next != null) { next.Previous = null; this._first.SetLine(next, 0); location.SetLine(next, 0); this._lineCount--; } else { line.Clear(); flag = false; } if (flag) { this.FixLocationLineNumbers(location.LineIndex, -1, location.Line, location.LineIndex, location.ColumnIndex); } return true; }
private int MoveToFirstCharIndex(TextBufferLocation location) { int index = 0; char[] data = location.Line.Data; if (data != null) { while (index < location.Line.Length) { if (!char.IsWhiteSpace(data[index])) { break; } index++; } } location.ColumnIndex = index; return index; }
public virtual TextBufferSpan GetWordSpan(TextBufferLocation location, WordType type) { TextBufferLocation location4; TextLine line2; int columnIndex; if (type != WordType.Previous) { if (type != WordType.Next) { if (location.Line.Length == 0) { return null; } TextBufferLocation start = location.Clone(); if (start.ColumnIndex >= start.Line.Length) { start.ColumnIndex = start.Line.Length - 1; } TextBufferLocation location7 = location.Clone(); if (!this.IsSeperatorChar(start.Line[start.ColumnIndex])) { while ((start.ColumnIndex > 0) && !this.IsSeperatorChar(start.Line[start.ColumnIndex - 1])) { start.ColumnIndex--; } while ((location7.ColumnIndex < location7.Line.Length) && !this.IsSeperatorChar(location7.Line[location7.ColumnIndex])) { location7.ColumnIndex++; } } else { while (((start.ColumnIndex > 0) && this.IsSeperatorChar(start.Line[start.ColumnIndex - 1])) && !char.IsWhiteSpace(start.Line[start.ColumnIndex - 1])) { start.ColumnIndex--; } while (((location7.ColumnIndex < location7.Line.Length) && this.IsSeperatorChar(location7.Line[location7.ColumnIndex])) && !char.IsWhiteSpace(start.Line[location7.ColumnIndex])) { location7.ColumnIndex++; } } return new TextBufferSpan(start, location7); } location4 = location.Clone(); line2 = location4.Line; columnIndex = location4.ColumnIndex; bool flag = false; if (columnIndex == line2.Length) { if (location4.MoveDown(1) > 0) { line2 = location4.Line; columnIndex = 0; flag = true; } else { columnIndex = line2.Length; } } if (!flag) { if ((columnIndex >= line2.Length) || !this.IsSeperatorChar(line2[columnIndex])) { while ((columnIndex < line2.Length) && !this.IsSeperatorChar(line2[columnIndex])) { columnIndex++; } } else { while ((columnIndex < line2.Length) && this.IsSeperatorChar(line2[columnIndex])) { columnIndex++; } } } } else { TextBufferLocation location2 = location.Clone(); TextLine line = location2.Line; int num = location2.ColumnIndex; TextBufferLocation location3 = location2.Clone(); if (num != 0) { while ((num > 0) && char.IsWhiteSpace(line[num - 1])) { num--; } if ((num <= 0) || !this.IsSeperatorChar(line[num - 1])) { while ((num > 0) && !this.IsSeperatorChar(line[num - 1])) { num--; } } else { while ((num > 0) && this.IsSeperatorChar(line[num - 1])) { num--; } } } else { if (location2.MoveUp(1) > 0) { location2.ColumnIndex = location2.Line.Length; return new TextBufferSpan(location2, location3); } location2.ColumnIndex = 0; return new TextBufferSpan(location2, location3); } location2.ColumnIndex = num; return new TextBufferSpan(location2, location3); } while ((columnIndex < line2.Length) && char.IsWhiteSpace(line2[columnIndex])) { columnIndex++; } location4.ColumnIndex = columnIndex; TextBufferLocation end = location4.Clone(); if ((end.ColumnIndex >= end.Line.Length) || !this.IsSeperatorChar(end.Line[end.ColumnIndex])) { while ((end.ColumnIndex < end.Line.Length) && !this.IsSeperatorChar(end.Line[end.ColumnIndex])) { end.ColumnIndex++; } } else { while ((end.ColumnIndex < end.Line.Length) && this.IsSeperatorChar(end.Line[end.ColumnIndex])) { end.ColumnIndex++; } } return new TextBufferSpan(location4, end); }
public TextBufferSpan GetWordSpan(TextBufferLocation location) { return this.TextLanguage.GetWordSpan(location, WordType.Current); }
private bool MergeWithNextLine(TextBufferLocation location) { int lineIndex = location.LineIndex; int columnIndex = location.ColumnIndex; TextLine line = location.Line; TextLine next = line.Next; if ((line == null) || (next == null)) { return false; } int length = line.Length; char[] data = next.Data; int num2 = next.Length; if ((data != null) && (num2 > 0)) { line.Append(data, num2); if (line.Length > this._maxLineLength) { this._maxLineLength = line.Length; this._maxLine = line; } } location.MoveDown(1); this.DeleteLine(location); location.ColumnIndex = length; return true; }
public bool Contains(TextBufferLocation location) { return this.Contains(location.LineIndex, location.ColumnIndex); }
public void ShowHelp(IServiceProvider provider, TextBufferLocation location) { }
private int RemoveTab(TextBufferLocation location) { if (this._view.ConvertTabsToSpaces) { TextBufferLocation start = this._buffer.CreateTextBufferLocation(location); TextLine line = start.Line; int index = start.ColumnIndex - 1; int num2 = 0; if (index > -1) { bool flag = line.Data[index] != ' '; while (((index % this._view.TabSize) != 0) && !flag) { index--; flag = line.Data[index] != ' '; } if (flag) { index++; } start.ColumnIndex = index; num2 = location.ColumnIndex - index; this._buffer.DeleteText(new TextBufferSpan(start, location)); } start.Dispose(); return num2; } if (location.ColumnIndex > 0) { int num3 = location.ColumnIndex - 1; if (location.Line.Data[num3] == '\t') { location.ColumnIndex--; this._buffer.DeleteChar(location); return 1; } } return 0; }
private bool DeleteChar(TextBufferLocation location, bool addToUndo) { if (!this._undoing) { this.RedoStack.Clear(); } TextLine line = location.Line; int columnIndex = location.ColumnIndex; if (columnIndex >= line.Length) { return false; } char data = line.Data[columnIndex]; line.Delete(columnIndex, 1); if (addToUndo) { this.AddUndo(2, location.LineIndex, columnIndex, data); } if (line == this._last.Line) { this._last.ColumnIndex = line.Length; } int lineIndex = location.LineIndex; this.OnTextBufferChanged(new TextBufferEventArgs(lineIndex, columnIndex, lineIndex, columnIndex + 1, lineIndex, columnIndex)); return true; }