VsixCommunity / Community.VisualStudio.Toolkit

Making it easier to write Visual Studio extensions
Other
256 stars 44 forks source link

How to get the files selected by the mouse? #422

Closed mirrortom closed 1 year ago

mirrortom commented 1 year ago

in the solution window , some file selected by the mouse , how to get them? I didn't find an API for this , help.

var project = await VS.Solutions.GetActiveProjectAsync();

// think 
foreach (var item in project.Children)
{
    if(item.Selected == true)
        return item;
}

// think
project.SelectedItmes();

help

reduckted commented 1 year ago

You can use SolutionExplorerWindow.

SolutionExplorerWindow? solutionExplorer = VS.Windows.GetSolutionExplorerWindowAsync();

if (solutionExplorer is not null) {
    foreach (SolutionItem item in await solutionExplorer.GetSelectionAsync()) {
        // ...
    }
}
mirrortom commented 1 year ago

I tried this API and it work! Thank you for your reply!