本文整理汇总了C#中ICSharpCode.AvalonEdit.Snippets.InsertionContext类的典型用法代码示例。如果您正苦于以下问题:C# InsertionContext类的具体用法?C# InsertionContext怎么用?C# InsertionContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InsertionContext类属于ICSharpCode.AvalonEdit.Snippets命名空间,在下文中一共展示了InsertionContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Link
public override Task Link(params AstNode[] nodes)
{
var segs = nodes.Select(node => GetSegment(node)).ToArray();
InsertionContext c = new InsertionContext(editor.GetRequiredService<TextArea>(), segs.Min(seg => seg.Offset));
c.InsertionPosition = segs.Max(seg => seg.EndOffset);
var tcs = new TaskCompletionSource<bool>();
c.Deactivated += (sender, e) => tcs.SetResult(true);
if (segs.Length > 0) {
// try to use node in identifier context to avoid the code completion popup.
var identifier = nodes.OfType<Identifier>().FirstOrDefault();
ISegment first;
if (identifier == null)
first = segs[0];
else
first = GetSegment(identifier);
c.Link(first, segs.Except(new[]{first}).ToArray());
c.RaiseInsertionCompleted(EventArgs.Empty);
} else {
c.RaiseInsertionCompleted(EventArgs.Empty);
c.Deactivate(new SnippetEventArgs(DeactivateReason.NoActiveElements));
}
return tcs.Task;
}
示例2: InsertCtorDialog
public InsertCtorDialog(InsertionContext context, ITextEditor editor, ITextAnchor anchor)
: base(context, editor, anchor)
{
InitializeComponent();
Visibility = System.Windows.Visibility.Collapsed;
}
示例3: OverrideEqualsGetHashCodeMethodsDialog
public OverrideEqualsGetHashCodeMethodsDialog(InsertionContext context, ITextEditor editor, ITextAnchor endAnchor,
ITextAnchor insertionPosition, ITypeDefinition selectedClass, IMethod selectedMethod, AstNode baseCallNode)
: base(context, editor, insertionPosition)
{
if (selectedClass == null)
throw new ArgumentNullException("selectedClass");
InitializeComponent();
this.selectedClass = selectedClass;
this.insertionEndAnchor = endAnchor;
this.selectedMethod = selectedMethod;
this.baseCallNode = baseCallNode;
addIEquatable.Content = string.Format(StringParser.Parse("${res:AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.AddInterface}"),
"IEquatable<" + selectedClass.Name + ">");
string otherMethod = selectedMethod.Name == "Equals" ? "GetHashCode" : "Equals";
addOtherMethod.Content = StringParser.Parse("${res:AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.AddOtherMethod}", new StringTagPair("otherMethod", otherMethod));
addIEquatable.IsEnabled = !selectedClass.GetAllBaseTypes().Any(
type => {
if (!type.IsParameterized || (type.TypeParameterCount != 1))
return false;
if (type.FullName != "System.IEquatable")
return false;
return type.TypeArguments.First().FullName == selectedClass.FullName;
}
);
}
示例4: Insert
/// <summary>
/// Called when this switch body element is inserted to the editor.
/// </summary>
public override void Insert(InsertionContext context)
{
this.context = context;
this.context.Deactivated += new EventHandler<SnippetEventArgs>(InteractiveModeCompleted);
this.anchor = SetUpAnchorAtInsertion(context);
this.classFinderContext = new ClassFinder(ParserService.ParseCurrentViewContent(), Editor.Document.Text, Editor.Caret.Offset);
}
示例5: BoundActiveElement
public BoundActiveElement(InsertionContext context, SnippetReplaceableTextElement targetSnippetElement, SnippetBoundElement boundElement, AnchorSegment segment)
{
this.context = context;
this.targetSnippetElement = targetSnippetElement;
this.boundElement = boundElement;
this.segment = segment;
}
示例6: Insert
/// <inheritdoc/>
public override void Insert(InsertionContext context)
{
int start = context.InsertionPosition;
base.Insert(context);
int end = context.InsertionPosition;
context.RegisterActiveElement(this, new ReplaceableActiveElement(context, start, end));
}
示例7: AnchorElement
/// <summary>
/// Creates a new AnchorElement.
/// </summary>
public AnchorElement(AnchorSegment segment, string text, string name, InsertionContext context)
{
this.segment = segment;
this.context = context;
this.Text = text;
this.Name = name;
}
示例8: Insert
/// <summary>
/// Inserts the snippet into the text area.
/// </summary>
public void Insert(TextArea textArea)
{
if (textArea == null)
throw new ArgumentNullException("textArea");
ISegment selection = textArea.Selection.SurroundingSegment;
int insertionPosition = textArea.Caret.Offset;
if (selection != null) // if something is selected
// use selection start instead of caret position,
// because caret could be at end of selection or anywhere inside.
// Removal of the selected text causes the caret position to be invalid.
insertionPosition = selection.Offset + TextUtilities.GetWhitespaceAfter(textArea.Document, selection.Offset).Length;
InsertionContext context = new InsertionContext(textArea, insertionPosition);
using (context.Document.RunUpdate()) {
if (selection != null)
textArea.Document.Remove(insertionPosition, selection.EndOffset - insertionPosition);
Insert(context);
// [DIGITALRUNE] Format inserted lines.
int beginLine = textArea.Document.GetLineByOffset(context.StartPosition).LineNumber;
int endLine = textArea.Document.GetLineByOffset(context.InsertionPosition).LineNumber;
textArea.IndentationStrategy?.IndentLines(textArea, beginLine, endLine);
context.RaiseInsertionCompleted(EventArgs.Empty);
}
}
示例9: CreateDialog
internal static CreatePropertiesDialog CreateDialog(InsertionContext context)
{
ITextEditor textEditor = context.TextArea.GetService(typeof(ITextEditor)) as ITextEditor;
if (textEditor == null)
return null;
using (textEditor.Document.OpenUndoGroup()) {
IEditorUIService uiService = textEditor.GetService(typeof(IEditorUIService)) as IEditorUIService;
if (uiService == null)
return null;
ITextAnchor anchor = textEditor.Document.CreateAnchor(context.InsertionPosition);
anchor.MovementType = AnchorMovementType.BeforeInsertion;
CreatePropertiesDialog dialog = new CreatePropertiesDialog(context, textEditor, anchor);
dialog.Element = uiService.CreateInlineUIElement(anchor, dialog);
// Add creation of this inline dialog as undoable operation
TextDocument document = textEditor.Document as TextDocument;
if (document != null) {
document.UndoStack.Push(dialog.UndoableCreationOperation);
}
return dialog;
}
}
示例10: OverrideEqualsGetHashCodeMethodsDialog
public OverrideEqualsGetHashCodeMethodsDialog(InsertionContext context, ITextEditor editor, ITextAnchor startAnchor, ITextAnchor endAnchor,
ITextAnchor insertionPosition, IClass selectedClass, IMethod selectedMethod, string baseCall)
: base(context, editor, insertionPosition)
{
if (selectedClass == null)
throw new ArgumentNullException("selectedClass");
InitializeComponent();
this.selectedClass = selectedClass;
this.startAnchor = startAnchor;
this.insertionEndAnchor = endAnchor;
this.selectedMethod = selectedMethod;
this.baseCall = baseCall;
addIEquatable.Content = string.Format(StringParser.Parse("${res:AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.AddInterface}"),
"IEquatable<" + selectedClass.Name + ">");
string otherMethod = selectedMethod.Name == "Equals" ? "GetHashCode" : "Equals";
addOtherMethod.Content = StringParser.Parse("${res:AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.AddOtherMethod}", new StringTagPair("otherMethod", otherMethod));
addIEquatable.IsEnabled = !selectedClass.BaseTypes.Any(
type => {
if (!type.IsGenericReturnType)
return false;
var genericType = type.CastToGenericReturnType();
var boundTo = genericType.TypeParameter.BoundTo;
if (boundTo == null)
return false;
return boundTo.Name == selectedClass.Name;
}
);
}
示例11: Insert
public void Insert(CompletionContext context, ICompletionItem item)
{
if (item == null)
throw new ArgumentNullException("item");
if (!(item is OverrideCompletionItem))
throw new ArgumentException("item is not an OverrideCompletionItem");
OverrideCompletionItem completionItem = item as OverrideCompletionItem;
ITextEditor textEditor = context.Editor;
IEditorUIService uiService = textEditor.GetService(typeof(IEditorUIService)) as IEditorUIService;
if (uiService == null)
return;
ParseInformation parseInfo = ParserService.GetParseInformation(textEditor.FileName);
if (parseInfo == null)
return;
CodeGenerator generator = parseInfo.CompilationUnit.Language.CodeGenerator;
IClass current = parseInfo.CompilationUnit.GetInnermostClass(textEditor.Caret.Line, textEditor.Caret.Column);
ClassFinder finder = new ClassFinder(current, textEditor.Caret.Line, textEditor.Caret.Column);
if (current == null)
return;
using (textEditor.Document.OpenUndoGroup()) {
ITextAnchor startAnchor = textEditor.Document.CreateAnchor(textEditor.Caret.Offset);
startAnchor.MovementType = AnchorMovementType.BeforeInsertion;
ITextAnchor endAnchor = textEditor.Document.CreateAnchor(textEditor.Caret.Offset);
endAnchor.MovementType = AnchorMovementType.AfterInsertion;
MethodDeclaration member = (MethodDeclaration)generator.GetOverridingMethod(completionItem.Member, finder);
string indent = DocumentUtilitites.GetWhitespaceBefore(textEditor.Document, textEditor.Caret.Offset);
string codeForBaseCall = generator.GenerateCode(member.Body.Children.OfType<AbstractNode>().First(), "");
string code = generator.GenerateCode(member, indent);
int marker = code.IndexOf(codeForBaseCall);
textEditor.Document.Insert(startAnchor.Offset, code.Substring(0, marker).TrimStart());
ITextAnchor insertionPos = textEditor.Document.CreateAnchor(endAnchor.Offset);
insertionPos.MovementType = AnchorMovementType.BeforeInsertion;
InsertionContext insertionContext = new InsertionContext(textEditor.GetService(typeof(TextArea)) as TextArea, startAnchor.Offset);
AbstractInlineRefactorDialog dialog = new OverrideEqualsGetHashCodeMethodsDialog(insertionContext, textEditor, startAnchor, endAnchor, insertionPos, current, completionItem.Member as IMethod, codeForBaseCall.Trim());
dialog.Element = uiService.CreateInlineUIElement(insertionPos, dialog);
textEditor.Document.InsertNormalized(endAnchor.Offset, Environment.NewLine + code.Substring(marker + codeForBaseCall.Length));
insertionContext.RegisterActiveElement(new InlineRefactorSnippetElement(cxt => null, ""), dialog);
insertionContext.RaiseInsertionCompleted(EventArgs.Empty);
}
}
示例12: Insert
/// <inheritdoc />
public override void Insert(InsertionContext context)
{
TextAnchor start = context.Document.CreateAnchor(context.InsertionPosition);
start.MovementType = AnchorMovementType.BeforeInsertion;
start.SurviveDeletion = true;
AnchorSegment segment = new AnchorSegment(start, start);
context.RegisterActiveElement(this, new AnchorElement(segment, Name, context));
}
示例13: OverrideToStringMethodDialog
public OverrideToStringMethodDialog(InsertionContext context, ITextEditor editor, ITextAnchor startAnchor, ITextAnchor anchor, IList<IField> fields, string baseCall)
: base(context, editor, anchor)
{
InitializeComponent();
this.baseCall = baseCall;
this.fields = fields.Select(f => new PropertyOrFieldWrapper(f) { IsSelected = true }).ToList();
this.listBox.ItemsSource = this.fields;
}
示例14: InsertCtorDialog
public InsertCtorDialog(InsertionContext context, ITextEditor editor, ITextAnchor anchor, IClass current, IList<PropertyOrFieldWrapper> possibleParameters)
: base(context, editor, anchor)
{
InitializeComponent();
this.varList.ItemsSource = parameterList = possibleParameters;
if (!parameterList.Any())
Visibility = System.Windows.Visibility.Collapsed;
}
示例15: OverrideToStringMethodDialog
public OverrideToStringMethodDialog(InsertionContext context, ITextEditor editor, ITextAnchor startAnchor, ITextAnchor anchor, IList<IField> fields, string baseCall)
: base(context, editor, anchor)
{
InitializeComponent();
this.baseCall = baseCall;
this.listBox.ItemsSource = fields.Where(f => f.ReturnType != null).Select(f => new PropertyOrFieldWrapper(f)).ToList();
listBox.SelectAll();
}