Skip to content

Commit 3567892

Browse files
committed
Update
1 parent 8e0f0c6 commit 3567892

File tree

3 files changed

+114
-97
lines changed

3 files changed

+114
-97
lines changed

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

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

4+
using System.Runtime.CompilerServices;
45
using System.Text;
56
using Windows.Win32;
67
using Windows.Win32.Foundation;
78
using Windows.Win32.System.SystemServices;
89
using Windows.Win32.UI.Shell;
10+
using Windows.Win32.UI.Shell.PropertiesSystem;
911
using Windows.Win32.UI.WindowsAndMessaging;
1012

1113
namespace Files.App.Storage
@@ -15,14 +17,27 @@ public static partial class WindowsStorableHelpers
1517
public unsafe static HRESULT GetPropertyValue<TValue>(this IWindowsStorable storable, string propKey, out TValue value)
1618
{
1719
using ComPtr<IShellItem2> pShellItem2 = default;
18-
var shellItem2Iid = typeof(IShellItem2).GUID;
19-
HRESULT hr = storable.ThisPtr.Get()->QueryInterface(&shellItem2Iid, (void**)pShellItem2.GetAddressOf());
20-
hr = PInvoke.PSGetPropertyKeyFromName(propKey, out var originalPathPropertyKey);
21-
hr = pShellItem2.Get()->GetString(originalPathPropertyKey, out var szOriginalPath);
20+
HRESULT hr = storable.ThisPtr.Get()->QueryInterface(IID.IID_IShellItem2, (void**)pShellItem2.GetAddressOf());
21+
22+
PROPERTYKEY propertyKey = default;
23+
fixed (char* pszPropertyKey = propKey)
24+
hr = PInvoke.PSGetPropertyKeyFromName(pszPropertyKey, &propertyKey);
2225

2326
if (typeof(TValue) == typeof(string))
2427
{
25-
value = (TValue)(object)szOriginalPath.ToString();
28+
ComHeapPtr<PWSTR> szPropertyValue = default;
29+
hr = pShellItem2.Get()->GetString(&propertyKey, szPropertyValue.Get());
30+
value = (TValue)(object)szPropertyValue.Get()->ToString();
31+
32+
return hr;
33+
}
34+
if (typeof(TValue) == typeof(bool))
35+
{
36+
bool propertyValue = false;
37+
hr = pShellItem2.Get()->GetBool(propertyKey, out var fPropertyValue);
38+
propertyValue = fPropertyValue;
39+
value = Unsafe.As<bool, TValue>(ref propertyValue);
40+
2641
return hr;
2742
}
2843
else

src/Files.App/Data/Items/WidgetFolderCardItem.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,11 @@ public async Task LoadCardThumbnailAsync()
4040
if (string.IsNullOrEmpty(Path))
4141
return;
4242

43-
var rawThumbnailData = await Item.GetThumbnailAsync((int)(32f * App.AppModel.AppWindowDPI), SIIGBF.SIIGBF_ICONONLY);
43+
Item.TryGetThumbnail((int)(32f * App.AppModel.AppWindowDPI), SIIGBF.SIIGBF_ICONONLY, out var rawThumbnailData);
4444
if (rawThumbnailData is null)
4545
return;
4646

47-
Thumbnail = await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(
48-
() => rawThumbnailData?.ToBitmapAsync(),
49-
Microsoft.UI.Dispatching.DispatcherQueuePriority.Normal);
47+
Thumbnail = await rawThumbnailData?.ToBitmapAsync();
5048
}
5149
}
5250
}

src/Files.App/ViewModels/UserControls/Widgets/QuickAccessWidgetViewModel.cs

Lines changed: 92 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ public sealed partial class QuickAccessWidgetViewModel : BaseWidgetViewModel, IW
3333

3434
public QuickAccessWidgetViewModel()
3535
{
36-
_ = InitializeWidget();
37-
3836
Items.CollectionChanged += Items_CollectionChanged;
3937

4038
OpenPropertiesCommand = new RelayCommand<WidgetFolderCardItem>(ExecuteOpenPropertiesCommand);
@@ -46,15 +44,22 @@ public QuickAccessWidgetViewModel()
4644

4745
private async Task InitializeWidget()
4846
{
49-
var itemsToAdd = await QuickAccessService.GetPinnedFoldersAsync();
50-
ModifyItemAsync(this, new(itemsToAdd.ToArray(), false) { Reset = true });
47+
//await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () =>
48+
//{
49+
// await foreach (IWindowsStorable folder in HomePageContext.HomeFolder.GetQuickAccessFolderAsync(default))
50+
// {
51+
// folder.GetPropertyValue<bool>("System.Home.IsPinned", out var isPinned);
52+
53+
// var card = new WidgetFolderCardItem(folder, folder.GetDisplayName(Windows.Win32.UI.Shell.SIGDN.SIGDN_PARENTRELATIVEFORUI), isPinned);
5154

52-
App.QuickAccessManager.UpdateQuickAccessWidget += ModifyItemAsync;
55+
// Items.Insert(Items.Count, card);
56+
// }
57+
//});
5358
}
5459

5560
public Task RefreshWidgetAsync()
5661
{
57-
return Task.CompletedTask;
62+
return InitializeWidget();
5863
}
5964

6065
public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCardItem item, bool isPinned, bool isFolder = false)
@@ -125,87 +130,87 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
125130
}.Where(x => x.ShowItem).ToList();
126131
}
127132

128-
private async void ModifyItemAsync(object? sender, ModifyQuickAccessEventArgs? e)
129-
{
130-
if (e is null)
131-
return;
132-
133-
await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () =>
134-
{
135-
if (e.Reset)
136-
{
137-
// Find the intersection between the two lists and determine whether to remove or add
138-
var originalItems = Items.ToList();
139-
var itemsToRemove = originalItems.Where(x => !e.Paths.Contains(x.Path));
140-
var itemsToAdd = e.Paths.Where(x => !originalItems.Any(y => y.Path == x));
141-
142-
// Remove items
143-
foreach (var itemToRemove in itemsToRemove)
144-
Items.Remove(itemToRemove);
145-
146-
// Add items
147-
foreach (var itemToAdd in itemsToAdd)
148-
{
149-
var interimItems = Items.ToList();
150-
var item = await App.QuickAccessManager.Model.CreateLocationItemFromPathAsync(itemToAdd);
151-
var lastIndex = Items.IndexOf(interimItems.FirstOrDefault(x => !x.IsPinned));
152-
var isPinned = (bool?)e.Items.Where(x => x.FilePath == itemToAdd).FirstOrDefault()?.Properties["System.Home.IsPinned"] ?? false;
153-
if (interimItems.Any(x => x.Path == itemToAdd))
154-
continue;
155-
156-
Items.Insert(isPinned && lastIndex >= 0 ? Math.Min(lastIndex, Items.Count) : Items.Count, new WidgetFolderCardItem(item, Path.GetFileName(item.Text), isPinned)
157-
{
158-
Path = item.Path,
159-
});
160-
}
161-
162-
return;
163-
}
164-
if (e.Reorder)
165-
{
166-
// Remove pinned items
167-
foreach (var itemToRemove in Items.ToList().Where(x => x.IsPinned))
168-
Items.Remove(itemToRemove);
169-
170-
// Add pinned items in the new order
171-
foreach (var itemToAdd in e.Paths)
172-
{
173-
var interimItems = Items.ToList();
174-
var item = await App.QuickAccessManager.Model.CreateLocationItemFromPathAsync(itemToAdd);
175-
var lastIndex = Items.IndexOf(interimItems.FirstOrDefault(x => !x.IsPinned));
176-
if (interimItems.Any(x => x.Path == itemToAdd))
177-
continue;
178-
179-
Items.Insert(lastIndex >= 0 ? Math.Min(lastIndex, Items.Count) : Items.Count, new WidgetFolderCardItem(item, Path.GetFileName(item.Text), true)
180-
{
181-
Path = item.Path,
182-
});
183-
}
184-
185-
return;
186-
}
187-
if (e.Add)
188-
{
189-
foreach (var itemToAdd in e.Paths)
190-
{
191-
var interimItems = Items.ToList();
192-
var item = await App.QuickAccessManager.Model.CreateLocationItemFromPathAsync(itemToAdd);
193-
var lastIndex = Items.IndexOf(interimItems.FirstOrDefault(x => !x.IsPinned));
194-
if (interimItems.Any(x => x.Path == itemToAdd))
195-
continue;
196-
Items.Insert(e.Pin && lastIndex >= 0 ? Math.Min(lastIndex, Items.Count) : Items.Count, new WidgetFolderCardItem(item, Path.GetFileName(item.Text), e.Pin) // Add just after the Recent Folders
197-
{
198-
Path = item.Path,
199-
});
200-
}
201-
}
202-
else
203-
{
204-
foreach (var itemToRemove in Items.ToList().Where(x => e.Item.Contains(x.Path)))
205-
Items.Remove(itemToRemove);
206-
}
207-
});
208-
}
133+
//private async void ModifyItemAsync(object? sender, ModifyQuickAccessEventArgs? e)
134+
//{
135+
// if (e is null)
136+
// return;
137+
138+
// await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () =>
139+
// {
140+
// if (e.Reset)
141+
// {
142+
// // Find the intersection between the two lists and determine whether to remove or add
143+
// var originalItems = Items.ToList();
144+
// var itemsToRemove = originalItems.Where(x => !e.Paths.Contains(x.Path));
145+
// var itemsToAdd = e.Paths.Where(x => !originalItems.Any(y => y.Path == x));
146+
147+
// // Remove items
148+
// foreach (var itemToRemove in itemsToRemove)
149+
// Items.Remove(itemToRemove);
150+
151+
// // Add items
152+
// foreach (var itemToAdd in itemsToAdd)
153+
// {
154+
// var interimItems = Items.ToList();
155+
// var item = await App.QuickAccessManager.Model.CreateLocationItemFromPathAsync(itemToAdd);
156+
// var lastIndex = Items.IndexOf(interimItems.FirstOrDefault(x => !x.IsPinned));
157+
// var isPinned = (bool?)e.Items.Where(x => x.FilePath == itemToAdd).FirstOrDefault()?.Properties["System.Home.IsPinned"] ?? false;
158+
// if (interimItems.Any(x => x.Path == itemToAdd))
159+
// continue;
160+
161+
// Items.Insert(isPinned && lastIndex >= 0 ? Math.Min(lastIndex, Items.Count) : Items.Count, new WidgetFolderCardItem(item, Path.GetFileName(item.Text), isPinned)
162+
// {
163+
// Path = item.Path,
164+
// });
165+
// }
166+
167+
// return;
168+
// }
169+
// if (e.Reorder)
170+
// {
171+
// // Remove pinned items
172+
// foreach (var itemToRemove in Items.ToList().Where(x => x.IsPinned))
173+
// Items.Remove(itemToRemove);
174+
175+
// // Add pinned items in the new order
176+
// foreach (var itemToAdd in e.Paths)
177+
// {
178+
// var interimItems = Items.ToList();
179+
// var item = await App.QuickAccessManager.Model.CreateLocationItemFromPathAsync(itemToAdd);
180+
// var lastIndex = Items.IndexOf(interimItems.FirstOrDefault(x => !x.IsPinned));
181+
// if (interimItems.Any(x => x.Path == itemToAdd))
182+
// continue;
183+
184+
// Items.Insert(lastIndex >= 0 ? Math.Min(lastIndex, Items.Count) : Items.Count, new WidgetFolderCardItem(item, Path.GetFileName(item.Text), true)
185+
// {
186+
// Path = item.Path,
187+
// });
188+
// }
189+
190+
// return;
191+
// }
192+
// if (e.Add)
193+
// {
194+
// foreach (var itemToAdd in e.Paths)
195+
// {
196+
// var interimItems = Items.ToList();
197+
// var item = await App.QuickAccessManager.Model.CreateLocationItemFromPathAsync(itemToAdd);
198+
// var lastIndex = Items.IndexOf(interimItems.FirstOrDefault(x => !x.IsPinned));
199+
// if (interimItems.Any(x => x.Path == itemToAdd))
200+
// continue;
201+
// Items.Insert(e.Pin && lastIndex >= 0 ? Math.Min(lastIndex, Items.Count) : Items.Count, new WidgetFolderCardItem(item, Path.GetFileName(item.Text), e.Pin) // Add just after the Recent Folders
202+
// {
203+
// Path = item.Path,
204+
// });
205+
// }
206+
// }
207+
// else
208+
// {
209+
// foreach (var itemToRemove in Items.ToList().Where(x => e.Item.Contains(x.Path)))
210+
// Items.Remove(itemToRemove);
211+
// }
212+
// });
213+
//}
209214

210215
public async Task NavigateToPath(string path)
211216
{
@@ -305,7 +310,6 @@ private void ExecuteOpenPropertiesCommand(WidgetFolderCardItem? item)
305310

306311
public void Dispose()
307312
{
308-
App.QuickAccessManager.UpdateQuickAccessWidget -= ModifyItemAsync;
309313
}
310314
}
311315
}

0 commit comments

Comments
 (0)