private int MatchNext(string matchText) { if (String.IsNullOrEmpty(matchText)) { return(-1); } int indexOf = -1; try { ActiveTextArea.BeginUpdate(); int lineNo = ActiveTextArea.Caret.Line; int colNo = ActiveTextArea.Caret.Column; int totalNumOfLines = ActiveDocument.TotalNumberOfLines; string LineText = SharpDevelopTextEditorUtilities.GetLineAsString(ActiveDocument, lineNo); LineText = ActiveDocument.GetText(ActiveTextArea.Caret.Offset, LineText.Length - colNo); indexOf = LineText.IndexOf(matchText, StringComparison.InvariantCultureIgnoreCase); int offset = colNo; if (indexOf < 0) { offset = 0; do { int tmpLineNo = ActiveDocument.GetNextVisibleLineAbove(lineNo, 1); if (tmpLineNo == lineNo) { break; } lineNo = tmpLineNo; LineText = SharpDevelopTextEditorUtilities.GetLineAsString(ActiveDocument, lineNo); indexOf = LineText.IndexOf(matchText, StringComparison.InvariantCultureIgnoreCase); }while (indexOf < 0 && lineNo < totalNumOfLines); } if (indexOf >= 0) { ActiveTextArea.Caret.Column = 0; ActiveTextArea.Caret.Line = lineNo; Point startPoint = ActiveTextArea.Caret.Position; startPoint.X = indexOf + offset; Point endPoint = startPoint; endPoint.X = endPoint.X + matchText.Length; ActiveTextArea.SelectionManager.SetSelection(startPoint, endPoint); ActiveTextArea.Caret.Column = endPoint.X; } else if (lineNo == totalNumOfLines - 1) { MessageBox.Show("Reached end of document", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } } finally { ActiveTextArea.EndUpdate(); } return(indexOf); }
private void HandleCodeCompletionSelection_Ex() { try { ActiveTextArea.BeginUpdate(); string userSelection = String.Empty; if (_codeCompWindowEx.Selector.HasMultipleSelection) { userSelection = _codeCompWindowEx.SelectedItemsAsCommaSeparatedString; } else { userSelection = _codeCompWindowEx.SelectedItem; } if (_codeCompWindowEx.Selector.HasMultipleSelection) { ActiveTextArea.InsertString(userSelection); } else { DeleteWordBeforeCaret(); ActiveTextArea.InsertString(userSelection); } FireAfterCodeCompletionShowed(CodeCompletionType.UserDefinedList, userSelection, true); } finally { ActiveTextArea.EndUpdate(); } _codeCompWindowEx.DismissSelector(); _textEditor.Focus(); }
private int MatchPrev(string matchText) { if (String.IsNullOrEmpty(matchText)) { return(-1); } int indexOf = -1; try { ActiveTextArea.BeginUpdate(); int lineNo = ActiveTextArea.Caret.Line; int colNo = ActiveTextArea.Caret.Column; string LineText = SharpDevelopTextEditorUtilities.GetLineAsString(ActiveDocument, lineNo); LineText = LineText.Substring(0, ActiveTextArea.Caret.Column); indexOf = LineText.LastIndexOf(matchText, StringComparison.InvariantCultureIgnoreCase); if (indexOf < 0) { do { int tmpLineNo = ActiveDocument.GetNextVisibleLineBelow(lineNo, 1); if (tmpLineNo == lineNo) { break; } lineNo = tmpLineNo; LineText = SharpDevelopTextEditorUtilities.GetLineAsString(ActiveDocument, lineNo); indexOf = LineText.LastIndexOf(matchText, StringComparison.InvariantCultureIgnoreCase); }while (indexOf < 0 && lineNo >= 0); } if (indexOf > 0) { ActiveTextArea.Caret.Column = 0; ActiveTextArea.Caret.Line = lineNo; Point startPoint = ActiveTextArea.Caret.Position; startPoint.X = indexOf; Point endPoint = startPoint; endPoint.X = endPoint.X + matchText.Length; ActiveTextArea.SelectionManager.SetSelection(startPoint, endPoint); ActiveTextArea.Caret.Column = startPoint.X; } else if (lineNo == 0) { MessageBox.Show("Reached start of document", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } } finally { ActiveTextArea.EndUpdate(); } return(indexOf); }
public void ConvertTokensTo(TokenConversionType conversionType) { try { ActiveTextArea.BeginUpdate(); StringBuilder sb = null; HighlightRuleSet rules = ActiveDocument.HighlightingStrategy.GetRuleSet(null); IList <LineSegment> lines = ActiveDocument.LineSegmentCollection; for (int k = 0; k < lines.Count; k++) { LineSegment segment = lines[k]; for (int i = 0; i < segment.Words.Count; i++) { TextWord word = segment.Words[i]; if (word.Type != TextWordType.Word) { continue; } if (rules.KeyWords[ActiveDocument, segment, word.Offset, word.Length] != null) { string newVal = word.Word; switch (conversionType) { case TokenConversionType.Lower: newVal = word.Word.ToLowerInvariant(); break; case TokenConversionType.Upper: newVal = word.Word.ToUpperInvariant(); break; case TokenConversionType.Capitalize: newVal = word.Word; char[] chars = newVal.ToCharArray(); chars[0] = Char.ToUpperInvariant(newVal[0]); sb = new StringBuilder(); sb.Append(chars); newVal = sb.ToString(); break; default: break; } ActiveDocument.Replace(segment.Offset + word.Offset, word.Length, newVal); } } } } finally { ActiveTextArea.EndUpdate(); } }
public void AppendContent(string content) { try { ActiveTextArea.BeginUpdate(); ActiveTextArea.Text += content; } finally { ActiveTextArea.EndUpdate(); ActiveTextArea.Invalidate(); } }
public void RemoveContent(CaretPosition startPos, CaretPosition endPos) { try { ActiveTextArea.BeginUpdate(); ActiveTextArea.SelectionManager.SetSelection(startPos.ToPoint(), endPos.ToPoint()); ActiveTextArea.SelectionManager.RemoveSelectedText(); } finally { ActiveTextArea.EndUpdate(); ActiveTextArea.Invalidate(); } }
private void OnAction_ToggleFoldings_Execute(object sender, EventArgs e) { try { ActiveTextArea.BeginUpdate(); foreach (FoldMarker marker in ActiveDocument.FoldingManager.FoldMarker) { marker.IsFolded = !marker.IsFolded; } } finally { ActiveTextArea.EndUpdate(); ActiveTextArea.Invalidate(); } }
public string GetContent(CaretPosition startPos, CaretPosition endPos) { string result = String.Empty; try { ActiveTextArea.BeginUpdate(); ActiveTextArea.SelectionManager.SetSelection(startPos.ToPoint(), endPos.ToPoint()); result = ActiveTextArea.SelectionManager.SelectedText; ActiveTextArea.SelectionManager.ClearSelection(); return(result); } finally { ActiveTextArea.EndUpdate(); ActiveTextArea.Invalidate(); } }
public void ChangeScriptCase(TokenConversionType conversionType) { try { ActiveTextArea.BeginUpdate(); HighlightRuleSet rules = ActiveDocument.HighlightingStrategy.GetRuleSet(null); IList <LineSegment> lines = ActiveDocument.LineSegmentCollection; for (int k = 0; k < lines.Count; k++) { LineSegment segment = lines[k]; for (int i = 0; i < segment.Words.Count; i++) { TextWord word = segment.Words[i]; if (word.Type != TextWordType.Word) { continue; } string newVal = word.Word; switch (conversionType) { case TokenConversionType.Lower: newVal = word.Word.ToLowerInvariant(); break; case TokenConversionType.Upper: newVal = word.Word.ToUpperInvariant(); break; default: break; } ActiveDocument.Replace(segment.Offset + word.Offset, word.Length, newVal); } } } finally { ActiveTextArea.EndUpdate(); } }