Skip to content

Commit acac1a3

Browse files
committed
Added ContextMenu and ShellNewMenu caches
1 parent 4b0fe97 commit acac1a3

File tree

5 files changed

+50
-4
lines changed

5 files changed

+50
-4
lines changed
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
// Copyright (c) Files Community
22
// Licensed under the MIT License.
33

4+
using Windows.Win32.UI.Shell;
5+
46
namespace Files.App.Storage
57
{
6-
public interface IWindowsFolder : IWindowsStorable, IChildFolder
8+
public unsafe interface IWindowsFolder : IWindowsStorable, IChildFolder
79
{
10+
/// <summary>
11+
/// Gets or sets the cached <see cref="IContextMenu"/> for the ShellNew context menu.
12+
/// </summary>
13+
public IContextMenu* ShellNewMenu { get; }
814
}
915
}

src/Files.App.Storage/Storables/WindowsStorage/IWindowsStorable.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ namespace Files.App.Storage
88
public unsafe interface IWindowsStorable : IStorableChild, IEquatable<IWindowsStorable>, IDisposable
99
{
1010
IShellItem* ThisPtr { get; }
11+
12+
IContextMenu* ContextMenu { get; }
1113
}
1214
}

src/Files.App.Storage/Storables/WindowsStorage/WindowsFolder.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Files Community
22
// Licensed under the MIT License.
33

4+
using System.Runtime.CompilerServices;
45
using Windows.Win32;
56
using Windows.Win32.Foundation;
67
using Windows.Win32.System.SystemServices;
@@ -11,6 +12,16 @@ namespace Files.App.Storage
1112
[DebuggerDisplay("{" + nameof(ToString) + "()}")]
1213
public unsafe class WindowsFolder : WindowsStorable, IWindowsFolder
1314
{
15+
/// <inheritdoc/>
16+
public IContextMenu* ShellNewMenu
17+
{
18+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
19+
get;
20+
21+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
22+
protected internal set;
23+
}
24+
1425
public WindowsFolder(IShellItem* ptr)
1526
{
1627
ThisPtr = ptr;
@@ -63,5 +74,12 @@ public IAsyncEnumerable<IStorableChild> GetItemsAsync(StorableType type = Storab
6374

6475
return childItems.ToAsyncEnumerable();
6576
}
77+
78+
public override void Dispose()
79+
{
80+
base.Dispose();
81+
82+
if (ShellNewMenu is not null) ShellNewMenu->Release();
83+
}
6684
}
6785
}

src/Files.App.Storage/Storables/WindowsStorage/WindowsStorable.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@ public IShellItem* ThisPtr
1717
get;
1818

1919
[MethodImpl(MethodImplOptions.AggressiveInlining)]
20-
protected set;
20+
protected internal set;
21+
}
22+
23+
public IContextMenu* ContextMenu
24+
{
25+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
26+
get;
27+
28+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
29+
protected internal set;
2130
}
2231

2332
public string Id => this.GetDisplayName(SIGDN.SIGDN_FILESYSPATH);
@@ -69,9 +78,10 @@ public override int GetHashCode()
6978
}
7079

7180
/// <inheritdoc/>
72-
public void Dispose()
81+
public virtual void Dispose()
7382
{
74-
ThisPtr->Release();
83+
if (ThisPtr is not null) ThisPtr->Release();
84+
if (ContextMenu is not null) ContextMenu->Release();
7585
}
7686

7787
/// <inheritdoc/>

src/Files.App.Storage/Storables/WindowsStorage/WindowsStorableHelpers.Shell.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,15 @@ public unsafe static HRESULT TryGetShellTooltip(this IWindowsStorable storable,
135135

136136
return HRESULT.S_OK;
137137
}
138+
139+
public unsafe static HRESULT TryPinFolderToQuickAccess()
140+
{
141+
return HRESULT.S_OK;
142+
}
143+
144+
public unsafe static HRESULT TryUnpinFolderFromQuickAccess()
145+
{
146+
return HRESULT.S_OK;
147+
}
138148
}
139149
}

0 commit comments

Comments
 (0)