mirror of https://github.com/dahall/Vanara.git
More work on ShellFolderCategorizer
parent
bca4b02b24
commit
a391f0c183
|
@ -137,5 +137,15 @@ namespace Vanara.Windows.Shell.Tests
|
||||||
Assert.That(() => f.GetChildrenUIObjects<IShellLibrary>(default, i), Throws.TypeOf<NotImplementedException>());
|
Assert.That(() => f.GetChildrenUIObjects<IShellLibrary>(default, i), Throws.TypeOf<NotImplementedException>());
|
||||||
Assert.That(() => f.GetViewObject<IShellLibrary>(default), Throws.TypeOf<InvalidCastException>());
|
Assert.That(() => f.GetViewObject<IShellLibrary>(default), Throws.TypeOf<InvalidCastException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CategoryTest()
|
||||||
|
{
|
||||||
|
using var ie = new ShellFolder(KNOWNFOLDERID.FOLDERID_Documents);
|
||||||
|
Assert.That(ie.Categories, Is.Not.Empty);
|
||||||
|
Assert.That(ie.Categories.DefaultCategory?.Name, Is.Not.Null);
|
||||||
|
foreach (var c in ie.Categories)
|
||||||
|
TestContext.WriteLine($"{c.Name}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -56,6 +56,7 @@ namespace Vanara.Windows.Shell
|
||||||
public class ShellFolder : ShellItem, IEnumerable<ShellItem>
|
public class ShellFolder : ShellItem, IEnumerable<ShellItem>
|
||||||
{
|
{
|
||||||
internal IShellFolder iShellFolder;
|
internal IShellFolder iShellFolder;
|
||||||
|
private ShellFolderCategorizer categories;
|
||||||
private static ShellFolder desktop;
|
private static ShellFolder desktop;
|
||||||
|
|
||||||
/// <summary>Initializes a new instance of the <see cref="ShellItem"/> class.</summary>
|
/// <summary>Initializes a new instance of the <see cref="ShellItem"/> class.</summary>
|
||||||
|
@ -177,7 +178,7 @@ namespace Vanara.Windows.Shell
|
||||||
|
|
||||||
/// <summary>Gets the registered categorizers.</summary>
|
/// <summary>Gets the registered categorizers.</summary>
|
||||||
/// <value>The categorizers.</value>
|
/// <value>The categorizers.</value>
|
||||||
public ShellFolderCategorizer Categories => new(IShellFolder);
|
public ShellFolderCategorizer Categories => categories ??= new(IShellFolder);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enumerates all children of this item. If this item is not a folder/container, this method will return an empty enumeration.
|
/// Enumerates all children of this item. If this item is not a folder/container, this method will return an empty enumeration.
|
||||||
|
|
|
@ -21,8 +21,12 @@ public class ShellFolderCategorizer : IEnumerable<ShellFolderCategory>
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
ICategoryProvider.GetDefaultCategory(out var guid, out _).ThrowIfFailed();
|
var hr = ICategoryProvider.GetDefaultCategory(out var guid, out _);
|
||||||
return GetCat(guid);
|
if (hr == HRESULT.S_OK)
|
||||||
|
return GetCat(guid);
|
||||||
|
if (hr == HRESULT.S_FALSE)
|
||||||
|
return null;
|
||||||
|
throw hr.GetException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,8 +47,9 @@ public class ShellFolderCategorizer : IEnumerable<ShellFolderCategory>
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IEnumerator<ShellFolderCategory> GetEnumerator()
|
public IEnumerator<ShellFolderCategory> GetEnumerator()
|
||||||
{
|
{
|
||||||
ICategoryProvider.EnumCategories(out IEnumGUID penum).ThrowIfFailed();
|
if (ICategoryProvider.EnumCategories(out IEnumGUID penum) == HRESULT.S_OK)
|
||||||
return new IEnumFromCom<Guid>(penum.Next, penum.Reset).Select(g => GetCat(g)).GetEnumerator();
|
return new IEnumFromCom<Guid>(penum.Next, penum.Reset).Select(g => GetCat(g)).GetEnumerator();
|
||||||
|
return Enumerable.Empty<ShellFolderCategory>().GetEnumerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|
Loading…
Reference in New Issue