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


C# IDocument.Insert方法代码示例

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


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

示例1: InsertCodeAtEnd

		/// <summary>
		/// Ensure that code is inserted correctly in {} code blocks - SD2-1180
		/// </summary>
		public override void InsertCodeAtEnd(DomRegion region, IDocument document, params AbstractNode[] nodes)
		{
			string beginLineIndentation = GetIndentation(document, region.BeginLine);
			int insertionLine = region.EndLine - 1;
			
			IDocumentLine endLine = document.GetLine(region.EndLine);
			string endLineText = endLine.Text;
			int originalPos = region.EndColumn - 2; // -1 for column coordinate => offset, -1 because EndColumn is after the '}'
			int pos = originalPos;
			if (pos >= endLineText.Length || endLineText[pos] != '}') {
				LoggingService.Warn("CSharpCodeGenerator.InsertCodeAtEnd: position is invalid (not pointing to '}')"
				                    + " endLineText=" + endLineText + ", pos=" + pos);
			} else {
				for (pos--; pos >= 0; pos--) {
					if (!char.IsWhiteSpace(endLineText[pos])) {
						// range before '}' is not empty: we cannot simply insert in the line before the '}', so
						// 
						pos++; // set pos to first whitespace character / the '{' character
						if (pos < originalPos) {
							// remove whitespace between last non-white character and the '}'
							document.Remove(endLine.Offset + pos, originalPos - pos);
						}
						// insert newline and same indentation as used in beginLine before the '}'
						document.Insert(endLine.Offset + pos, Environment.NewLine + beginLineIndentation);
						insertionLine++;
						
						pos = region.BeginColumn - 1;
						if (region.BeginLine == region.EndLine && pos >= 1 && pos < endLineText.Length) {
							// The whole block was in on a single line, e.g. "get { return field; }".
							// Insert an additional newline after the '{'.
							
							originalPos = pos = endLineText.IndexOf('{', pos);
							if (pos >= 0 && pos < region.EndColumn - 1) {
								// find next non-whitespace after originalPos
								originalPos++; // point to insertion position for newline after {
								for (pos++; pos < endLineText.Length; pos++) {
									if (!char.IsWhiteSpace(endLineText[pos])) {
										// remove all between originalPos and pos
										if (originalPos < pos) {
											document.Remove(endLine.Offset + originalPos, pos - originalPos);
										}
										document.Insert(endLine.Offset + originalPos, Environment.NewLine + beginLineIndentation + '\t');
										insertionLine++;
										break;
									}
								}
							}
						}
						break;
					}
				}
			}
			InsertCodeAfter(insertionLine, document, beginLineIndentation + this.Options.IndentString, nodes);
		}
开发者ID:Adam-Fogle,项目名称:agentralphplugin,代码行数:57,代码来源:CSharpCodeGenerator.cs

示例2: TryFix

		public override bool TryFix(ConstructFixer fixer, SyntaxTree syntaxTree, IDocument document, TextLocation location, ref int newOffset)
		{
			var typeDeclaration = syntaxTree.GetNodeAt<DelegateDeclaration>(location); 
			if (typeDeclaration != null) {
				if (typeDeclaration.RParToken.IsNull) {
					var lastNode = GetLastNonErrorChild (typeDeclaration);
					if (lastNode == null)
						return false;
					var insertionOffset = document.GetOffset(lastNode.EndLocation);
					document.Insert(insertionOffset, ");\n");
					newOffset += ");\n".Length;
					return true;
				}
			}
			return false;
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:16,代码来源:ConstructFixer.cs

示例3: InsertEventHandler

		public override int InsertEventHandler(IDocument document, string eventHandler)
		{
			int line = document.TotalNumberOfLines;
			IDocumentLine lastLineSegment = document.GetLine(line);
			int offset = lastLineSegment.Offset + lastLineSegment.Length;

			string newContent = "\r\n" + eventHandler;
			if (lastLineSegment.Length > 0) {
				// Add an extra new line between the last line and the event handler.
				newContent = "\r\n" + newContent;
			}
			document.Insert(offset, newContent);
			
			// Set position so it points to the line
			// where the event handler was inserted.
			return line + 1;
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:17,代码来源:PythonDesignerGenerator.cs

示例4: InsertTabs

		void InsertTabs(IDocument document, ISelection selection, int y1, int y2)
		{
			string indentationString = GetIndentationString(document);
			for (int i = y2; i >= y1; --i) {
				LineSegment line = document.GetLineSegment(i);
				if (i == y2 && i == selection.EndPosition.Y && selection.EndPosition.X  == 0) {
					continue;
				}
				
				// this bit is optional - but useful if you are using block tabbing to sort out
				// a source file with a mixture of tabs and spaces
//				string newLine = document.GetText(line.Offset,line.Length);
//				document.Replace(line.Offset,line.Length,newLine);
				
				document.Insert(line.Offset, indentationString);
			}
		}
开发者ID:lisiynos,项目名称:pascalabcnet,代码行数:17,代码来源:MiscActions.cs

示例5: InsertNewLine

		void InsertNewLine (IDocument document, NewLineInsertion insertion, ref int offset)
		{
			string eolMarker = DocumentUtilities.GetLineTerminator(document, 1);
			string str = null;
			switch (insertion) {
				case NewLineInsertion.Eol:
					str = eolMarker;
					break;
				case NewLineInsertion.BlankLine:
					str = eolMarker + eolMarker;
					break;
				default:
					return;
			}
			
			document.Insert (offset, str);
			offset += str.Length;
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:18,代码来源:InsertionPoint.cs

示例6: InsertTabs

		void InsertTabs(IDocument document, ISelection selection, int y1, int y2)
		{
			int    redocounter = 0;
			string indentationString = GetIndentationString(document);
			for (int i = y2; i >= y1; --i) {
				LineSegment line = document.GetLineSegment(i);
				if (i == y2 && i == selection.EndPosition.Y && selection.EndPosition.X  == 0) {
					continue;
				}
				
				document.Insert(line.Offset, indentationString);
				++redocounter;
			}
			
			if (redocounter > 0) {
				document.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes)
			}
		}
开发者ID:tangxuehua,项目名称:DataStructure,代码行数:18,代码来源:MiscActions.cs

示例7: InsertTabs

		void InsertTabs(IDocument document, ISelection selection, int y1, int y2)
		{
			int    redocounter = 0;
			string indentationString = GetIndentationString(document);
			for (int i = y2; i >= y1; --i) {
				LineSegment line = document.GetLineSegment(i);
				if (i == y2 && i == selection.EndPosition.Y && selection.EndPosition.X  == 0) {
					continue;
				}
				
				// this bit is optional - but useful if you are using block tabbing to sort out
				// a source file with a mixture of tabs and spaces
//				string newLine = document.GetText(line.Offset,line.Length);
//				document.Replace(line.Offset,line.Length,newLine);
//				++redocounter;
				
				document.Insert(line.Offset, indentationString);
				++redocounter;
			}
			
			if (redocounter > 0) {
				document.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes)
			}
		}
开发者ID:viticm,项目名称:pap2,代码行数:24,代码来源:MiscActions.cs

示例8: SetCommentAt

 void SetCommentAt(IDocument document, int offsetStart, int offsetEnd, string commentStart, string commentEnd)
 {
     document.Insert(offsetEnd, commentEnd);
     document.Insert(offsetStart, commentStart);
 }
开发者ID:KindDragon,项目名称:ICSharpCode.TextEditor.V4,代码行数:5,代码来源:MiscActions.cs

示例9: SetCommentAt

        void SetCommentAt(IDocument document, string comment, ISelection selection, int y1, int y2)
        {
            int  redocounter = 0;
            firstLine = y1;
            lastLine  = y2;

            for (int i = y2; i >= y1; --i) {
                LineSegment line = document.GetLineSegment(i);
                if (selection != null && i == y2 && line.Offset == selection.Offset + selection.Length) {
                    --lastLine;
                    continue;
                }

                string lineText = document.GetText(line.Offset, line.Length);
                document.Insert(line.Offset, comment);
                ++redocounter;
            }

            if (redocounter > 0) {
                document.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes)
            }
        }
开发者ID:slluis,项目名称:monodevelop-prehistoric,代码行数:22,代码来源:MiscActions.cs

示例10: CreateComponentEvent

		// static method that for use by the WPF designer
		public static void CreateComponentEvent(
			IClass c, IDocument document,
			Type eventType, string eventMethodName, string body, out int lineNumber)
		{
			if (c == null)
				throw new ArgumentNullException("c");
			if (document == null)
				throw new ArgumentNullException("document");
			if (eventType == null)
				throw new ArgumentNullException("edesc");
			
			CSharpDesignerGenerator gen = new CSharpDesignerGenerator();
			
			gen.CurrentClassPart = c;
			int line = gen.GetEventHandlerInsertionLine(c);
			
			int offset = document.GetLineSegment(line - 1).Offset;
			
			string tabs = SharpDevelop.DefaultEditor.Gui.Editor.SharpDevelopTextEditorProperties.Instance.IndentationString;
			tabs += tabs;
			
			document.Insert(offset, gen.CreateEventHandler(eventType, eventMethodName, body, tabs));
			lineNumber = line + gen.GetCursorLineAfterEventHandlerCreation();
		}
开发者ID:kingjiang,项目名称:SharpDevelopLite,代码行数:25,代码来源:CSharpDesignerGenerator.cs

示例11: SetCommentAt

 void SetCommentAt(IDocument document, int offsetStart, int offsetEnd, string commentStart, string commentEnd)
 {
     document.Insert(offsetEnd, commentEnd);
     document.Insert(offsetStart, commentStart);
     document.UndoStack.CombineLast(2);
 }
开发者ID:jumpinjackie,项目名称:fdotoolbox,代码行数:6,代码来源:MiscActions.cs

示例12: SetCommentAt

        void SetCommentAt(IDocument document, string comment, ISelection selection, int y1, int y2)
        {
            firstLine = y1;
            lastLine  = y2;

            for (int i = y2; i >= y1; --i) {
                LineSegment line = document.GetLineSegment(i);
                if (selection != null && i == y2 && line.Offset == selection.Offset + selection.Length) {
                    --lastLine;
                    continue;
                }

                document.Insert(line.Offset, comment);
            }
        }
开发者ID:umabiel,项目名称:WsdlUI,代码行数:15,代码来源:MiscActions.cs

示例13: Insert

		public int Insert (IDocument document, string text)
		{
			int offset = document.GetOffset (Location);
			using (var undo = document.OpenUndoGroup ()) {
				text = DocumentUtilities.NormalizeNewLines(text, document, Location.Line);
				
				var line = document.GetLineByOffset (offset);
				int insertionOffset = line.Offset + Location.Column - 1;
				offset = insertionOffset;
				InsertNewLine (document, LineBefore, ref offset);
				
				document.Insert (offset, text);
				offset += text.Length;
				InsertNewLine (document, LineAfter, ref offset);
				return offset;
			}
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:17,代码来源:InsertionPoint.cs

示例14: InsertEventHandlerBeforeLine

		void InsertEventHandlerBeforeLine(IDocument doc, string eventHandler, IDocumentLine classEndLine)
		{
			string newContent = "\r\n" + eventHandler + "\r\n";
			int offset = classEndLine.Offset;
			doc.Insert(offset, newContent);
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:6,代码来源:RubyDesignerGenerator.cs


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