Skip to content
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

Code Quality: Clean up Widgets #13808

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
39cc097
Move 1
0x5bfa Nov 11, 2023
ece82f0
Refactor
0x5bfa Nov 11, 2023
7d8875c
Update
0x5bfa Nov 11, 2023
471a9bc
Working well!
0x5bfa Nov 12, 2023
a511511
Update
0x5bfa Nov 12, 2023
f0a23e5
Fix
0x5bfa Nov 12, 2023
9c02178
Added comments
0x5bfa Nov 14, 2023
1e077c6
Merge remote-tracking branch 'upstream/main' into 5bfa/Cleanup-Widgets
0x5bfa Nov 15, 2023
60f714f
Code Quality: Refactored ToolbarViewModel (#13659)
0x5bfa Nov 16, 2023
e4dc3ee
Fix: Fixed ArgumentException with ShowViewControlButton (#13911)
yaira2 Nov 16, 2023
9449b7a
New Crowdin updates (#13912)
yaira2 Nov 16, 2023
663dc41
Fix: Fixed NullReferenceException with HasTags (#13708)
yaira2 Nov 16, 2023
1bb6fc0
Build(deps): Bump Microsoft.Extensions.Logging from 7.0.0 to 8.0.0 (#…
dependabot[bot] Nov 16, 2023
b459484
Build(deps): Bump Microsoft.Extensions.Hosting from 7.0.1 to 8.0.0 (#…
dependabot[bot] Nov 16, 2023
287d80b
Fix: Fixed potential COMException when updating preview pane selectio…
yaira2 Nov 17, 2023
948e102
Fix: Fixed null exception with isRenaming (#13914)
yaira2 Nov 17, 2023
4c5d0f2
Fix: Fixed potential COMException when setting the wallpaper (#13921)
yaira2 Nov 17, 2023
cef90ad
Fix: Fixed IO Error in RunCompatibilityTroubleshooterAsync (#13920)
yaira2 Nov 17, 2023
46626f7
Fix: Fixed NullReferenceException in SetSelectedPathOrNavigate (#13923)
hishitetsu Nov 17, 2023
e4b0d49
Release: 3.0.6
yaira2 Nov 17, 2023
086154c
merge upstream/main into here
0x5bfa Nov 17, 2023
d3dc6f2
Added comments
0x5bfa Nov 17, 2023
822f72b
Fix
0x5bfa Nov 17, 2023
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
2 changes: 1 addition & 1 deletion src/Files.App (Package)/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<Identity
Name="FilesDev"
Publisher="CN=Files"
Version="3.0.5.0" />
Version="3.0.6.0" />

<Properties>
<DisplayName>Files - Dev</DisplayName>
Expand Down
16 changes: 15 additions & 1 deletion src/Files.App/Actions/Content/Selection/InvertSelectionAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Files.App.Actions
{
internal class InvertSelectionAction : IAction
internal class InvertSelectionAction : ObservableObject, IAction
{
private readonly IContentPageContext context;

Expand Down Expand Up @@ -41,6 +41,8 @@ public bool IsExecutable
public InvertSelectionAction()
{
context = Ioc.Default.GetRequiredService<IContentPageContext>();

context.PropertyChanged += Context_PropertyChanged;
}

public Task ExecuteAsync()
Expand All @@ -49,5 +51,17 @@ public Task ExecuteAsync()

return Task.CompletedTask;
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IContentPageContext.PageType):
case nameof(IContentPageContext.HasItem):
case nameof(IContentPageContext.ShellPage):
OnPropertyChanged(nameof(IsExecutable));
break;
}
}
}
}
2 changes: 1 addition & 1 deletion src/Files.App/Actions/Content/Selection/SelectAllAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public bool IsExecutable

bool isCommandPaletteOpen = page.ToolbarViewModel.IsCommandPaletteOpen;
bool isEditing = page.ToolbarViewModel.IsEditModeEnabled;
bool isRenaming = page.SlimContentPage.IsRenamingItem;
bool isRenaming = page.SlimContentPage?.IsRenamingItem ?? false;

return isCommandPaletteOpen || (!isEditing && !isRenaming);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
OnPropertyChanged(nameof(IsOn));
}
}
}
}
7 changes: 7 additions & 0 deletions src/Files.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ private IHost ConfigureHost()
.AddSingleton<NetworkDrivesViewModel>()
.AddSingleton<StatusCenterViewModel>()
.AddSingleton<AppearanceViewModel>()
.AddSingleton<PathBreadcrumbViewModel>()
.AddSingleton<AddressToolbarViewModel>()
.AddTransient<HomeViewModel>()
.AddTransient<DrivesWidgetViewModel>()
.AddTransient<FileTagsWidgetViewModel>()
.AddTransient<QuickAccessWidgetViewModel>()
.AddTransient<RecentFilesWidgetViewModel>()
).Build();
}

Expand Down
14 changes: 7 additions & 7 deletions src/Files.App/Data/Contexts/ContentPage/ContentPageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ private void ToolbarViewModel_PropertyChanged(object? sender, PropertyChangedEve
{
switch (e.PropertyName)
{
case nameof(ToolbarViewModel.CanGoBack):
case nameof(ToolbarViewModel.CanGoForward):
case nameof(ToolbarViewModel.CanNavigateToParent):
case nameof(ToolbarViewModel.HasItem):
case nameof(ToolbarViewModel.CanRefresh):
case nameof(ToolbarViewModel.IsSearchBoxVisible):
case nameof(AddressToolbarViewModel.CanGoBack):
case nameof(AddressToolbarViewModel.CanGoForward):
case nameof(AddressToolbarViewModel.CanNavigateToParent):
case nameof(AddressToolbarViewModel.HasItem):
case nameof(AddressToolbarViewModel.CanRefresh):
case nameof(AddressToolbarViewModel.IsSearchBoxVisible):
OnPropertyChanged(e.PropertyName);
break;
case nameof(ToolbarViewModel.SelectedItems):
case nameof(AddressToolbarViewModel.SelectedItems):
UpdateSelectedItems();
break;
}
Expand Down
10 changes: 10 additions & 0 deletions src/Files.App/Data/EventArguments/DrivesWidgetInvokedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

namespace Files.App.Data.EventArguments
{
public class DrivesWidgetInvokedEventArgs : EventArgs
{
public string? Path { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Files.App.Data.EventArguments
{
public class PathBoxItemDroppedEventArgs
public class PathBreadcrumbItemDroppedEventArgs
{
public DataPackageView Package { get; set; }

Expand Down
41 changes: 41 additions & 0 deletions src/Files.App/Data/EventArguments/QuickAccessCardEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Files.App.Data.EventArguments
{
public class QuickAccessCardEventArgs : EventArgs
{
public LocationItem Item { get; set; }
}

public class QuickAccessCardInvokedEventArgs : EventArgs
{
public string Path { get; set; }
}

public class ModifyQuickAccessEventArgs : EventArgs
{
public string[] Paths { get; set; }
public ShellFileItem[] Items { get; set; }
public bool Add;
public bool Pin = true;
public bool Reset = false;
public bool Reorder = false;

public ModifyQuickAccessEventArgs(string[] paths, bool add)
{
Paths = paths;
Add = add;
}

public ModifyQuickAccessEventArgs(ShellFileItem[] items, bool add)
{
Paths = items.Select(x => x.FilePath).ToArray();
Items = items;
Add = add;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public class ToolbarPathItemLoadedEventArgs
{
public MenuFlyout OpenedFlyout { get; set; }

public PathBoxItem Item { get; set; }
public PathBreadcrumbItem Item { get; set; }
}
}
46 changes: 46 additions & 0 deletions src/Files.App/Data/Items/DriveCardItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Microsoft.UI.Xaml.Media.Imaging;

namespace Files.App.Data.Items
{
public class DriveCardItem : WidgetCardItem, IWidgetCardItem<DriveItem>, IComparable<DriveCardItem>
{
private BitmapImage thumbnail;
private byte[] thumbnailData;

public new DriveItem Item { get; private set; }
public bool HasThumbnail => thumbnail is not null && thumbnailData is not null;
public BitmapImage Thumbnail
{
get => thumbnail;
set => SetProperty(ref thumbnail, value);
}
public DriveCardItem(DriveItem item)
{
Item = item;
Path = item.Path;
}

public async Task LoadCardThumbnailAsync()
{
// Try load thumbnail using ListView mode
if (thumbnailData is null || thumbnailData.Length == 0)
thumbnailData = await FileThumbnailHelper.LoadIconFromPathAsync(Item.Path, Convert.ToUInt32(Constants.Widgets.WidgetIconSize), Windows.Storage.FileProperties.ThumbnailMode.SingleItem, Windows.Storage.FileProperties.ThumbnailOptions.ResizeThumbnail);

// Thumbnail is still null, use DriveItem icon (loaded using SingleItem mode)
if (thumbnailData is null || thumbnailData.Length == 0)
{
await Item.LoadThumbnailAsync();
thumbnailData = Item.IconData;
}

// Thumbnail data is valid, set the item icon
if (thumbnailData is not null && thumbnailData.Length > 0)
Thumbnail = await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(() => thumbnailData.ToBitmapAsync(Constants.Widgets.WidgetIconSize));
}

public int CompareTo(DriveCardItem? other) => Item.Path.CompareTo(other?.Item?.Path);
}
}
57 changes: 32 additions & 25 deletions src/Files.App/Data/Items/DriveItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ namespace Files.App.Data.Items
{
public class DriveItem : ObservableObject, INavigationControlItem, ILocatableFolder
{
private BitmapImage icon;
public BitmapImage Icon
private BitmapImage? _Icon;
public BitmapImage? Icon
{
get => icon;
get => _Icon;
set
{
SetProperty(ref icon, value, nameof(Icon));
SetProperty(ref _Icon, value, nameof(Icon));
OnPropertyChanged(nameof(IconSource));
}
}

public byte[] IconData { get; set; }

private string path;
private string _Path;
public string Path
{
get => path;
set => path = value;
get => _Path;
set => _Path = value;
}

public string DeviceID { get; set; }
Expand All @@ -52,7 +52,7 @@ public bool IsNetwork
=> Type == DriveType.Network;

public bool IsPinned
=> App.QuickAccessManager.Model.FavoriteItems.Contains(path);
=> App.QuickAccessManager.Model.FavoriteItems.Contains(_Path);

public string MaxSpaceText
=> MaxSpace.ToSizeString();
Expand Down Expand Up @@ -133,43 +133,43 @@ public DriveType Type
}
}

private string text;
private string _Text;
public string Text
{
get => text;
set => SetProperty(ref text, value);
get => _Text;
set => SetProperty(ref _Text, value);
}

private string spaceText;
private string _SpaceText;
public string SpaceText
{
get => spaceText;
set => SetProperty(ref spaceText, value);
get => _SpaceText;
set => SetProperty(ref _SpaceText, value);
}

public SectionType Section { get; set; }

public ContextMenuOptions MenuOptions { get; set; }

private float percentageUsed = 0.0f;
private float _PercentageUsed = 0.0f;
public float PercentageUsed
{
get => percentageUsed;
get => _PercentageUsed;
set
{
if (!SetProperty(ref percentageUsed, value))
if (!SetProperty(ref _PercentageUsed, value))
return;

if (Type == DriveType.Fixed)
ShowStorageSense = percentageUsed >= Constants.Widgets.Drives.LowStorageSpacePercentageThreshold;
ShowStorageSense = _PercentageUsed >= Constants.Widgets.Drives.LowStorageSpacePercentageThreshold;
}
}

private bool showStorageSense = false;
private bool _ShowStorageSense = false;
public bool ShowStorageSense
{
get => showStorageSense;
set => SetProperty(ref showStorageSense, value);
get => _ShowStorageSense;
set => SetProperty(ref _ShowStorageSense, value);
}

public string Id => DeviceID;
Expand All @@ -178,13 +178,13 @@ public bool ShowStorageSense

public object? Children => null;

private object toolTip = "";
private object _ToolTip = "";
public object ToolTip
{
get => toolTip;
get => _ToolTip;
set
{
SetProperty(ref toolTip, value);
SetProperty(ref _ToolTip, value);
}
}

Expand Down Expand Up @@ -242,7 +242,7 @@ public static async Task<DriveItem> CreateFromPropertiesAsync(StorageFolder root
DriveType.CDRom when !string.IsNullOrEmpty(label) => root.DisplayName.Replace(label.Left(32), label),
_ => root.DisplayName
};
item.Type = type;

item.MenuOptions = new ContextMenuOptions
{
IsLocationItem = true,
Expand All @@ -251,6 +251,8 @@ public static async Task<DriveItem> CreateFromPropertiesAsync(StorageFolder root
ShowFormatDrive = !(item.Type == DriveType.Network || string.Equals(root.Path, "C:\\", StringComparison.OrdinalIgnoreCase)),
ShowProperties = true
};

item.Type = type;
item.Path = string.IsNullOrEmpty(root.Path) ? $"\\\\?\\{root.Name}\\" : root.Path;
item.DeviceID = deviceId;
item.Root = root;
Expand Down Expand Up @@ -337,6 +339,7 @@ public async Task LoadThumbnailAsync(bool isSidebar = false)

IconData ??= UIHelpers.GetSidebarIconResourceInfo(Constants.ImageRes.Folder).IconData;
}

Icon ??= await IconData.ToBitmapAsync();
}

Expand All @@ -351,24 +354,28 @@ private string GetSizeString()
public Task<INestedFile> GetFileAsync(string fileName, CancellationToken cancellationToken = default)
{
var folder = new WindowsStorageFolder(Root);

return folder.GetFileAsync(fileName, cancellationToken);
}

public Task<INestedFolder> GetFolderAsync(string folderName, CancellationToken cancellationToken = default)
{
var folder = new WindowsStorageFolder(Root);

return folder.GetFolderAsync(folderName, cancellationToken);
}

public IAsyncEnumerable<INestedStorable> GetItemsAsync(StorableKind kind = StorableKind.All, CancellationToken cancellationToken = default)
{
var folder = new WindowsStorageFolder(Root);

return folder.GetItemsAsync(kind, cancellationToken);
}

public Task<IFolder?> GetParentAsync(CancellationToken cancellationToken = default)
{
var folder = new WindowsStorageFolder(Root);

return folder.GetParentAsync(cancellationToken);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.UserControls.Widgets;
using Files.App.ViewModels.UserControls.Widgets;
using Files.Core.Storage;
using Files.Core.Storage.Extensions;
using Files.Shared.Utils;
Expand Down
Loading