提交 2a33b762 编写于 作者: T Tom Meschter 提交者: GitHub

Merge pull request #20410 from tmeschter/SupportInspectingSolutionExplorer

Add support for inspecting Solution Explorer items
......@@ -802,6 +802,62 @@ public void SelectItem(string itemName)
solutionExplorer.Parent.Activate();
}
public void SelectItemAtPath(params string[] path)
{
var dte = (DTE2)GetDTE();
var solutionExplorer = dte.ToolWindows.SolutionExplorer;
var item = FindItemAtPath(solutionExplorer.UIHierarchyItems, path);
item.Select(EnvDTE.vsUISelectionType.vsUISelectionTypeSelect);
solutionExplorer.Parent.Activate();
}
public string[] GetChildrenOfItem(string itemName)
{
var dte = (DTE2)GetDTE();
var solutionExplorer = dte.ToolWindows.SolutionExplorer;
var item = FindFirstItemRecursively(solutionExplorer.UIHierarchyItems, itemName);
return item.UIHierarchyItems
.Cast<EnvDTE.UIHierarchyItem>()
.Select(i => i.Name)
.ToArray();
}
public string[] GetChildrenOfItemAtPath(params string[] path)
{
var dte = (DTE2)GetDTE();
var solutionExplorer = dte.ToolWindows.SolutionExplorer;
var item = FindItemAtPath(solutionExplorer.UIHierarchyItems, path);
return item.UIHierarchyItems
.Cast<EnvDTE.UIHierarchyItem>()
.Select(i => i.Name)
.ToArray();
}
private static EnvDTE.UIHierarchyItem FindItemAtPath(
EnvDTE.UIHierarchyItems currentItems,
string[] path)
{
EnvDTE.UIHierarchyItem item = null;
foreach (var name in path)
{
item = currentItems.Cast<EnvDTE.UIHierarchyItem>().FirstOrDefault(i => i.Name == name);
if (item == null)
{
return null;
}
currentItems = item.UIHierarchyItems;
}
return item;
}
private static EnvDTE.UIHierarchyItem FindFirstItemRecursively(
EnvDTE.UIHierarchyItems currentItems,
string itemName)
......
......@@ -47,7 +47,7 @@ public void AddProject(ProjectUtils.Project projectName, string projectTemplate,
public void AddProjectReference(ProjectUtils.Project fromProjectName, ProjectUtils.ProjectReference toProjectName)
{
_inProc.AddProjectReference(fromProjectName.Name, toProjectName.Name);
_inProc.AddProjectReference(fromProjectName.Name, toProjectName.Name);
_instance.Workspace.WaitForAsyncOperations(FeatureAttribute.Workspace);
}
......@@ -123,9 +123,36 @@ public string[] GetProjectReferences(ProjectUtils.Project project)
public string[] GetAssemblyReferences(ProjectUtils.Project project)
=> _inProc.GetAssemblyReferences(project.Name);
/// <summary>
/// Selects an item named by the <paramref name="itemName"/> parameter.
/// Note that this selects the first item of the given name found. In situations where
/// there may be more than one item of a given name, use <see cref="SelectItemAtPath(string[])"/>
/// instead.
/// </summary>
public void SelectItem(string itemName)
=> _inProc.SelectItem(itemName);
/// <summary>
/// Selects the specific item at the given "path".
/// </summary>
public void SelectItemAtPath(params string[] path)
=> _inProc.SelectItemAtPath(path);
/// <summary>
/// Returns the names of the immediate children of the given item.
/// Note that this uses the first item of the given name found. In situations where there
/// may be more than one item of a given name, use <see cref="GetChildrenOfItemAtPath(string[])"/>
/// instead.
/// </summary>
public string[] GetChildrenOfItem(string itemName)
=> _inProc.GetChildrenOfItem(itemName);
/// <summary>
/// Returns the names of the immediate children of the item at the given "path".
/// </summary>
public string[] GetChildrenOfItemAtPath(params string[] path)
=> _inProc.GetChildrenOfItemAtPath(path);
public void ClearBuildOutputWindowPane()
=> _inProc.ClearBuildOutputWindowPane();
......@@ -135,7 +162,7 @@ public void WaitForBuildToFinish()
public void EditProjectFile(ProjectUtils.Project project)
=> _inProc.EditProjectFile(project.Name);
public void AddStandaloneFile(string fileName)
public void AddStandaloneFile(string fileName)
=> _inProc.AddStandaloneFile(fileName);
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册