Skip to content

Commit 16f7241

Browse files
Merge pull request #567 from rezanid/patch-1
New SelectInSolutionExplorerAsync method for SolutionItem [release]
2 parents 2a4495f + f1b75ee commit 16f7241

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

src/toolkit/Community.VisualStudio.Toolkit.Shared/Solution/SolutionItem.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,42 @@ public void GetItemInfo(out IVsHierarchy hierarchy, out uint itemId, out IVsHier
176176
}
177177
}
178178

179+
/// <summary>
180+
/// Selects the given hierarchy/itemId in Solution Explorer.
181+
/// Pass the item-specific hierarchy if you have both (hierarchy & itemHierarchy).
182+
/// </summary>
183+
public async System.Threading.Tasks.Task SelectInSolutionExplorerAsync()
184+
{
185+
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
186+
187+
if (_hierarchy == null)
188+
return;
189+
190+
// Ensure Solution Explorer is created/shown
191+
var uiShellObj = await AsyncServiceProvider.GlobalProvider.GetServiceAsync(typeof(SVsUIShell));
192+
var seGuid = VSConstants.StandardToolWindows.SolutionExplorer;
193+
IVsWindowFrame? frame = null;
194+
if (uiShellObj is IVsUIShell uiShell)
195+
{
196+
uiShell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fForceCreate, ref seGuid, out frame);
197+
}
198+
199+
if (frame == null)
200+
return;
201+
202+
frame.Show();
203+
204+
// Get the IVsUIHierarchyWindow behind Solution Explorer
205+
frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out object docView);
206+
if (docView is not IVsUIHierarchyWindow hierarchyWindow)
207+
return;
208+
209+
if (_hierarchy is IVsUIHierarchy uiHierarchy)
210+
{
211+
hierarchyWindow.ExpandItem(uiHierarchy, _itemId, EXPANDFLAGS.EXPF_SelectItem);
212+
}
213+
}
214+
179215
private static SolutionItemType GetSolutionItemType(IVsHierarchyItemIdentity identity)
180216
{
181217
if (HierarchyUtilities.IsSolutionNode(identity))

0 commit comments

Comments
 (0)