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

Fix: Fixed some null reference warnings #13776

Merged
merged 3 commits into from
Nov 10, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public CompressIntoArchiveAction()

public override async Task ExecuteAsync()
{
if (context.ShellPage is null)
return;

var (sources, directory, fileName) = CompressHelper.GetCompressDestination(context.ShellPage);

var dialog = new CreateArchiveDialog
Expand Down
5 changes: 4 additions & 1 deletion src/Files.App/Actions/Content/RefreshItemsAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ public RefreshItemsAction()

public async Task ExecuteAsync()
{
context.ShellPage?.Refresh_ClickAsync();
if (context.ShellPage is null)
return;

await context.ShellPage.Refresh_Click();
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public RunWithPowershellAction()

public Task ExecuteAsync()
{
return Win32API.RunPowershellCommandAsync($"{context.ShellPage?.SlimContentPage?.SelectedItem.ItemPath}", false);
return Win32API.RunPowershellCommandAsync($"{context.ShellPage?.SlimContentPage?.SelectedItem?.ItemPath}", false);
}

private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Actions/FileSystem/CopyItemAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public string Description
=> "CopyItemDescription".GetLocalizedResource();

public RichGlyph Glyph
=> new RichGlyph(opacityStyle: "ColorIconCopy");
=> new(opacityStyle: "ColorIconCopy");

public HotKey HotKey
=> new(Keys.C, KeyModifiers.Ctrl);
Expand Down
8 changes: 6 additions & 2 deletions src/Files.App/Actions/FileSystem/OpenFileLocationAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public RichGlyph Glyph
=> new(baseGlyph: "\uE8DA");

public bool IsExecutable =>
context.ShellPage is not null &&
context.HasSelection &&
context.SelectedItem is ShortcutItem;

Expand All @@ -31,18 +32,21 @@ public OpenFileLocationAction()

public async Task ExecuteAsync()
{
if (context.ShellPage?.FilesystemViewModel is null)
return;

var item = context.SelectedItem as ShortcutItem;

if (string.IsNullOrWhiteSpace(item?.TargetPath))
return;

// Check if destination path exists
var folderPath = Path.GetDirectoryName(item.TargetPath);
var destFolder = await context.ShellPage?.FilesystemViewModel.GetFolderWithPathFromPathAsync(folderPath);
var destFolder = await context.ShellPage.FilesystemViewModel.GetFolderWithPathFromPathAsync(folderPath);

if (destFolder)
{
context.ShellPage?.NavigateWithArguments(context.ShellPage?.InstanceViewModel.FolderSettings.GetLayoutType(folderPath), new NavigationArguments()
context.ShellPage?.NavigateWithArguments(context.ShellPage.InstanceViewModel.FolderSettings.GetLayoutType(folderPath), new NavigationArguments()
{
NavPathParam = folderPath,
SelectItems = new[] { Path.GetFileName(item.TargetPath.TrimPath()) },
Expand Down
9 changes: 8 additions & 1 deletion src/Files.App/Actions/FileSystem/OpenItemAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public RichGlyph Glyph

public bool IsExecutable =>
context.HasSelection &&
context.ShellPage is not null &&
context.ShellPage.InstanceViewModel.IsPageTypeSearchResults;

public OpenParentFolderAction()
Expand All @@ -113,8 +114,14 @@ public OpenParentFolderAction()

public async Task ExecuteAsync()
{
if (context.ShellPage is null)
return;

var item = context.SelectedItem;
var folderPath = Path.GetDirectoryName(item.ItemPath.TrimEnd('\\'));
var folderPath = Path.GetDirectoryName(item?.ItemPath.TrimEnd('\\'));

if (folderPath is null || item is null)
return;

context.ShellPage.NavigateWithArguments(context.ShellPage.InstanceViewModel.FolderSettings.GetLayoutType(folderPath), new NavigationArguments()
{
Expand Down
5 changes: 5 additions & 0 deletions src/Files.App/Actions/Navigation/OpenInNewWindowItemAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public RichGlyph Glyph
=> new(opacityStyle: "ColorIconOpenInNewWindow");

public bool IsExecutable =>
context.ShellPage is not null &&
context.ShellPage.SlimContentPage is not null &&
context.SelectedItems.Count <= 5 &&
context.SelectedItems.Where(x => x.IsFolder == true).Count() == context.SelectedItems.Count &&
userSettingsService.GeneralSettingsService.ShowOpenInNewWindow;
Expand All @@ -35,6 +37,9 @@ public OpenInNewWindowItemAction()

public async Task ExecuteAsync()
{
if (context.ShellPage?.SlimContentPage?.SelectedItems is null)
return;

List<ListedItem> items = context.ShellPage.SlimContentPage.SelectedItems;

foreach (ListedItem listedItem in items)
Expand Down
11 changes: 7 additions & 4 deletions src/Files.App/Actions/Start/PinToStartAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,24 @@ public string Description
public RichGlyph Glyph
=> new(opacityStyle: "ColorIconPinToFavorites");

public bool IsExecutable =>
context.ShellPage is not null;

public PinToStartAction()
{
context = Ioc.Default.GetRequiredService<IContentPageContext>();
}

public async Task ExecuteAsync()
{
if (context.SelectedItems.Count > 0)
if (context.SelectedItems.Count > 0 && context.ShellPage?.SlimContentPage?.SelectedItems is not null)
{
foreach (ListedItem listedItem in context.ShellPage?.SlimContentPage.SelectedItems)
foreach (ListedItem listedItem in context.ShellPage.SlimContentPage.SelectedItems)
await App.SecondaryTileHelper.TryPinFolderAsync(listedItem.ItemPath, listedItem.Name);
}
else
else if (context.ShellPage?.FilesystemViewModel?.CurrentFolder is not null)
{
await App.SecondaryTileHelper.TryPinFolderAsync(context.ShellPage?.FilesystemViewModel.CurrentFolder.ItemPath, context.ShellPage?.FilesystemViewModel.CurrentFolder.Name);
await App.SecondaryTileHelper.TryPinFolderAsync(context.ShellPage.FilesystemViewModel.CurrentFolder.ItemPath, context.ShellPage.FilesystemViewModel.CurrentFolder.Name);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Files.App/Views/Shells/BaseShellPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ protected async void ShellPage_TextChanged(ISearchBox sender, SearchBoxTextChang

protected void ShellPage_RefreshRequested(object sender, EventArgs e)
{
Refresh_ClickAsync();
Refresh_Click();
}

protected void AppSettings_SortDirectionPreferenceUpdated(object sender, SortDirection e)
Expand Down Expand Up @@ -511,10 +511,10 @@ public Task TabItemDrop(object sender, DragEventArgs e)
public async Task RefreshIfNoWatcherExistsAsync()
{
if (FilesystemViewModel.HasNoWatcher)
await Refresh_ClickAsync();
await Refresh_Click();
}

public async Task Refresh_ClickAsync()
public async Task Refresh_Click()
{
if (InstanceViewModel.IsPageTypeSearchResults)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Views/Shells/IShellPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public interface IShellPage : ITabBarItemContent, IMultiPaneInfo, IDisposable, I

Task RefreshIfNoWatcherExistsAsync();

Task Refresh_ClickAsync();
Task Refresh_Click();

void Back_Click();

Expand Down