Skip to content

Commit c525ec9

Browse files
committed
Implemented GetShellNewItems & InvokeShellNewItem
1 parent 90fb817 commit c525ec9

File tree

9 files changed

+284
-11
lines changed

9 files changed

+284
-11
lines changed

src/Files.App.CsWin32/ManualGuid.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ public static Guid* IID_IStorageProviderStatusUISourceFactory
4747

4848
[GuidRVAGen.Guid("000214F9-0000-0000-C000-000000000046")]
4949
public static partial Guid* IID_IShellLinkW { get; }
50+
51+
[GuidRVAGen.Guid("B63EA76D-1F85-456F-A19C-48159EFA858B")]
52+
public static partial Guid* IID_IShellItemArray { get; }
53+
54+
[GuidRVAGen.Guid("7F9185B0-CB92-43C5-80A9-92277A4F7B54")]
55+
public static partial Guid* IID_IExecuteCommand { get; }
56+
57+
[GuidRVAGen.Guid("1C9CD5BB-98E9-4491-A60F-31AACC72B83C")]
58+
public static partial Guid* IID_IObjectWithSelection { get; }
59+
60+
[GuidRVAGen.Guid("BCC18B79-BA16-442F-80C4-8A59C30C463B")]
61+
public static partial Guid* IID_IShellItemImageFactory { get; }
62+
63+
[GuidRVAGen.Guid("000214E8-0000-0000-C000-000000000046")]
64+
public static partial Guid* IID_IShellExtInit { get; }
65+
66+
[GuidRVAGen.Guid("000214F4-0000-0000-C000-000000000046")]
67+
public static partial Guid* IID_IContextMenu2 { get; }
5068
}
5169

5270
public static unsafe partial class CLSID
@@ -65,6 +83,15 @@ public static unsafe partial class CLSID
6583

6684
[GuidRVAGen.Guid("45BA127D-10A8-46EA-8AB7-56EA9078943C")]
6785
public static partial Guid* CLSID_ApplicationActivationManager { get; }
86+
87+
[GuidRVAGen.Guid("B455F46E-E4AF-4035-B0A4-CF18D2F6F28E")]
88+
public static partial Guid* CLSID_PinToFrequentExecute { get; }
89+
90+
[GuidRVAGen.Guid("EE20EEBA-DF64-4A4E-B7BB-2D1C6B2DFCC1")]
91+
public static partial Guid* CLSID_UnPinFromFrequentExecute { get; }
92+
93+
[GuidRVAGen.Guid("D969A300-E7FF-11d0-A93B-00A0C90F2719")]
94+
public static partial Guid* CLSID_NewMenu { get; }
6895
}
6996

7097
public static unsafe partial class BHID

src/Files.App.CsWin32/NativeMethods.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,11 @@ GetKeyboardState
226226
MapVirtualKey
227227
GetKeyboardLayout
228228
S_FALSE
229+
IExecuteCommand
230+
IObjectWithSelection
231+
SHCreateShellItemArrayFromShellItem
232+
IShellExtInit
233+
IContextMenu2
234+
GetSubMenu
235+
GetMenuItemCount
236+
GetMenuItemInfo
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
namespace Files.App.Storage
5+
{
6+
/// <summary>
7+
/// Represents a Windows Shell ContextMenu item.
8+
/// </summary>
9+
public partial class ContextMenuItem
10+
{
11+
public ContextMenuType Type { get; set; }
12+
13+
public uint Id { get; set; }
14+
15+
public byte[]? Icon { get; set; }
16+
17+
public string? Name { get; set; }
18+
}
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
namespace Files.App.Storage
5+
{
6+
public enum ContextMenuType
7+
{
8+
Normal = 0x00000000,
9+
10+
Disabled = 0x00000003,
11+
12+
Checked = 0x00000008,
13+
14+
Highlighted = 0x00000080,
15+
16+
Default = 0x00001000,
17+
}
18+
}
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; set; }
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/>

0 commit comments

Comments
 (0)