Skip to content

Commit

Permalink
Adds the 'IsNonVisibleItem' property to the 'SolutionItem' class.
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenRasmussen committed Dec 18, 2022
1 parent e0d1596 commit 7d555d2
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;

namespace Community.VisualStudio.Toolkit.Shared.Helpers
{
/// <summary>
/// Extensions for the <see cref="IVsHierarchyItem"/> interface.
/// </summary>
public static class VsHierarchyExtensions
{
/// <summary>
/// Returns the <see cref="IVsHierarchy"/> for the <see cref="IVsHierarchyItemIdentity"/>
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
public static IVsHierarchy GetHierarchy(this IVsHierarchyItemIdentity item) =>
item.IsNestedItem ? item.NestedHierarchy : item.Hierarchy;

/// <summary>
/// Returns the 'ItemId' for the <see cref="IVsHierarchyItemIdentity"/>
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
public static uint GetItemId(this IVsHierarchyItemIdentity item) =>
item.IsNestedItem ? item.NestedItemID : item.ItemID;

/// <summary>
/// Returns the <see cref="IVsHierarchy"/> for the <see cref="IVsHierarchyItem"/>
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
public static IVsHierarchy GetHierarchy(this IVsHierarchyItem item) =>
item.HierarchyIdentity.GetHierarchy();

/// <summary>
/// Returns the 'ItemId' for the <see cref="IVsHierarchyItem"/>
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
public static uint GetItemId(this IVsHierarchyItem item) =>
item.HierarchyIdentity.GetItemId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Automation.Peers;
using Community.VisualStudio.Toolkit.Shared.Helpers;
using Microsoft.Internal.VisualStudio.PlatformUI;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
Expand All @@ -23,6 +23,7 @@ public class SolutionItem
private IVsHierarchy _hierarchy = default!; // Initialized to non-null via the `Update()` method.
private string? _fullPath;
private uint _itemId;
private Lazy<bool> _isNonVisibleItem = default!; // Initialized to non-null via the `Update()` method.

/// <summary>
/// Creates a new instance of the solution item.
Expand All @@ -38,9 +39,18 @@ internal void Update(IVsHierarchyItem item)
{
ThreadHelper.ThrowIfNotOnUIThread();
_item = item;
_hierarchy = item.HierarchyIdentity.IsNestedItem ? item.HierarchyIdentity.NestedHierarchy : item.HierarchyIdentity.Hierarchy;
_itemId = item.HierarchyIdentity.IsNestedItem ? item.HierarchyIdentity.NestedItemID : item.HierarchyIdentity.ItemID;
_hierarchy = item.GetHierarchy();
_itemId = item.GetItemId();
_fullPath = GetFullPath();
_isNonVisibleItem = new Lazy<bool>(() =>
{
if (HierarchyUtilities.TryGetHierarchyProperty(_hierarchy, _itemId, (int)__VSHPROPID.VSHPROPID_IsNonMemberItem, out bool isNonMemberItem)
&& isNonMemberItem)
{
return isNonMemberItem;
}
return false;
});
}

/// <summary>
Expand Down Expand Up @@ -73,6 +83,11 @@ internal void Update(IVsHierarchyItem item)
/// </summary>
public IEnumerable<SolutionItem?> Children => _children ??= _item.Children.Select(t => FromHierarchyItem(t));

/// <summary>
/// Returns whether the item is normally visible in soltuion explorer
/// </summary>
public bool IsNonVisibleItem => _isNonVisibleItem.Value;

/// <summary>
/// Gets information from the underlying data types.
/// </summary>
Expand Down Expand Up @@ -128,7 +143,7 @@ public void GetItemInfo(out IVsHierarchy hierarchy, out uint itemId, out IVsHier
{
throw new ArgumentNullException(nameof(hierarchy));
}

ThreadHelper.ThrowIfNotOnUIThread();
IVsHierarchyItem item = hierarchy.ToHierarchyItem(itemId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Debugger\Debugger.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\IVsHierarchyItem.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Windows\IToolWindowPaneAware.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Windows\ToolkitToolWindowPane.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\Attributes\ProvideBraceCompletionAttribute.cs" />
Expand Down

0 comments on commit 7d555d2

Please sign in to comment.