Compartir a través de


Find2 Interface

Supports general text Find operations in the environment for documents and files.

Namespace:  EnvDTE80
Assembly:  EnvDTE80 (in EnvDTE80.dll)

Syntax

'Declaration
<GuidAttribute("01568308-5B2A-4F30-8D0A-E10EE0F28F4A")> _
Public Interface Find2 _
    Inherits Find
[GuidAttribute("01568308-5B2A-4F30-8D0A-E10EE0F28F4A")]
public interface Find2 : Find
[GuidAttribute(L"01568308-5B2A-4F30-8D0A-E10EE0F28F4A")]
public interface class Find2 : Find
[<GuidAttribute("01568308-5B2A-4F30-8D0A-E10EE0F28F4A")>]
type Find2 =  
    interface 
        interface Find 
    end
public interface Find2 extends Find

The Find2 type exposes the following members.

Properties

  Name Description
Public property Action Gets or sets how to find, such as find next match, find all, replace and find, and so forth.
Public property Backwards Gets or sets a value indicating whether the search is performed backwards from the current position.
Public property DTE Gets the top-level extensibility object.
Public property FilesOfType Gets or sets the file extension for the files to be searched.
Public property FindWhat Gets or sets the text or pattern to find.
Public property KeepModifiedDocumentsOpen Gets or sets a value indicating whether or not modified documents remain open after a replace operation.
Public property MatchCase Gets or sets a value indicating whether the search is case-sensitive.
Public property MatchInHiddenText Gets or sets a value indicating whether hidden text is included in the search.
Public property MatchWholeWord Gets or sets a value indicating whether the search matches whole words only.
Public property Parent Gets the immediate parent object of a Find object.
Public property PatternSyntax Gets or sets the syntax used to specify the search pattern.
Public property ReplaceWith Gets or sets the replacement text for a replacement operation.
Public property ResultsLocation Gets or sets the location where the results are shown in a bulk search operation.
Public property SearchPath Gets or sets a list of directories to use for a find-in-files operation.
Public property SearchSubfolders Gets or sets a value indicating whether subfolders are included in a search operation.
Public property Target Gets or sets the target of the search operation, such as all open docs, files, the active document, and so forth.
Public property WaitForFindToComplete Gets or sets a value indicating whether a find result is returned before continuing execution.

Top

Methods

  Name Description
Public method Execute Performs a search based on the options set for the Find object.
Public method FindReplace Performs a Find or Replace operation based on the arguments to the method, without affecting the options set for the Find object.

Top

Remarks

The Find object allows you to find and replace text in places of the environment that support such operations, such as the Code editor.

It is intended primarily for macro recording purposes. The editor's macro recording mechanism uses Find rather than TextSelection.FindPattern so that you can discover the global find functionality. Furthermore, it is generally more useful than using the TextSelection object for such operations as Find-in-files.

The Visual Studio environment's global find state is shared across all its tools and provides search capabilities. For example, all Visual Studio elements share the history of search patterns used during a session and whether the next Find operation for open documents should be forwards or backwards. The Find object's properties interact with and track the global find state. When you set properties on the Find object, you also set the global find state. If users perform a Find operation through the environment, the Find object reflects the kind of search they performed. Since automation code runs synchronously with the environment's UI thread, you do not need to worry about setting some properties and having the user perform a search before you can call the Execute.

The Execute method performs a Find operation based on the settings of the Find object. You can also pass arguments to the FindReplace method to perform a search without affecting the global find state. It is important for automation clients to be able to perform a search without affecting the global find state or interfering with the end user's model of the environment's state.

Examples

Sub FindExample()
   Dim objTextDoc As TextDocument
   Dim objEditPt As EditPoint
   Dim iCtr As Integer
   Dim objFind As Find

   ' Create a new text file.
   DTE.ItemOperations.NewFile("General\Text File")

   ' Get a handle to the new document and create an EditPoint.
   objTextDoc = DTE.ActiveDocument.Object("TextDocument")
   objEditPt = objTextDoc.StartPoint.CreateEditPoint
   objFind = objTextDoc.DTE.Find

   ' Insert ten lines of text.
   For iCtr = 1 To 10
      objEditPt.Insert("This is a test." & Chr(13))
   Next iCtr

   ' Set the find options.
   objFind.Action = vsFindAction.vsFindActionReplaceAll
   objFind.Backwards = False
   objFind.FilesOfType = "*.txt"
   objFind.FindWhat = "test"
   objFind.KeepModifiedDocumentsOpen = True
   objFind.MatchCase = False
   objFind.MatchInHiddenText = False
   objFind.MatchWholeWord = True
   objFind.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxLiteral
   objFind.ReplaceWith = "NEW THING"
   objFind.ResultsLocation = vsFindResultsLocation.vsFindResultsNone
   objFind.SearchPath = "c:\temp"
   objFind.SearchSubfolders = False
   objFind.Target = vsFindTarget.vsFindTargetCurrentDocument
   ' Perform the Find operation.
   objFind.Execute()
End Sub

See Also

Reference

EnvDTE80 Namespace