سؤال

I'm trying to open the find dialog in my VS2012 extension but I'm unable to set any options other than the find text:

    var dte=(_DTE)Package.GetGlobalService(typeof(_DTE));
    dte.ExecuteCommand("Edit.Find");

    // this gets set:
    dte.Find.FindWhat="test";

    // but all others are ignored:
    dte.Find.Target=vsFindTarget.vsFindTargetSolution;
    dte.Find.MatchCase=false;
    dte.Find.MatchWholeWord=true;

Am I missing something? I'm using VS 2012 Update 1.


Thanks to Ameen I'm now trying a different approach, however I can't find any documentation on how I need to set the arguments when raising commands:

    object a=false;
    object b=null;
    dte.Commands.Raise(
      VSConstants.GUID_VSStandardCommandSet97.ToString("B").ToUpper(),
      (int)VSConstants.VSStd97CmdID.FindMatchCase, ref a, ref b);

This will always give me an E_INVALIDARG.

هل كانت مفيدة؟

المحلول

The DTE.Find object is stateful. It will flush down its state to the find dialog when you call the Execute method on it. In other words, it does not allow you to change the search options without executing a search.

The setting of the search term is a separate matter. Under the hoods, there is a cmdidSetSearchCombo (recalling from memory) that allows you to only set the search term and that command is executed when you set the FindWhat field of DTE.Find.

As a workaround, you can execute a search with a control character to flush the settings down to the dialog. I'd use a \r\n as the search term and simultaneously unset the multi-line search option guaranteeing that no matches will be found. Needless to say this is a hack and you should resort to this if all else fails and you are about to cry.

Are you trying to do a search in the text editor? The editor exposes the ITextSearchService2 service via MEF which will allow you to do searches scoped to a single document without the need to interact with the find dialog.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top