当前位置: 首页>>代码示例>>C#>>正文


C# InsertionContext.RaiseInsertionCompleted方法代码示例

本文整理汇总了C#中ICSharpCode.AvalonEdit.Snippets.InsertionContext.RaiseInsertionCompleted方法的典型用法代码示例。如果您正苦于以下问题:C# InsertionContext.RaiseInsertionCompleted方法的具体用法?C# InsertionContext.RaiseInsertionCompleted怎么用?C# InsertionContext.RaiseInsertionCompleted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICSharpCode.AvalonEdit.Snippets.InsertionContext的用法示例。


在下文中一共展示了InsertionContext.RaiseInsertionCompleted方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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

示例2: 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

示例3: 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
				insertionPosition = selection.Offset; // 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.
			
			InsertionContext context = new InsertionContext(textArea, insertionPosition);
			
			if (selection != null)
				textArea.Document.Remove(selection);
			
			using (context.Document.RunUpdate()) {
				Insert(context);
				context.RaiseInsertionCompleted(EventArgs.Empty);
			}
		}
开发者ID:pusp,项目名称:o2platform,代码行数:26,代码来源:Snippet.cs

示例4: Complete

		public override void Complete(CompletionContext context)
		{
			if (declarationBegin > context.StartOffset) {
				base.Complete(context);
				return;
			}
			
			TypeSystemAstBuilder b = new TypeSystemAstBuilder(contextAtCaret);
			b.ShowTypeParameterConstraints = false;
			b.GenerateBody = true;
			
			var entityDeclaration = b.ConvertEntity(this.Entity);
			entityDeclaration.Modifiers &= ~(Modifiers.Virtual | Modifiers.Abstract);
			entityDeclaration.Modifiers |= Modifiers.Override;
			
			var body = entityDeclaration.GetChildByRole(Roles.Body);
			Statement baseCallStatement = body.Children.OfType<Statement>().FirstOrDefault();
			
			if (!this.Entity.IsAbstract) {
				// modify body to call the base method
				if (this.Entity.SymbolKind == SymbolKind.Method) {
					var baseCall = new BaseReferenceExpression().Invoke(this.Entity.Name, new Expression[] { });
					if (((IMethod)this.Entity).ReturnType.IsKnownType(KnownTypeCode.Void))
						baseCallStatement = new ExpressionStatement(baseCall);
					else
						baseCallStatement = new ReturnStatement(baseCall);
					
					// Clear body of inserted method
					entityDeclaration.GetChildByRole(Roles.Body).Statements.Clear();
				}
			}
			
			var document = context.Editor.Document;
			StringWriter w = new StringWriter();
			var formattingOptions = FormattingOptionsFactory.CreateSharpDevelop();
			var segmentDict = SegmentTrackingOutputFormatter.WriteNode(w, entityDeclaration, formattingOptions, context.Editor.Options);
			
			using (document.OpenUndoGroup()) {
				InsertionContext insertionContext = new InsertionContext(context.Editor.GetService(typeof(TextArea)) as TextArea, declarationBegin);
				insertionContext.InsertionPosition = context.Editor.Caret.Offset;
				
				string newText = w.ToString().TrimEnd();
				document.Replace(declarationBegin, context.EndOffset - declarationBegin, newText);
				var throwStatement = entityDeclaration.Descendants.FirstOrDefault(n => n is ThrowStatement);
				if (throwStatement != null) {
					var segment = segmentDict[throwStatement];
					context.Editor.Select(declarationBegin + segment.Offset, segment.Length);
				}
				CSharpFormatterHelper.Format(context.Editor, declarationBegin, newText.Length, formattingOptions);
				
				var refactoringContext = SDRefactoringContext.Create(context.Editor, CancellationToken.None);
				var typeResolveContext = refactoringContext.GetTypeResolveContext();
				if (typeResolveContext == null) {
					return;
				}
				var resolvedCurrent = typeResolveContext.CurrentTypeDefinition;
				var entities = FindFieldsAndProperties(resolvedCurrent).ToList();
				if (entities.Any()) {
					IEditorUIService uiService = context.Editor.GetService(typeof(IEditorUIService)) as IEditorUIService;
					
					ITextAnchor endAnchor = context.Editor.Document.CreateAnchor(context.Editor.Caret.Offset);
					endAnchor.MovementType = AnchorMovementType.AfterInsertion;
					
					ITextAnchor startAnchor = context.Editor.Document.CreateAnchor(context.Editor.Caret.Offset);
					startAnchor.MovementType = AnchorMovementType.BeforeInsertion;
					
					ITextAnchor insertionPos = context.Editor.Document.CreateAnchor(endAnchor.Offset);
					insertionPos.MovementType = AnchorMovementType.BeforeInsertion;

					AbstractInlineRefactorDialog dialog = new OverrideToStringMethodDialog(insertionContext, context.Editor, insertionPos, entities, baseCallStatement);
					dialog.Element = uiService.CreateInlineUIElement(insertionPos, dialog);
					
					insertionContext.RegisterActiveElement(new InlineRefactorSnippetElement(cxt => null, ""), dialog);
				} else {
					if (baseCallStatement != null) {
						// Add default base call
						MethodDeclaration insertedOverrideMethod = refactoringContext.GetNode().PrevSibling as MethodDeclaration;
						if (insertedOverrideMethod == null)
						{
							// We are not inside of a method declaration
							return;
						}
						using (Script script = refactoringContext.StartScript()) {
							script.AddTo(insertedOverrideMethod.Body, baseCallStatement);
						}
					}
				}
				
				insertionContext.RaiseInsertionCompleted(EventArgs.Empty);
			}
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:91,代码来源:OverrideToStringCompletionData.cs

示例5: 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

示例6: Complete

 public void Complete(TextArea textArea, ISegment completionSegment, EventArgs insertionRequestEventArgs)
 {
     var context = new InsertionContext(textArea, completionSegment.Offset);
     var sni = new SnippetContainerElement();
     sni.Elements.Add(new SnippetTextElement{Text = Name + "("});
     foreach (var argument in Arguments)
     {
         var element = new SnippetReplaceableTextElement{Text = argument.ToString()};
         sni.Elements.Add(element);
         sni.Elements.Add(new SnippetTextElement{Text = ", "});
     }
     if (Arguments.Count > 0) sni.Elements.RemoveAt(sni.Elements.Count - 1);
     sni.Elements.Add(new SnippetTextElement{Text = ")"});
     textArea.Document.Remove(completionSegment);
     sni.Insert(context);
     context.RaiseInsertionCompleted(null);
 }
开发者ID:itsbth,项目名称:E2Edit,代码行数:17,代码来源:Function.cs


注:本文中的ICSharpCode.AvalonEdit.Snippets.InsertionContext.RaiseInsertionCompleted方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。