public GetService ( |
||
serviceType | ||
Résultat | object |
const string LineSelectedType = "MSDEVLineSelect"; // This is the type VS 2003 and 2005 use for flagging a whole line copy static void CopyWholeLine(TextArea textArea, DocumentLine line) { ISegment wholeLine = new SimpleSegment(line.Offset, line.TotalLength); string text = textArea.Document.GetText(wholeLine); // Ensure we use the appropriate newline sequence for the OS text = TextUtilities.NormalizeNewLines(text, Environment.NewLine); DataObject data = new DataObject(text); // Also copy text in HTML format to clipboard - good for pasting text into Word // or to the SharpDevelop forums. IHighlighter highlighter = textArea.GetService(typeof(IHighlighter)) as IHighlighter; HtmlClipboard.SetHtml(data, HtmlClipboard.CreateHtmlFragment(textArea.Document, highlighter, wholeLine, new HtmlOptions(textArea.Options))); MemoryStream lineSelected = new MemoryStream(1); lineSelected.WriteByte(1); data.SetData(LineSelectedType, lineSelected, false); try { Clipboard.SetDataObject(data, true); } catch (ExternalException) { // Apparently this exception sometimes happens randomly. // The MS controls just ignore it, so we'll do the same. return; } textArea.OnTextCopied(new TextEventArgs(text)); }
/// <summary> /// Creates a HTML fragment for the selected text. /// </summary> public string CreateHtmlFragment(TextArea textArea, HtmlOptions options) { if (textArea == null) { throw new ArgumentNullException("textArea"); } if (options == null) { throw new ArgumentNullException("options"); } IHighlighter highlighter = textArea.GetService(typeof(IHighlighter)) as IHighlighter; StringBuilder html = new StringBuilder(); bool first = true; foreach (ISegment selectedSegment in this.Segments) { if (first) { first = false; } else { html.AppendLine("<br>"); } html.Append(HtmlClipboard.CreateHtmlFragment(textArea.Document, highlighter, selectedSegment, options)); } return(html.ToString()); }
public override object GetPattern(PatternInterface patternInterface) { if (patternInterface == PatternInterface.Text) { return(this); } if (patternInterface == PatternInterface.Value) { return(this); } if (patternInterface == PatternInterface.Scroll) { TextEditor editor = TextArea.GetService(typeof(TextEditor)) as TextEditor; if (editor != null) { return(FromElement(editor).GetPattern(patternInterface)); } } return(base.GetPattern(patternInterface)); }
const string LineSelectedType = "MSDEVLineSelect"; // This is the type VS 2003 and 2005 use for flagging a whole line copy static void CopyWholeLine(TextArea textArea, DocumentLine line) { ISegment wholeLine = new SimpleSegment(line.Offset, line.TotalLength); string text = textArea.Document.GetText(wholeLine); // Ensure we use the appropriate newline sequence for the OS DataObject data = new DataObject(NewLineFinder.NormalizeNewLines(text, Environment.NewLine)); // Also copy text in HTML format to clipboard - good for pasting text into Word // or to the SharpDevelop forums. DocumentHighlighter highlighter = textArea.GetService(typeof(DocumentHighlighter)) as DocumentHighlighter; HtmlClipboard.SetHtml(data, HtmlClipboard.CreateHtmlFragment(textArea.Document, highlighter, wholeLine, new HtmlOptions(textArea.Options))); MemoryStream lineSelected = new MemoryStream(1); lineSelected.WriteByte(1); data.SetData(LineSelectedType, lineSelected, false); Clipboard.SetDataObject(data, true); }
public virtual void Complete(TextArea textArea, ISegment completionSegment, EventArgs insertionRequestEventArgs) { var textEditor = textArea.GetService(typeof(Editor)) as Editor; if (textEditor == null) { return; } var kukaTextEditor = textEditor as Editor; var text = (kukaTextEditor == null) ? textEditor.GetWordBeforeCaret() : kukaTextEditor.GetWordBeforeCaret(kukaTextEditor.GetWordParts()); if (Text.StartsWith(text, StringComparison.InvariantCultureIgnoreCase) || Text.ToLowerInvariant().Contains(text.ToLowerInvariant())) { textEditor.Document.Replace(textEditor.CaretOffset - text.Length, text.Length, Text); } else { textEditor.Document.Insert(textEditor.CaretOffset, Text); } if (UsageName != null) { CodeCompletionDataUsageCache.IncrementUsage(UsageName); } }
/// <summary> /// Creates a new SearchPanel and attaches it to a text area. /// </summary> public SearchPanel(TextArea textArea) { if (textArea == null) throw new ArgumentNullException("textArea"); this.textArea = textArea; DataContext = this; InitializeComponent(); textArea.TextView.Layers.Add(this); foldingManager = textArea.GetService(typeof(FoldingManager)) as FoldingManager; renderer = new SearchResultBackgroundRenderer(); textArea.TextView.BackgroundRenderers.Add(renderer); textArea.Document.TextChanged += delegate { DoSearch(false); }; this.Loaded += delegate { searchTextBox.Focus(); }; useRegex.Checked += ValidateSearchText; matchCase.Checked += ValidateSearchText; wholeWords.Checked += ValidateSearchText; useRegex.Unchecked += ValidateSearchText; matchCase.Unchecked += ValidateSearchText; wholeWords.Unchecked += ValidateSearchText; }
internal static void CopyWholeLine(TextArea textArea, DocumentLine line) { ISegment wholeLine = new VerySimpleSegment(line.Offset, line.TotalLength); string text = textArea.Document.GetText(wholeLine); // Ensure we use the appropriate newline sequence for the OS text = TextUtilities.NormalizeNewLines(text, Environment.NewLine); DataObject data = new DataObject(text); // Also copy text in HTML format to clipboard - good for pasting text into Word // or to the SharpDevelop forums. IHighlighter highlighter = textArea.GetService(typeof(IHighlighter)) as IHighlighter; HtmlClipboard.SetHtml(data, HtmlClipboard.CreateHtmlFragment(textArea.Document, highlighter, wholeLine, new HtmlOptions(textArea.Options))); MemoryStream lineSelected = new MemoryStream(1); lineSelected.WriteByte(1); data.SetData(LineSelectedType, lineSelected, false); try { Clipboard.SetDataObject(data, true); } catch (ExternalException) { // Apparently this exception sometimes happens randomly. // The MS controls just ignore it, so we'll do the same. return; } //textArea.OnTextCopied(new TextEventArgs(text)); }
const string LineSelectedType = "MSDEVLineSelect"; // This is the type VS 2003 and 2005 use for flagging a whole line copy static void CopyWholeLine(TextArea textArea, DocumentLine line) { ISegment wholeLine = new SimpleSegment(line.Offset, line.TotalLength); string text = textArea.Document.GetText(wholeLine); // Ensure we use the appropriate newline sequence for the OS DataObject data = new DataObject(NewLineFinder.NormalizeNewLines(text, Environment.NewLine)); // Also copy text in HTML format to clipboard - good for pasting text into Word // or to the SharpDevelop forums. DocumentHighlighter highlighter = textArea.GetService(typeof(DocumentHighlighter)) as DocumentHighlighter; HtmlClipboard.SetHtml(data, HtmlClipboard.CreateHtmlFragment(textArea.Document, highlighter, wholeLine, new HtmlOptions(textArea.Options))); MemoryStream lineSelected = new MemoryStream(1); lineSelected.WriteByte(1); data.SetData(LineSelectedType, lineSelected, false); Clipboard.SetDataObject(data, true); }
public void ShowExample(TextArea exampleTextArea) { string exampleText = StringParser.Parse(color.ExampleText, GetXshdProperties().ToArray()); int semanticHighlightStart = exampleText.IndexOf("#{#", StringComparison.OrdinalIgnoreCase); int semanticHighlightEnd = exampleText.IndexOf("#}#", StringComparison.OrdinalIgnoreCase); if (semanticHighlightStart > -1 && semanticHighlightEnd >= semanticHighlightStart + 3) { semanticHighlightEnd -= 3; exampleText = exampleText.Remove(semanticHighlightStart, 3).Remove(semanticHighlightEnd, 3); ITextMarkerService svc = exampleTextArea.GetService(typeof(ITextMarkerService)) as ITextMarkerService; exampleTextArea.Document.Text = exampleText; if (svc != null) { ITextMarker m = svc.Create(semanticHighlightStart, semanticHighlightEnd - semanticHighlightStart); m.Tag = (Action<IHighlightingItem, ITextMarker>)( (IHighlightingItem item, ITextMarker marker) => { marker.BackgroundColor = item.Background; marker.ForegroundColor = item.Foreground; marker.FontStyle = item.Italic ? FontStyles.Italic : FontStyles.Normal; marker.FontWeight = item.Bold ? FontWeights.Bold : FontWeights.Normal; }); } } else { exampleTextArea.Document.Text = exampleText; } }
/// <summary> /// Creates a HTML fragment for the selected text. /// </summary> public string CreateHtmlFragment(TextArea textArea, HtmlOptions options) { if (textArea == null) throw new ArgumentNullException("textArea"); if (options == null) throw new ArgumentNullException("options"); IHighlighter highlighter = textArea.GetService(typeof(IHighlighter)) as IHighlighter; StringBuilder html = new StringBuilder(); bool first = true; foreach (ISegment selectedSegment in this.Segments) { if (first) first = false; else html.AppendLine("<br>"); html.Append(HtmlClipboard.CreateHtmlFragment(textArea.Document, highlighter, selectedSegment, options)); } return html.ToString(); }
private void FormatLineInternal(TextArea textArea, int lineNr, int cursorOffset, char ch) { DocumentLine curLine = textArea.Document.GetLineByNumber(lineNr); DocumentLine lineAbove = lineNr > 1 ? textArea.Document.GetLineByNumber(lineNr - 1) : null; string terminator = TextUtilities.GetLineTerminator(textArea.Document, lineNr); string curLineText; if (ch != '\n' && ch != '>') { if (IsInsideStringOrComment(textArea, curLine, cursorOffset)) return; } switch (ch) { case '>': if (IsInsideDocumentationComment(textArea, curLine, cursorOffset)) { curLineText = textArea.Document.GetText(curLine); int column = cursorOffset - curLine.Offset; int index = Math.Min(column - 1, curLineText.Length - 1); while (index >= 0 && curLineText[index] != '<') { --index; if (curLineText[index] == '/') return; // the tag was an end tag or already } if (index > 0) { StringBuilder commentBuilder = new StringBuilder(""); for (int i = index; i < curLineText.Length && i < column && !Char.IsWhiteSpace(curLineText[i]); ++i) { commentBuilder.Append(curLineText[i]); } string tag = commentBuilder.ToString().Trim(); if (!tag.EndsWith(">")) { tag += ">"; } if (!tag.StartsWith("/")) { textArea.Document.Insert(cursorOffset, "</" + tag.Substring(1)); } } } break; case ':': case ')': case ']': case '}': case '{': if (textArea.IndentationStrategy != null) textArea.IndentationStrategy.IndentLine(textArea, curLine); break; case '\n': string lineAboveText = lineAbove == null ? "" : textArea.Document.GetText(lineAbove); //// curLine might have some text which should be added to indentation curLineText = textArea.Document.GetText(curLine); IHighlighter highlighter = textArea.GetService(typeof(IHighlighter)) as IHighlighter; bool isInMultilineComment = false; bool isInMultilineString = false; if (highlighter != null && lineAbove != null) { var spanStack = highlighter.GetSpanColorNamesFromLineStart(lineNr); isInMultilineComment = spanStack.Contains(HighlightingKnownNames.Comment); isInMultilineString = spanStack.Contains(HighlightingKnownNames.String); } bool isInNormalCode = !(isInMultilineComment || isInMultilineString); if (lineAbove != null && isInMultilineComment) { string lineAboveTextTrimmed = lineAboveText.TrimStart(); if (lineAboveTextTrimmed.StartsWith("/*", StringComparison.Ordinal)) { textArea.Document.Insert(cursorOffset, " * "); return; } if (lineAboveTextTrimmed.StartsWith("*", StringComparison.Ordinal)) { textArea.Document.Insert(cursorOffset, "* "); return; } } if (lineAbove != null && isInNormalCode) { DocumentLine nextLine = lineNr + 1 <= textArea.Document.LineCount ? textArea.Document.GetLineByNumber(lineNr + 1) : null; string nextLineText = (nextLine != null) ? textArea.Document.GetText(nextLine) : ""; int indexAbove = lineAboveText.IndexOf("///"); int indexNext = nextLineText.IndexOf("///"); if (indexAbove > 0 && (indexNext != -1 || indexAbove + 4 < lineAbove.Length)) { textArea.Document.Insert(cursorOffset, "/// "); return; } if (IsInNonVerbatimString(lineAboveText, curLineText)) { textArea.Document.Insert(cursorOffset, "\""); textArea.Document.Insert(lineAbove.Offset + lineAbove.Length, "\" +"); } } if (/*textArea.Options.AutoInsertBlockEnd &&*/ lineAbove != null && isInNormalCode) { string oldLineText = textArea.Document.GetText(lineAbove); if (oldLineText.EndsWith("{")) { if (NeedCurlyBracket(textArea.Document.Text)) { int insertionPoint = curLine.Offset + curLine.Length; textArea.Document.Insert(insertionPoint, terminator + "}"); if (textArea.IndentationStrategy != null) textArea.IndentationStrategy.IndentLine(textArea, textArea.Document.GetLineByNumber(lineNr + 1)); textArea.Caret.Offset = insertionPoint; } } } return; } }
private void FormatLineInternal(TextArea textArea, int lineNr, int cursorOffset, char ch) { DocumentLine curLine = textArea.Document.GetLineByNumber(lineNr); DocumentLine lineAbove = lineNr > 1 ? textArea.Document.GetLineByNumber(lineNr - 1) : null; string terminator = TextUtilities.GetLineTerminator(textArea.Document, lineNr); string curLineText; // /// local string for curLine segment //if (ch == '/') //{ // curLineText = curLine.Text; // string lineAboveText = lineAbove == null ? "" : lineAbove.Text; // if (curLineText != null && curLineText.EndsWith("///") && (lineAboveText == null || !lineAboveText.Trim().StartsWith("///"))) // { // string indentation = DocumentUtilitites.GetWhitespaceAfter(textArea.Document, curLine.Offset); // object member = GetMemberAfter(textArea, lineNr); // if (member != null) // { // StringBuilder sb = new StringBuilder(); // sb.Append(" <summary>"); // sb.Append(terminator); // sb.Append(indentation); // sb.Append("/// "); // sb.Append(terminator); // sb.Append(indentation); // sb.Append("/// </summary>"); // if (member is IMethod) // { // IMethod method = (IMethod)member; // if (method.Parameters != null && method.Parameters.Count > 0) // { // for (int i = 0; i < method.Parameters.Count; ++i) // { // sb.Append(terminator); // sb.Append(indentation); // sb.Append("/// <param name=\""); // sb.Append(method.Parameters[i].Name); // sb.Append("\"></param>"); // } // } // if (method.ReturnType != null && !method.IsConstructor && method.ReturnType.FullyQualifiedName != "System.Void") // { // sb.Append(terminator); // sb.Append(indentation); // sb.Append("/// <returns></returns>"); // } // } // textArea.Document.Insert(cursorOffset, sb.ToString()); // textArea.Caret.Offset = cursorOffset + indentation.Length + "/// ".Length + " <summary>".Length + terminator.Length; // } // } // return; //} if (ch != '\n' && ch != '>') { if (IsInsideStringOrComment(textArea, curLine, cursorOffset)) { return; } } switch (ch) { case '>': if (IsInsideDocumentationComment(textArea, curLine, cursorOffset)) { curLineText = textArea.Document.GetText(curLine); int column = cursorOffset - curLine.Offset; int index = Math.Min(column - 1, curLineText.Length - 1); while (index >= 0 && curLineText[index] != '<') { --index; if (curLineText[index] == '/') return; // the tag was an end tag or already } if (index > 0) { StringBuilder commentBuilder = new StringBuilder(""); for (int i = index; i < curLineText.Length && i < column && !Char.IsWhiteSpace(curLineText[i]); ++i) { commentBuilder.Append(curLineText[i]); } string tag = commentBuilder.ToString().Trim(); if (!tag.EndsWith(">")) { tag += ">"; } if (!tag.StartsWith("/")) { textArea.Document.Insert(cursorOffset, "</" + tag.Substring(1)); } } } break; case ':': case ')': case ']': case '}': case '{': if (textArea.IndentationStrategy != null) textArea.IndentationStrategy.IndentLine(textArea, curLine); break; case '\n': string lineAboveText = lineAbove == null ? "" : textArea.Document.GetText(lineAbove); //// curLine might have some text which should be added to indentation curLineText = textArea.Document.GetText(curLine); if (lineAbove != null && textArea.Document.GetText(lineAbove).Trim().StartsWith("#region") && NeedEndregion(textArea.Document)) { textArea.Document.Insert(cursorOffset, "#endregion"); return; } IHighlighter highlighter = textArea.GetService(typeof(IHighlighter)) as IHighlighter; bool isInMultilineComment = false; bool isInMultilineString = false; if (highlighter != null && lineAbove != null) { var spanStack = highlighter.GetSpanColorNamesFromLineStart(lineNr); isInMultilineComment = spanStack.Contains(HighlightingKnownNames.Comment); isInMultilineString = spanStack.Contains(HighlightingKnownNames.String); } bool isInNormalCode = !(isInMultilineComment || isInMultilineString); if (lineAbove != null && isInMultilineComment) { string lineAboveTextTrimmed = lineAboveText.TrimStart(); if (lineAboveTextTrimmed.StartsWith("/*", StringComparison.Ordinal)) { textArea.Document.Insert(cursorOffset, " * "); return; } if (lineAboveTextTrimmed.StartsWith("*", StringComparison.Ordinal)) { textArea.Document.Insert(cursorOffset, "* "); return; } } if (lineAbove != null && isInNormalCode) { DocumentLine nextLine = lineNr + 1 <= textArea.Document.LineCount ? textArea.Document.GetLineByNumber(lineNr + 1) : null; string nextLineText = (nextLine != null) ? textArea.Document.GetText(nextLine) : ""; int indexAbove = lineAboveText.IndexOf("///"); int indexNext = nextLineText.IndexOf("///"); if (indexAbove > 0 && (indexNext != -1 || indexAbove + 4 < lineAbove.Length)) { textArea.Document.Insert(cursorOffset, "/// "); return; } if (IsInNonVerbatimString(lineAboveText, curLineText)) { textArea.Document.Insert(cursorOffset, "\""); textArea.Document.Insert(lineAbove.Offset + lineAbove.Length, "\" +"); } } if (/*textArea.Options.AutoInsertBlockEnd &&*/ lineAbove != null && isInNormalCode) { string oldLineText = textArea.Document.GetText(lineAbove); if (oldLineText.EndsWith("{")) { if (NeedCurlyBracket(textArea.Document.Text)) { int insertionPoint = curLine.Offset + curLine.Length; textArea.Document.Insert(insertionPoint, terminator + "}"); if (textArea.IndentationStrategy != null) textArea.IndentationStrategy.IndentLine(textArea, textArea.Document.GetLineByNumber(lineNr + 1)); textArea.Caret.Offset = insertionPoint; } } } return; } }