Skip to content

Commit

Permalink
Merge pull request #403 from StevenRasmussen/is-non-visible-item
Browse files Browse the repository at this point in the history
Adds the 'IsNonVisibleItem' property to the 'SolutionItem' class.
  • Loading branch information
madskristensen authored Jan 4, 2023
2 parents e0d1596 + 95335a6 commit a37ebbb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,37 @@ public static bool IsSharedProject(this IVsHierarchy hierarchy)

return hierarchy.GetSharedAssetsProject() != null;
}

/// <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,6 @@
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Automation.Peers;
using Microsoft.Internal.VisualStudio.PlatformUI;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
Expand All @@ -23,6 +22,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 +38,13 @@ 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>(() =>
{
return HierarchyUtilities.TryGetHierarchyProperty(_hierarchy, _itemId, (int)__VSHPROPID.VSHPROPID_IsNonMemberItem, out bool isNonMemberItem) && isNonMemberItem;
});
}

/// <summary>
Expand Down Expand Up @@ -73,6 +77,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 hidden in solution explorer and only visible when Show All Files is enabled.
/// </summary>
public bool IsNonVisibleItem => _isNonVisibleItem.Value;

/// <summary>
/// Gets information from the underlying data types.
/// </summary>
Expand Down Expand Up @@ -128,7 +137,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

0 comments on commit a37ebbb

Please sign in to comment.