Skip to content

Commit d501d1d

Browse files
authored
Code Quality: Improved Widget code (#14458)
1 parent c73e127 commit d501d1d

39 files changed

+429
-584
lines changed

src/Files.App/Data/Contexts/HomePage/HomePageContext.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
// Licensed under the MIT License. See the LICENSE.
33

44
using Files.App.UserControls.Widgets;
5-
using Files.App.ViewModels.Widgets;
65
using Microsoft.UI.Xaml.Controls;
76
using System.Collections.Immutable;
87

98
namespace Files.App.Data.Contexts
109
{
1110
internal class HomePageContext : ObservableObject, IHomePageContext
1211
{
13-
private static readonly IImmutableList<FileTagsItemViewModel> emptyTaggedItems = Enumerable.Empty<FileTagsItemViewModel>().ToImmutableList();
12+
private static readonly IImmutableList<WidgetFileTagCardItem> emptyTaggedItems = Enumerable.Empty<WidgetFileTagCardItem>().ToImmutableList();
1413

1514
public bool IsAnyItemRightClicked => rightClickedItem is not null;
1615

@@ -20,20 +19,20 @@ internal class HomePageContext : ObservableObject, IHomePageContext
2019
private CommandBarFlyout? itemContextFlyoutMenu = null;
2120
public CommandBarFlyout? ItemContextFlyoutMenu => itemContextFlyoutMenu;
2221

23-
private IReadOnlyList<FileTagsItemViewModel> selectedTaggedItems = emptyTaggedItems;
24-
public IReadOnlyList<FileTagsItemViewModel> SelectedTaggedItems
22+
private IReadOnlyList<WidgetFileTagCardItem> selectedTaggedItems = emptyTaggedItems;
23+
public IReadOnlyList<WidgetFileTagCardItem> SelectedTaggedItems
2524
{
2625
get => selectedTaggedItems;
2726
set => selectedTaggedItems = value ?? emptyTaggedItems;
2827
}
2928

3029
public HomePageContext()
3130
{
32-
HomePageWidget.RightClickedItemChanged += HomePageWidget_RightClickedItemChanged;
31+
BaseWidgetViewModel.RightClickedItemChanged += HomePageWidget_RightClickedItemChanged;
3332
FileTagsWidget.SelectedTaggedItemsChanged += FileTagsWidget_SelectedTaggedItemsChanged;
3433
}
3534

36-
private void FileTagsWidget_SelectedTaggedItemsChanged(object? sender, IEnumerable<FileTagsItemViewModel> e)
35+
private void FileTagsWidget_SelectedTaggedItemsChanged(object? sender, IEnumerable<WidgetFileTagCardItem> e)
3736
{
3837
SetProperty(ref selectedTaggedItems, e.ToList());
3938
}

src/Files.App/Data/Contexts/HomePage/IHomePageContext.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) 2023 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4-
using Files.App.UserControls.Widgets;
5-
using Files.App.ViewModels.Widgets;
64
using Microsoft.UI.Xaml.Controls;
75

86
namespace Files.App.Data.Contexts
@@ -22,7 +20,7 @@ internal interface IHomePageContext
2220
/// <summary>
2321
/// An list containing all the selected tagged items
2422
/// </summary>
25-
IReadOnlyList<FileTagsItemViewModel> SelectedTaggedItems { get; }
23+
IReadOnlyList<WidgetFileTagCardItem> SelectedTaggedItems { get; }
2624

2725
/// <summary>
2826
/// Tells whether any item has been right clicked

src/Files.App/Data/Contexts/Tags/TagsContext.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
// Copyright (c) 2023 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4-
using Files.App.ViewModels.Widgets;
54
using System.Collections.Immutable;
65

76
namespace Files.App.Data.Contexts
87
{
9-
sealed class TagsContext : ITagsContext
8+
sealed class TagsContext : ITagsContext
109
{
1110
private static readonly IReadOnlyList<(string path, bool isFolder)> _emptyTaggedItemsList
1211
= Enumerable.Empty<(string path, bool isFolder)>().ToImmutableList();
@@ -29,7 +28,7 @@ sealed class TagsContext : ITagsContext
2928

3029
public TagsContext()
3130
{
32-
FileTagsContainerViewModel.SelectedTagChanged += SelectedTagsChanged;
31+
WidgetFileTagsContainerItem.SelectedTagChanged += SelectedTagsChanged;
3332
SidebarViewModel.SelectedTagChanged += SelectedTagsChanged;
3433
}
3534

src/Files.App/Data/Items/INavigationControlItem.cs renamed to src/Files.App/Data/Contracts/INavigationControlItem.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
// Licensed under the MIT License. See the LICENSE.
33

44
using Files.App.UserControls.Sidebar;
5-
using Microsoft.UI.Xaml.Controls;
65

7-
namespace Files.App.Data.Items
6+
namespace Files.App.Data.Contracts
87
{
9-
108
public interface INavigationControlItem : IComparable<INavigationControlItem>, INotifyPropertyChanged, ISidebarItemModel
119
{
1210
public new string Text { get; }

src/Files.App/UserControls/Widgets/IWidgetCardItem.cs renamed to src/Files.App/Data/Contracts/IWidgetCardItem.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
// Licensed under the MIT License. See the LICENSE.
33

44
using Microsoft.UI.Xaml.Media.Imaging;
5-
using System.Threading.Tasks;
65

7-
namespace Files.App.UserControls.Widgets
6+
namespace Files.App.Data.Contracts
87
{
98
public interface IWidgetCardItem<T>
109
{
@@ -14,4 +13,4 @@ public interface IWidgetCardItem<T>
1413

1514
Task LoadCardThumbnailAsync();
1615
}
17-
}
16+
}

src/Files.App/ViewModels/Widgets/IWidgetItem.cs renamed to src/Files.App/Data/Contracts/IWidgetViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
using Microsoft.UI.Xaml.Controls;
55

6-
namespace Files.App.ViewModels.Widgets
6+
namespace Files.App.Data.Contracts
77
{
8-
public interface IWidgetItem : IDisposable
8+
public interface IWidgetViewModel : IDisposable
99
{
1010
string WidgetName { get; }
1111

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) 2023 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
namespace Files.App.Data.EventArguments
5+
{
6+
public class QuickAccessCardEventArgs : EventArgs
7+
{
8+
public LocationItem? Item { get; set; }
9+
}
10+
11+
public class QuickAccessCardInvokedEventArgs : EventArgs
12+
{
13+
public string? Path { get; set; }
14+
}
15+
16+
public class ModifyQuickAccessEventArgs : EventArgs
17+
{
18+
public string[]? Paths { get; set; }
19+
public ShellFileItem[]? Items { get; set; }
20+
public bool Add;
21+
public bool Pin = true;
22+
public bool Reset = false;
23+
public bool Reorder = false;
24+
25+
public ModifyQuickAccessEventArgs(string[] paths, bool add)
26+
{
27+
Paths = paths;
28+
Add = add;
29+
}
30+
31+
public ModifyQuickAccessEventArgs(ShellFileItem[] items, bool add)
32+
{
33+
Paths = items.Select(x => x.FilePath).ToArray();
34+
Items = items;
35+
Add = add;
36+
}
37+
}
38+
}

src/Files.App/Data/EventArguments/WidgetsRightClickedItemChangedEventArgs.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) 2023 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4-
using Files.App.UserControls.Widgets;
54
using Microsoft.UI.Xaml.Controls;
65

76
namespace Files.App.Data.EventArguments

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,4 @@ public RecycleBinLocationItem()
155155
RecycleBinManager.Default.RecycleBinItemDeleted += RefreshSpaceUsed;
156156
}
157157
}
158-
}
158+
}

src/Files.App/Utils/Library/LibraryLocationItem.cs renamed to src/Files.App/Data/Items/SidebarLibraryItem.cs

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

4-
namespace Files.App.Utils.Library
4+
namespace Files.App.Data.Items
55
{
66
public class LibraryLocationItem : LocationItem
77
{
@@ -57,4 +57,4 @@ public async Task LoadLibraryIconAsync()
5757
public override bool Equals(object obj)
5858
=> obj is LibraryLocationItem other && GetType() == obj.GetType() && string.Equals(Path, other.Path, System.StringComparison.OrdinalIgnoreCase);
5959
}
60-
}
60+
}

0 commit comments

Comments
 (0)