本文整理汇总了C#中ICSharpCode.AvalonEdit.Editing.TextArea.GetService方法的典型用法代码示例。如果您正苦于以下问题:C# TextArea.GetService方法的具体用法?C# TextArea.GetService怎么用?C# TextArea.GetService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.AvalonEdit.Editing.TextArea
的用法示例。
在下文中一共展示了TextArea.GetService方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Complete
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);
}
}
示例2: SearchPanel
/// <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;
}
示例3: CopyWholeLine
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));
}
示例4: CopyWholeLine
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);
}
示例5: ShowExample
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;
}
}
示例6: CreateHtmlFragment
/// <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();
}
示例7: FormatLineInternal
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;
}
//.........这里部分代码省略.........
示例8: FormatLineInternal
//.........这里部分代码省略.........
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;
}
}