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


C# ITextEditor.Select方法代码示例

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


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

示例1: Run

 public static void Run(ITextEditor editor, int offset)
 {
     BracketSearchResult result = editor.Language.BracketSearcher.SearchBracket(editor.Document, offset);
     if (result != null) {
         // place caret after the other bracket
         if (result.OpeningBracketOffset <= offset && offset <= result.OpeningBracketOffset + result.OpeningBracketLength) {
             editor.Select(result.ClosingBracketOffset + result.ClosingBracketLength, 0);
         } else {
             editor.Select(result.OpeningBracketOffset + result.OpeningBracketLength, 0);
         }
     }
 }
开发者ID:ichengzi,项目名称:SharpDevelop,代码行数:12,代码来源:GoToMatchingBrace.cs

示例2: SetText

		void SetText(ITextEditor textEditor, string resourceName, string oldText)
		{
			// ensure caret is at start of selection / deselect text
			textEditor.Select(textEditor.SelectionStart, 0);
			// replace the selected text with the new text:
			string newText;
			if (Path.GetExtension(textEditor.FileName) == ".xaml")
				newText = "{core:Localize " + resourceName + "}";
			else
				newText = "$" + "{res:" + resourceName + "}";
			// Replace() takes the arguments: start offset to replace, length of the text to remove, new text
			textEditor.Document.Replace(textEditor.Caret.Offset, oldText.Length, newText);
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:13,代码来源:Command.cs

示例3: Run

		protected override void Run(ITextEditor textEditor, RefactoringProvider provider)
		{
			if (textEditor.SelectionLength > 0) {
				
				MethodExtractorBase extractor = GetCurrentExtractor(textEditor);
				if (extractor != null) {
					if (extractor.Extract()) {
						ExtractMethodForm form = new ExtractMethodForm(extractor.ExtractedMethod, new Func<IOutputAstVisitor>(extractor.GetOutputVisitor));
						
						if (form.ShowDialog() == DialogResult.OK) {
							extractor.ExtractedMethod.Name = form.Text;
							using (textEditor.Document.OpenUndoGroup()) {
								extractor.InsertAfterCurrentMethod();
								extractor.InsertCall();
								textEditor.Language.FormattingStrategy.IndentLines(textEditor, 0, textEditor.Document.TotalNumberOfLines - 1);
							}
							textEditor.Select(textEditor.SelectionStart, 0);
						}
					}
				}
			}
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:22,代码来源:ExtractMethodCommand.cs

示例4: ExecuteIntroduceMethod


//.........这里部分代码省略.........
			CodeGenerator gen = targetClass.ProjectContent.Language.CodeGenerator;
			IAmbience ambience = targetClass.ProjectContent.Language.GetAmbience();
			
			ClassFinder finder = new ClassFinder(rr.CallingMember);
			
			ModifierEnum modifiers = ModifierEnum.None;
			
			bool isExtension = !targetClass.IsUserCode();
			
			if (IsEqualClass(rr.CallingClass, targetClass)) {
				if (rr.CallingMember != null)
					modifiers |= (rr.CallingMember.Modifiers & ModifierEnum.Static);
			} else {
				if (isExtension) {
					if (isNew)
						targetClass = rr.CallingClass;
					else
						targetClass = result as IClass;
				}
				// exclude in Unit Test mode
				if (WorkbenchSingleton.Workbench != null)
					editor = (FileService.OpenFile(targetClass.CompilationUnit.FileName) as ITextEditorProvider).TextEditor;
				if (targetClass.ClassType != ClassType.Interface)
					modifiers |= ModifierEnum.Public;
				if (rr.IsStaticContext)
					modifiers |= ModifierEnum.Static;
			}
			
			NRefactoryResolver resolver = Extensions.CreateResolverForContext(targetClass.ProjectContent.Language, editor);
			
			IReturnType type = resolver.GetExpectedTypeFromContext(invocationExpr);
			Ast.TypeReference typeRef = CodeGenerator.ConvertType(type, finder);
			
			if (typeRef.IsNull) {
				if (invocationExpr.Parent is Ast.ExpressionStatement)
					typeRef = new Ast.TypeReference("void", true);
				else
					typeRef = new Ast.TypeReference("object", true);
			}
			
			Ast.MethodDeclaration method = new Ast.MethodDeclaration {
				Name = rr.CallName,
				Modifier = CodeGenerator.ConvertModifier(modifiers, finder),
				TypeReference = typeRef,
				Parameters = CreateParameters(rr, finder, invocationExpr as Ast.InvocationExpression).ToList(),
			};
			
			if (targetClass.ClassType != ClassType.Interface)
				method.Body = CodeGenerator.CreateNotImplementedBlock();
			
			RefactoringDocumentAdapter documentWrapper = new RefactoringDocumentAdapter(editor.Document);
			
			if (isExtension) {
				method.Parameters.Insert(0, new Ast.ParameterDeclarationExpression(CodeGenerator.ConvertType(rr.Target, finder), "thisInstance"));
				method.IsExtensionMethod = true;
				method.Modifier |= Ast.Modifiers.Static;
			}
			
			if (isNew) {
				Ast.TypeDeclaration newType = new Ast.TypeDeclaration(isExtension ? Ast.Modifiers.Static : Ast.Modifiers.None, null);
				newType.Name = result as string;
				newType.AddChild(method);
				gen.InsertCodeAfter(targetClass, documentWrapper, newType);
			} else {
				if (IsEqualClass(rr.CallingClass, targetClass))
					gen.InsertCodeAfter(rr.CallingMember, documentWrapper, method);
				else
					gen.InsertCodeAtEnd(targetClass.BodyRegion, documentWrapper, method);
			}
			
			if (targetClass.ClassType == ClassType.Interface)
				return;
			
			ParseInformation info = ParserService.ParseFile(targetClass.CompilationUnit.FileName);
			if (info != null) {
				IMember newMember;
				
				if (isNew)
					targetClass = info.CompilationUnit.Classes.FirstOrDefault(c => c.DotNetName == c.Namespace + "." + (result as string));
				else
					targetClass = info.CompilationUnit.Classes.Flatten(c => c.InnerClasses).FirstOrDefault(c => c.DotNetName == targetClass.DotNetName);
				
				if (targetClass == null)
					return;
				
				if (IsEqualClass(rr.CallingClass, targetClass)) {
					newMember = targetClass.GetInnermostMember(editor.Caret.Line, editor.Caret.Column);
					newMember = targetClass.AllMembers
						.OrderBy(m => m.BodyRegion.BeginLine)
						.ThenBy(m2 => m2.BodyRegion.BeginColumn)
						.First(m3 => m3.BodyRegion.BeginLine > newMember.BodyRegion.BeginLine);
				} else {
					newMember = targetClass.Methods.Last();
				}
				
				IDocumentLine line = editor.Document.GetLine(newMember.BodyRegion.BeginLine + 2);
				int indentLength = DocumentUtilitites.GetWhitespaceAfter(editor.Document, line.Offset).Length;
				editor.Select(line.Offset + indentLength, "throw new NotImplementedException();".Length);
			}
		}
开发者ID:Rpinski,项目名称:SharpDevelop,代码行数:101,代码来源:GenerateCode.cs

示例5: SelectText

		static void SelectText(Selection selection, ITextEditor editor)
		{
			int startOffset, endOffset;
			try {
				startOffset = editor.Document.PositionToOffset(selection.Start);
				endOffset = editor.Document.PositionToOffset(selection.End);
			} catch (ArgumentOutOfRangeException) {
				return;
			}
			editor.Select(startOffset, endOffset - startOffset);
		}
开发者ID:hpsa,项目名称:SharpDevelop,代码行数:11,代码来源:CodeManipulation.cs

示例6: AddCodeToMethodStart

		/// <summary>
		/// C# only.
		/// </summary>
		public static void AddCodeToMethodStart(IMember m, ITextEditor textArea, string newCode)
		{
			int methodStart = FindMethodStartOffset(textArea.Document, m.BodyRegion);
			if (methodStart < 0)
				return;
			textArea.Select(methodStart, 0);
			using (textArea.Document.OpenUndoGroup()) {
				int startLine = textArea.Caret.Line;
				foreach (string newCodeLine in newCode.Split('\n')) {
					textArea.Document.Insert(textArea.Caret.Offset,
					                         DocumentUtilitites.GetLineTerminator(textArea.Document, textArea.Caret.Line) + newCodeLine);
				}
				int endLine = textArea.Caret.Line;
				textArea.Language.FormattingStrategy.IndentLines(textArea, startLine, endLine);
			}
		}
开发者ID:hpsa,项目名称:SharpDevelop,代码行数:19,代码来源:Extensions.cs

示例7: SurroundSelectionWithBlockComment

        /// <summary>
        /// Default implementation for multiline comments.
        /// </summary>
        protected void SurroundSelectionWithBlockComment(ITextEditor editor, string blockStart, string blockEnd)
        {
            using (editor.Document.OpenUndoGroup()) {
                int startOffset = editor.SelectionStart;
                int endOffset = editor.SelectionStart + editor.SelectionLength;

                if (editor.SelectionLength == 0) {
                    IDocumentLine line = editor.Document.GetLineByOffset(editor.SelectionStart);
                    startOffset = line.Offset;
                    endOffset = line.Offset + line.Length;
                }

                BlockCommentRegion region = FindSelectedCommentRegion(editor, blockStart, blockEnd);

                if (region != null) {
                    do {
                        editor.Document.Remove(region.EndOffset, region.CommentEnd.Length);
                        editor.Document.Remove(region.StartOffset, region.CommentStart.Length);

                        int selectionStart = region.EndOffset;
                        int selectionLength = editor.SelectionLength - (region.EndOffset - editor.SelectionStart);

                        if(selectionLength > 0) {
                            editor.Select(region.EndOffset, selectionLength);
                            region = FindSelectedCommentRegion(editor, blockStart, blockEnd);
                        } else {
                            region = null;
                        }
                    } while(region != null);

                } else {
                    editor.Document.Insert(endOffset, blockEnd);
                    editor.Document.Insert(startOffset, blockStart);
                }
            }
        }
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:39,代码来源:IFormattingStrategy.cs

示例8: Complete

			public override void Complete(CompletionContext context)
			{
				base.Complete(context);
				
				// save a reference to the relevant textArea so that we can remove our event handlers after the next keystroke
				editor = context.Editor;
				// select suggested name
				editor.Caret.Column -= this.selectionBeginOffset;
				editor.Select(editor.Caret.Offset, this.selectionLength);

				// TODO: refactor ToolTip architecture to allow for showing a tooltip relative to the current caret position so that we can show our "press TAB to create this method" text as a text-based tooltip
				
				// TODO: skip the auto-insert step if the method already exists, or change behavior so that it moves the caret inside the existing method.

				// attach our keydown filter to catch the next character pressed
				editor.SelectionChanged += EditorSelectionChanged;
				editor.KeyPress += EditorKeyPress;
			}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:18,代码来源:EventHandlerCompletionItemProvider.cs


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