Skip to content

Commit aec76bb

Browse files
committed
Implemented TryPinFolderToQuickAccess & TryUnpinFolderFromQuickAccess
1 parent acac1a3 commit aec76bb

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

src/Files.App.CsWin32/ManualGuid.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ 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; }
5059
}
5160

5261
public static unsafe partial class CLSID
@@ -65,6 +74,12 @@ public static unsafe partial class CLSID
6574

6675
[GuidRVAGen.Guid("45BA127D-10A8-46EA-8AB7-56EA9078943C")]
6776
public static partial Guid* CLSID_ApplicationActivationManager { get; }
77+
78+
[GuidRVAGen.Guid("B455F46E-E4AF-4035-B0A4-CF18D2F6F28E")]
79+
public static partial Guid* CLSID_PinToFrequentExecute { get; }
80+
81+
[GuidRVAGen.Guid("EE20EEBA-DF64-4A4E-B7BB-2D1C6B2DFCC1")]
82+
public static partial Guid* CLSID_UnPinFromFrequentExecute { get; }
6883
}
6984

7085
public static unsafe partial class BHID

src/Files.App.CsWin32/NativeMethods.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,6 @@ GetKeyboardState
226226
MapVirtualKey
227227
GetKeyboardLayout
228228
S_FALSE
229+
IExecuteCommand
230+
IObjectWithSelection
231+
SHCreateShellItemArrayFromShellItem

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

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Text;
66
using Windows.Win32;
77
using Windows.Win32.Foundation;
8+
using Windows.Win32.System.Com;
89
using Windows.Win32.System.SystemServices;
910
using Windows.Win32.UI.Shell;
1011
using Windows.Win32.UI.Shell.PropertiesSystem;
@@ -136,13 +137,65 @@ public unsafe static HRESULT TryGetShellTooltip(this IWindowsStorable storable,
136137
return HRESULT.S_OK;
137138
}
138139

139-
public unsafe static HRESULT TryPinFolderToQuickAccess()
140+
public unsafe static HRESULT TryPinFolderToQuickAccess(this IWindowsFolder @this)
140141
{
142+
HRESULT hr = default;
143+
144+
using ComPtr<IExecuteCommand> pExecuteCommand = default;
145+
using ComPtr<IObjectWithSelection> pObjectWithSelection = default;
146+
147+
hr = PInvoke.CoCreateInstance(CLSID.CLSID_PinToFrequentExecute, null, CLSCTX.CLSCTX_INPROC_SERVER, IID.IID_IExecuteCommand, (void**)pExecuteCommand.GetAddressOf());
148+
if (hr.ThrowIfFailedOnDebug().Failed)
149+
return hr;
150+
151+
using ComPtr<IShellItemArray> pShellItemArray = default;
152+
hr = PInvoke.SHCreateShellItemArrayFromShellItem(@this.ThisPtr, IID.IID_IShellItemArray, (void**)pShellItemArray.GetAddressOf());
153+
if (hr.ThrowIfFailedOnDebug().Failed)
154+
return hr;
155+
156+
hr = pExecuteCommand.Get()->QueryInterface(IID.IID_IObjectWithSelection, (void**)pObjectWithSelection.GetAddressOf());
157+
if (hr.ThrowIfFailedOnDebug().Failed)
158+
return hr;
159+
160+
hr = pObjectWithSelection.Get()->SetSelection(pShellItemArray.Get());
161+
if (hr.ThrowIfFailedOnDebug().Failed)
162+
return hr;
163+
164+
hr = pExecuteCommand.Get()->Execute();
165+
if (hr.ThrowIfFailedOnDebug().Failed)
166+
return hr;
167+
141168
return HRESULT.S_OK;
142169
}
143170

144-
public unsafe static HRESULT TryUnpinFolderFromQuickAccess()
171+
public unsafe static HRESULT TryUnpinFolderFromQuickAccess(this IWindowsFolder @this)
145172
{
173+
HRESULT hr = default;
174+
175+
using ComPtr<IExecuteCommand> pExecuteCommand = default;
176+
using ComPtr<IObjectWithSelection> pObjectWithSelection = default;
177+
178+
hr = PInvoke.CoCreateInstance(CLSID.CLSID_UnPinFromFrequentExecute, null, CLSCTX.CLSCTX_INPROC_SERVER, IID.IID_IExecuteCommand, (void**)pExecuteCommand.GetAddressOf());
179+
if (hr.ThrowIfFailedOnDebug().Failed)
180+
return hr;
181+
182+
using ComPtr<IShellItemArray> pShellItemArray = default;
183+
hr = PInvoke.SHCreateShellItemArrayFromShellItem(@this.ThisPtr, IID.IID_IShellItemArray, (void**)pShellItemArray.GetAddressOf());
184+
if (hr.ThrowIfFailedOnDebug().Failed)
185+
return hr;
186+
187+
hr = pExecuteCommand.Get()->QueryInterface(IID.IID_IObjectWithSelection, (void**)pObjectWithSelection.GetAddressOf());
188+
if (hr.ThrowIfFailedOnDebug().Failed)
189+
return hr;
190+
191+
hr = pObjectWithSelection.Get()->SetSelection(pShellItemArray.Get());
192+
if (hr.ThrowIfFailedOnDebug().Failed)
193+
return hr;
194+
195+
hr = pExecuteCommand.Get()->Execute();
196+
if (hr.ThrowIfFailedOnDebug().Failed)
197+
return hr;
198+
146199
return HRESULT.S_OK;
147200
}
148201
}

0 commit comments

Comments
 (0)