CSharpie
CSharpie

Reputation: 9467

Visual Studio Command for going to a specific item in source control explorer

Im looking for a way to automatically open Source Control Explorer from inside a plugincode. So far I managed to open it by executing the command

View.TfsSourceControlExplorer

However, this does not seem to accept any arguments.

My goal here is to do something like this:

destination = "$/dev/framework/someFolder";

_dteObject.ExecuteCommand("View.TfsSourceControlExplorer", destination);

Which will them show me Source Control Explorer in the specified destination.

Upvotes: 1

Views: 475

Answers (3)

Yvanddivans
Yvanddivans

Reputation: 31

To anwser CSharpie's comment :

Also there seems to be a bug, if you call navigate to a file of the same directory as the explorer currently is in, everything will disappear.

I had the same problem, got two ways of solving this :

  • Truncate the filename from the path to only Navigate to folders.
  • Navigate to root first ("$/"), then navigate to the file you want.

Both works fine in VS2013.

And thanks for the "Application.DoEvent()" fix when the SourceControlExplorer's not opened.

Upvotes: 3

Sergey Vlasov
Sergey Vlasov

Reputation: 27880

Use the following code to show Source Control Explorer in the specified destination:

    public void SelectFolder(string path)
    {
        dte.ExecuteCommand("View.TfsSourceControlExplorer");

        Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExplorerExt explorer =
            GetSourceControlExplorer();
        if (explorer != null)
            explorer.Navigate(path);
    }

    private Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExplorerExt GetSourceControlExplorer()
    {
        Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt versionControl =
            dte.GetObject("Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt") as
                Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt;
        if (versionControl == null)
            return null;

        return versionControl.Explorer;
    }

Upvotes: 2

I believe this is not possible. The source explorer detects the team project and drops you at the root of the team project node. $/myproject/ ..

Happy to be proven wrong on this one...

Upvotes: 0

Related Questions