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: Fixed null warnings in MainPage.xaml.cs #14145

Merged
merged 18 commits into from
Dec 11, 2023
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
2 changes: 1 addition & 1 deletion src/Files.App/Helpers/Navigation/NavigationHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ private static async Task UpdateTabInfoAsync(TabBarItem tabItem, object navigati
return (tabLocationHeader, iconSource, toolTipText);
}

public static async Task UpdateInstancePropertiesAsync(object navigationArg)
public static async Task UpdateInstancePropertiesAsync(object? navigationArg)
{
await SafetyExtensions.IgnoreExceptions(async () =>
{
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/UserControls/AddressToolbar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public bool ShowSearchBox
// Using a DependencyProperty as the backing store for ViewModel. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ViewModelProperty =
DependencyProperty.Register(nameof(ViewModel), typeof(ToolbarViewModel), typeof(AddressToolbar), new PropertyMetadata(null));
public ToolbarViewModel ViewModel
public ToolbarViewModel? ViewModel
{
get => (ToolbarViewModel)GetValue(ViewModelProperty);
set => SetValue(ViewModelProperty, value);
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/UserControls/InnerNavigationToolbar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public InnerNavigationToolbar()

public AppModel AppModel => App.AppModel;

public ToolbarViewModel ViewModel
public ToolbarViewModel? ViewModel
{
get => (ToolbarViewModel)GetValue(ViewModelProperty);
set => SetValue(ViewModelProperty, value);
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/UserControls/StatusBarControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public DirectoryPropertiesViewModel? DirectoryPropertiesViewModel
public static readonly DependencyProperty DirectoryPropertiesViewModelProperty =
DependencyProperty.Register(nameof(DirectoryPropertiesViewModel), typeof(DirectoryPropertiesViewModel), typeof(StatusBarControl), new PropertyMetadata(null));

public SelectedItemsPropertiesViewModel SelectedItemsPropertiesViewModel
public SelectedItemsPropertiesViewModel? SelectedItemsPropertiesViewModel
{
get => (SelectedItemsPropertiesViewModel)GetValue(SelectedItemsPropertiesViewModelProperty);
set => SetValue(SelectedItemsPropertiesViewModelProperty, value);
Expand Down
18 changes: 14 additions & 4 deletions src/Files.App/Utils/RecycleBin/RecycleBinHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,14 @@ public static async Task RestoreRecycleBinAsync()

public static async Task RestoreSelectionRecycleBinAsync(IShellPage associatedInstance)
{
var items = associatedInstance.SlimContentPage.SelectedItems;
if (items == null)
return;
var ConfirmEmptyBinDialog = new ContentDialog()
{
Title = "ConfirmRestoreSelectionBinDialogTitle".GetLocalizedResource(),
Content = string.Format("ConfirmRestoreSelectionBinDialogContent".GetLocalizedResource(), associatedInstance.SlimContentPage.SelectedItems.Count),

Content = string.Format("ConfirmRestoreSelectionBinDialogContent".GetLocalizedResource(), items.Count),
PrimaryButtonText = "Yes".GetLocalizedResource(),
SecondaryButtonText = "Cancel".GetLocalizedResource(),
DefaultButton = ContentDialogButton.Primary
Expand Down Expand Up @@ -152,7 +156,10 @@ public static bool RecycleBinHasItems()

public static async Task RestoreItemAsync(IShellPage associatedInstance)
{
var items = associatedInstance.SlimContentPage.SelectedItems.ToList().Where(x => x is RecycleBinItem).Select((item) => new
var selected = associatedInstance.SlimContentPage.SelectedItems;
if (selected == null)
return;
var items = selected.ToList().Where(x => x is RecycleBinItem).Select((item) => new
{
Source = StorageHelpers.FromPathAndType(
item.ItemPath,
Expand All @@ -164,10 +171,13 @@ public static async Task RestoreItemAsync(IShellPage associatedInstance)

public static async Task DeleteItemAsync(IShellPage associatedInstance)
{
var items = associatedInstance.SlimContentPage.SelectedItems.ToList().Select((item) => StorageHelpers.FromPathAndType(
var selected = associatedInstance.SlimContentPage.SelectedItems;
if (selected == null)
return;
var items = selected.ToList().Select((item) => StorageHelpers.FromPathAndType(
item.ItemPath,
item.PrimaryItemAttribute == StorageItemTypes.File ? FilesystemItemType.File : FilesystemItemType.Directory));
await associatedInstance.FilesystemHelpers.DeleteItemsAsync(items, userSettingsService.FoldersSettingsService.DeleteConfirmationPolicy, false, true);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class StorageHistoryWrapper : IDisposable

public IStorageHistory GetCurrentHistory() => histories[index];

public void AddHistory(IStorageHistory history)
public void AddHistory(IStorageHistory? history)
{
if (history is not null)
{
Expand Down
15 changes: 9 additions & 6 deletions src/Files.App/Utils/Storage/Operations/FilesystemHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public sealed class FilesystemHelpers : IFilesystemHelpers
private readonly IJumpListService jumpListService;
private IFilesystemOperations filesystemOperations;

private ItemManipulationModel itemManipulationModel => associatedInstance.SlimContentPage?.ItemManipulationModel;
private ItemManipulationModel? itemManipulationModel => associatedInstance.SlimContentPage?.ItemManipulationModel;

private readonly CancellationToken cancellationToken;
private static char[] RestrictedCharacters
Expand Down Expand Up @@ -58,7 +58,7 @@ public FilesystemHelpers(IShellPage associatedInstance, CancellationToken cancel
jumpListService = Ioc.Default.GetRequiredService<IJumpListService>();
filesystemOperations = new ShellFilesystemOperations(this.associatedInstance);
}
public async Task<(ReturnResult, IStorageItem)> CreateAsync(IStorageItemWithPath source, bool registerHistory)
public async Task<(ReturnResult, IStorageItem?)> CreateAsync(IStorageItemWithPath source, bool registerHistory)
{
var returnStatus = ReturnResult.InProgress;
var progress = new Progress<StatusCenterItemProgressModel>();
Expand Down Expand Up @@ -363,7 +363,7 @@ public async Task<ReturnResult> CopyItemsFromClipboard(DataPackageView packageVi
ReturnResult returnStatus = ReturnResult.InProgress;

var destinations = new List<string>();
List<ShellFileItem> binItems = null;
List<ShellFileItem>? binItems = null;
foreach (var item in source)
{
if (RecycleBinHelpers.IsPathUnderRecycleBin(item.Path))
Expand Down Expand Up @@ -511,7 +511,7 @@ public async Task<ReturnResult> MoveItemsFromClipboard(DataPackageView packageVi
ReturnResult returnStatus = ReturnResult.InProgress;

var destinations = new List<string>();
List<ShellFileItem> binItems = null;
List<ShellFileItem>? binItems = null;
foreach (var item in source)
{
if (RecycleBinHelpers.IsPathUnderRecycleBin(item.Path))
Expand Down Expand Up @@ -551,7 +551,7 @@ await DialogDisplayHelper.ShowDialogAsync(
return ReturnResult.Failed;
}

IStorageHistory history = null;
IStorageHistory? history = null;

switch (source.ItemType)
{
Expand Down Expand Up @@ -658,7 +658,8 @@ public static bool IsValidForFilename(string name)
{
var itemPathOrName = string.IsNullOrEmpty(item.src.Path) ? item.src.Item.Name : item.src.Path;
incomingItems.Add(new FileSystemDialogConflictItemViewModel() { ConflictResolveOption = FileNameConflictResolveOptionType.None, SourcePath = itemPathOrName, DestinationPath = item.dest, DestinationDisplayName = Path.GetFileName(item.dest) });
if (collisions.ContainsKey(incomingItems.ElementAt(item.index).SourcePath))
var path = incomingItems.ElementAt(item.index).SourcePath;
if (path is not null && collisions.ContainsKey(path))
{
// Something strange happened, log
App.Logger.LogWarning($"Duplicate key when resolving conflicts: {incomingItems.ElementAt(item.index).SourcePath}, {item.src.Name}\n" +
Expand Down Expand Up @@ -870,6 +871,8 @@ public void Dispose()
{
filesystemOperations?.Dispose();

// SUPPRESS: Cannot convert null literal to non-nullable reference type.
#pragma warning disable CS8625
associatedInstance = null;
filesystemOperations = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface IFilesystemHelpers : IDisposable
/// <param name="source">FullPath to the item</param>
/// <param name="registerHistory">Determines whether <see cref="IStorageHistory"/> is saved</param>
/// <returns><see cref="ReturnResult"/> of performed operation</returns>
Task<(ReturnResult, IStorageItem)> CreateAsync(IStorageItemWithPath source, bool registerHistory);
Task<(ReturnResult, IStorageItem?)> CreateAsync(IStorageItemWithPath source, bool registerHistory);

#region Delete

Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/ViewModels/UserControls/SidebarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ public SidebarDisplayMode SidebarDisplayMode
public bool IsSidebarCompactSize
=> SidebarDisplayMode == SidebarDisplayMode.Compact || SidebarDisplayMode == SidebarDisplayMode.Minimal;

public void NotifyInstanceRelatedPropertiesChanged(string arg)
public void NotifyInstanceRelatedPropertiesChanged(string? arg)
{
UpdateSidebarSelectedItemFromArgs(arg);

OnPropertyChanged(nameof(SidebarSelectedItem));
}

public void UpdateSidebarSelectedItemFromArgs(string arg)
public void UpdateSidebarSelectedItemFromArgs(string? arg)
{
var value = arg;

Expand Down
11 changes: 7 additions & 4 deletions src/Files.App/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public async void TabItemContent_ContentChanged(object? sender, CustomTabViewIte

var paneArgs = e.NavigationParameter as PaneNavigationArguments;
SidebarAdaptiveViewModel.UpdateSidebarSelectedItemFromArgs(SidebarAdaptiveViewModel.PaneHolder.IsLeftPaneActive ?
paneArgs.LeftPaneNavPathParam : paneArgs.RightPaneNavPathParam);
paneArgs?.LeftPaneNavPathParam : paneArgs?.RightPaneNavPathParam);

UpdateStatusBarProperties();
LoadPaneChanged();
Expand All @@ -175,9 +175,12 @@ public void MultitaskingControl_CurrentInstanceChanged(object? sender, CurrentIn
SidebarAdaptiveViewModel.PaneHolder.PropertyChanged -= PaneHolder_PropertyChanged;

var navArgs = e.CurrentInstance.TabItemParameter?.NavigationParameter;
SidebarAdaptiveViewModel.PaneHolder = e.CurrentInstance as IPaneHolder;
SidebarAdaptiveViewModel.PaneHolder.PropertyChanged += PaneHolder_PropertyChanged;
SidebarAdaptiveViewModel.NotifyInstanceRelatedPropertiesChanged((navArgs as PaneNavigationArguments).LeftPaneNavPathParam);
if (e.CurrentInstance is IPaneHolder currentInstance)
{
SidebarAdaptiveViewModel.PaneHolder = currentInstance;
SidebarAdaptiveViewModel.PaneHolder.PropertyChanged += PaneHolder_PropertyChanged;
}
SidebarAdaptiveViewModel.NotifyInstanceRelatedPropertiesChanged((navArgs as PaneNavigationArguments)?.LeftPaneNavPathParam);

if (SidebarAdaptiveViewModel.PaneHolder?.ActivePaneOrColumn.SlimContentPage?.DirectoryPropertiesViewModel is not null)
SidebarAdaptiveViewModel.PaneHolder.ActivePaneOrColumn.SlimContentPage.DirectoryPropertiesViewModel.ShowLocals = true;
Expand Down