本文整理汇总了C#中ICSharpCode.AvalonEdit.Snippets.InsertionContext类的典型用法代码示例。如果您正苦于以下问题:C# InsertionContext类的具体用法?C# InsertionContext怎么用?C# InsertionContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InsertionContext类属于ICSharpCode.AvalonEdit.Snippets命名空间,在下文中一共展示了InsertionContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:nataviva,项目名称:SharpDevelop-1,代码行数:26,代码来源:EditorScript.cs
示例2: InsertCtorDialog
public InsertCtorDialog(InsertionContext context, ITextEditor editor, ITextAnchor anchor)
: base(context, editor, anchor)
{
InitializeComponent();
Visibility = System.Windows.Visibility.Collapsed;
}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:7,代码来源:InsertCtorDialog.xaml.cs
示例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;
}
);
}
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:31,代码来源:OverrideEqualsGetHashCodeMethodsDialog.xaml.cs
示例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);
}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:10,代码来源:SwitchBodySnippetElement.cs
示例5: BoundActiveElement
public BoundActiveElement(InsertionContext context, SnippetReplaceableTextElement targetSnippetElement, SnippetBoundElement boundElement, AnchorSegment segment)
{
this.context = context;
this.targetSnippetElement = targetSnippetElement;
this.boundElement = boundElement;
this.segment = segment;
}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:7,代码来源:SnippetBoundElement.cs
示例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));
}
开发者ID:AkshayVats,项目名称:SuperShell,代码行数:8,代码来源:SnippetReplaceableTextElement.cs
示例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;
}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:10,代码来源:SnippetAnchorElement.cs
示例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);
}
}
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:32,代码来源:Snippet.cs
示例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;
}
}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:30,代码来源:CreateProperties.cs
示例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;
}
);
}
开发者ID:nylen,项目名称:SharpDevelop,代码行数:34,代码来源:OverrideEqualsGetHashCodeMethodsDialog.xaml.cs
示例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);
}
}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:59,代码来源:OverrideEqualsGetHashCodeMethodsRefactoring.cs
示例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));
}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:9,代码来源:SnippetAnchorElement.cs
示例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;
}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:9,代码来源:OverrideToStringMethodDialog.xaml.cs
示例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;
}
开发者ID:hpsa,项目名称:SharpDevelop,代码行数:10,代码来源:InsertCtorDialog.xaml.cs
示例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();
}
开发者ID:dondublon,项目名称:SharpDevelop,代码行数:10,代码来源:OverrideToStringMethodDialog.xaml.cs
示例16: SetCaret
internal static void SetCaret(InsertionContext context)
{
TextAnchor pos = context.Document.CreateAnchor(context.InsertionPosition);
pos.SurviveDeletion = true;
context.Deactivated += (sender, e) => {
if (e.Reason == DeactivateReason.ReturnPressed || e.Reason == DeactivateReason.NoActiveElements) {
context.TextArea.Caret.Offset = pos.Offset;
}
};
}
开发者ID:Amichai,项目名称:PhysicsPad,代码行数:10,代码来源:SnippetCaretElement.cs
示例17: OverrideToStringMethodDialog
public OverrideToStringMethodDialog(InsertionContext context, ITextEditor editor, ITextAnchor startAnchor, ITextAnchor anchor, IList<PropertyOrFieldWrapper> fields, string baseCall)
: base(context, editor, anchor)
{
InitializeComponent();
this.baseCall = baseCall;
this.listBox.ItemsSource = fields;
listBox.SelectAll();
}
开发者ID:Rpinski,项目名称:SharpDevelop,代码行数:10,代码来源:OverrideToStringMethodDialog.xaml.cs
示例18: OverrideToStringMethodDialog
public OverrideToStringMethodDialog(InsertionContext context, ITextEditor editor, ITextAnchor anchor, IList<PropertyOrFieldWrapper> fields, AstNode baseCallNode)
: base(context, editor, anchor)
{
InitializeComponent();
this.baseCallNode = baseCallNode;
parameterList = fields;
this.listBox.ItemsSource = fields;
SelectAllChecked();
}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:11,代码来源:OverrideToStringMethodDialog.xaml.cs
示例19: AbstractInlineRefactorDialog
protected AbstractInlineRefactorDialog(InsertionContext context, ITextEditor editor, ITextAnchor anchor)
{
if (context == null)
throw new ArgumentNullException("context");
this.anchor = insertionEndAnchor = anchor;
this.editor = editor;
this.context = context;
this.classFinderContext = new ClassFinder(ParserService.ParseCurrentViewContent(), editor.Document.Text, anchor.Offset);
this.Background = SystemColors.ControlBrush;
}
开发者ID:nylen,项目名称:SharpDevelop,代码行数:13,代码来源:AbstractInlineRefactorDialog.cs
示例20: Insert
/// <inheritdoc/>
public override void Insert(InsertionContext context)
{
if (targetElement != null) {
int start = context.InsertionPosition;
string inputText = targetElement.Text;
if (inputText != null) {
context.InsertText(ConvertText(inputText));
}
int end = context.InsertionPosition;
AnchorSegment segment = new AnchorSegment(context.Document, start, end - start);
context.RegisterActiveElement(this, new BoundActiveElement(context, targetElement, this, segment));
}
}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:14,代码来源:SnippetBoundElement.cs
注:本文中的ICSharpCode.AvalonEdit.Snippets.InsertionContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论