Search code examples
c#visual-studiovisual-studio-2012vs-extensibility

Switch Task List to comments mode


I've written a Visual Studio project template that includes quite a few files. A few of those files have some extra elements that need to be filled in after the template is complete1, so I've marked those up with //TODO - style comments.

After the template has finished executing, I'd like to make sure that those tasks are obvious by showing the Task List in "Comments" mode (as opposed to "User Tasks" mode, the mode being selected from the drop-down at the top of the Task List window).

The project template already has a wizard (IWizard based) so I'm just trying to extend the wizard slightly to add this step in.

In the RunStarted, I'm grabbing the automationObject and casting it to DTE:

_dte = (DTE)automationObject;

And then in the RunFinished method, I'm calling my own ShowTaskList method:

protected void ShowTaskList()
{
    //Can't use EnvDTE.Constants class here because of embedded interop types
    var wind = _dte.Windows.Item(EnvDTE_Constants_vsWindowKindTaskList);
    wind.Activate();
}

private const string EnvDTE_Constants_vsWindowKindTaskList =
    "{4A9B7E51-AA16-11D0-A8C5-00A0C921A4D2}";

And yay, it works. Unfortunately, it defaults to whatever mode the task list was last shown in, which I believe defaults to "User Tasks". I really want it to be in "Comments" mode.

I've looked around at the TaskList interface and the Window interface (both also part of EnvDTE) but I'm just not having much luck trying to find the right interface and method/property to ask it to change mode.

How do I extend my ShowTaskList method to make this happen?


1Ideally I'd gather this information as part of the template but all I can find ways to do is to put up rather anaemic looking forms with basic text input and no way to help the user to select other assemblies/types/methods at this point so I've decided to leave them as //TODOs and then at least the user gets the benefit of e.g. Intellisense.


Solution

  • There is a command to filter the task list that receives the filter as command parameter. See:

    HOWTO: Add a filtered task with navigation to the Task List from a Visual Studio add-in

    http://www.visualstudioextensibility.com/articles/add-ins/

    You can also get native services from DTE:

    HOWTO: Get a Visual Studio service from an add-in (Same link)

    And then use the native IVSTaskList interface, the AutoFilter method that receives the category parameter (User comments, TODOs, etc):

    https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivstasklist.autofilter.aspx