Skip to content

Commit 0a700af

Browse files
committed
Code Quality: Remove manual item reordering in QuickAccessWidgetViewModel
Eliminated manual moving and removal of items in the QuickAccessWidgetViewModel after pin and unpin actions. The file watcher now handles collection updates automatically, simplifying the code and reducing redundancy.
1 parent 0f10a3a commit 0a700af

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ public override async Task ExecutePinToSidebarCommand(WidgetCardItem? item)
193193

194194
var lastPinnedItemIndex = Items.LastOrDefault(x => x.IsPinned) is { } lastPinnedItem ? Items.IndexOf(lastPinnedItem) : 0;
195195
var currentPinnedItemIndex = Items.IndexOf(folderCardItem);
196+
196197
if (currentPinnedItemIndex is -1)
197198
return;
198199

@@ -212,19 +213,12 @@ public override async Task ExecutePinToSidebarCommand(WidgetCardItem? item)
212213
IShellItem* pShellItem = null;
213214
hr = pAgileReference.Get()->Resolve(IID.IID_IShellItem, (void**)&pShellItem);
214215
using var windowsFile = new WindowsFile(pShellItem);
215-
216216
// NOTE: "pintohome" is an undocumented verb, which calls an undocumented COM class, windows.storage.dll!CPinToFrequentExecute : public IExecuteCommand, ...
217217
return windowsFile.TryInvokeContextMenuVerb("pintohome");
218218
}
219219
});
220220

221-
if (hr.ThrowIfFailedOnDebug().Failed)
222-
return;
223-
224-
// Add this to right before the last pinned item
225-
// NOTE: To be honest, this is not needed as the file watcher will take care of this
226-
if (lastPinnedItemIndex + 1 != currentPinnedItemIndex)
227-
Items.Move(currentPinnedItemIndex, lastPinnedItemIndex + 1);
221+
// The file watcher will update the collection automatically
228222
}
229223

230224
public override async Task ExecuteUnpinFromSidebarCommand(WidgetCardItem? item)
@@ -258,7 +252,7 @@ public override async Task ExecuteUnpinFromSidebarCommand(WidgetCardItem? item)
258252
if (hr.ThrowIfFailedOnDebug().Failed)
259253
return;
260254

261-
Items.Remove(folderCardItem);
255+
// The file watcher will update the collection automatically
262256
}
263257

264258
private void ExecuteOpenPropertiesCommand(WidgetFolderCardItem? item)

0 commit comments

Comments
 (0)