Skip to content

Commit 1a5d615

Browse files
committed
Refactor: Simplify sidebar drag interfaces and utilize collection Move
1 parent 1cc3475 commit 1a5d615

4 files changed

Lines changed: 9 additions & 21 deletions

File tree

src/Files.App.Controls/Sidebar/ISidebarItemModel.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,10 @@ public interface ISidebarItemModel : INotifyPropertyChanged
3030
/// Expansion participant that keeps the regular row appearance (icon + normal text) instead of the section-header style.
3131
/// </summary>
3232
bool IsLeafWithChildren => false;
33-
}
34-
35-
public interface IDraggableSidebarItemModel : ISidebarItemModel
36-
{
37-
/// <summary>
38-
/// The file path used for drag and drop operations
39-
/// </summary>
40-
string? DropPath { get; }
4133

4234
/// <summary>
43-
/// Indicates whether the item supports reorder dropping
35+
/// Indicates whether the item supports reorder dropping.
4436
/// </summary>
45-
bool IsReorderDropItem { get; }
37+
bool IsReorderDropItem => false;
4638
}
4739
}

src/Files.App.Controls/Sidebar/SidebarItem.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ public void HandleItemChange()
133133
UpdateExpansionState();
134134
ReevaluateSelection();
135135

136-
if (Item is IDraggableSidebarItemModel draggableItem)
136+
if (Item is not null)
137137
{
138-
CanDrag = IsValidDropPath(draggableItem.DropPath);
139-
UseReorderDrop = !IsGroupHeader && CanDrag && draggableItem.IsReorderDropItem;
138+
CanDrag = IsValidDropPath(Item.Path);
139+
UseReorderDrop = !IsGroupHeader && CanDrag && Item.IsReorderDropItem;
140140
}
141141
else
142142
{
@@ -211,7 +211,7 @@ private static bool IsValidDropPath(string? path)
211211

212212
private void SidebarItem_DragStarting(UIElement sender, DragStartingEventArgs args)
213213
{
214-
if (Item is not IDraggableSidebarItemModel draggableItem || draggableItem.DropPath is not string dragPath || !IsValidDropPath(dragPath))
214+
if (Item?.Path is not string dragPath || !IsValidDropPath(dragPath))
215215
return;
216216

217217
SafetyExtensions.IgnoreExceptions(() =>

src/Files.App/Data/Contracts/INavigationControlItem.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55

66
namespace Files.App.Data.Contracts
77
{
8-
public interface INavigationControlItem : IComparable<INavigationControlItem>, INotifyPropertyChanged, IDraggableSidebarItemModel
8+
public interface INavigationControlItem : IComparable<INavigationControlItem>, INotifyPropertyChanged, ISidebarItemModel
99
{
1010
public new string Text { get; }
1111

1212
public string Path { get; }
1313

14-
string? IDraggableSidebarItemModel.DropPath => Path;
15-
16-
bool IDraggableSidebarItemModel.IsReorderDropItem => Section == SectionType.Pinned;
14+
bool ISidebarItemModel.IsReorderDropItem => Section == SectionType.Pinned;
1715

1816
public SectionType Section { get; }
1917

src/Files.App/ViewModels/UserControls/SidebarViewModel.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,9 +1546,7 @@ private async Task HandleLocationItemDroppedAsync(LocationItem locationItem, Ite
15461546

15471547
if (sourceIndex != targetIndex && targetIndex >= 0 && targetIndex < section.ChildItems.Count)
15481548
{
1549-
var item = section.ChildItems[sourceIndex];
1550-
section.ChildItems.RemoveAt(sourceIndex);
1551-
section.ChildItems.Insert(targetIndex, item);
1549+
section.ChildItems.Move(sourceIndex, targetIndex);
15521550
await PersistPinnedOrderAsync(section);
15531551
}
15541552
}

0 commit comments

Comments
 (0)