Skip to content

Fix: Fixed issue where drives had the wrong order in the sidebar #10258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/Files.App/UserControls/Widgets/DrivesWidget.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Files.App.Helpers.XamlHelpers;
using Files.App.ViewModels.Widgets;
using Files.Backend.Services.Settings;
using Files.Shared.Extensions;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
Expand All @@ -25,7 +26,7 @@

namespace Files.App.UserControls.Widgets
{
public class DriveCardItem : ObservableObject, IWidgetCardItem<DriveItem>
public class DriveCardItem : ObservableObject, IWidgetCardItem<DriveItem>, IComparable<DriveCardItem>
{
private BitmapImage thumbnail;
private byte[] thumbnailData;
Expand Down Expand Up @@ -61,7 +62,9 @@ public async Task LoadCardThumbnailAsync()
Thumbnail = await App.Window.DispatcherQueue.EnqueueAsync(() => thumbnailData.ToBitmapAsync(Constants.Widgets.WidgetIconSize));
}
}
}

public int CompareTo(DriveCardItem? other) => Item.Path.CompareTo(other?.Item?.Path);
}

public sealed partial class DrivesWidget : UserControl, IWidgetItemModel, INotifyPropertyChanged
{
Expand Down Expand Up @@ -122,7 +125,7 @@ await DispatcherQueue.EnqueueAsync(async () =>
if (drive.Type != DriveType.VirtualDrive)
{
var cardItem = new DriveCardItem(drive);
ItemsAdded.Add(cardItem);
ItemsAdded.AddSorted(cardItem);
await cardItem.LoadCardThumbnailAsync(); // After add
}
}
Expand Down
14 changes: 10 additions & 4 deletions src/Files.App/ViewModels/SidebarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.WinUI;
using Files.App.DataModels.NavigationControlItems;
using Files.App.Extensions;
using Files.App.Filesystem;
using Files.App.Helpers;
using Files.App.UserControls;
using Files.App.Extensions;
using Files.Backend.Services.Settings;
using Files.Shared.EventArguments;
using Files.Shared.Extensions;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media.Imaging;
using Microsoft.UI.Dispatching;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
Expand Down Expand Up @@ -349,9 +349,15 @@ private async Task AddElementToSection(INavigationControlItem elem, LocationItem
}
else if (elem is DriveItem drive)
{
if (!section.ChildItems.Any(x => x.Path == drive.Path))
string drivePath = drive.Path;
IList<string> paths = section.ChildItems.Select(item => item.Path).ToList();

if (!paths.Contains(drivePath))
{
section.ChildItems.Insert(index < 0 ? section.ChildItems.Count : Math.Min(index, section.ChildItems.Count), drive);
paths.AddSorted(drivePath);
int position = paths.IndexOf(drivePath);

section.ChildItems.Insert(position, drive);
await drive.LoadDriveIcon();
}
}
Expand Down