Skip to content

Commit 6a35907

Browse files
authored
Fix: Fixed some null reference warnings (#13776)
1 parent cf1f09c commit 6a35907

File tree

10 files changed

+39
-14
lines changed

10 files changed

+39
-14
lines changed

src/Files.App/Actions/Content/Archives/Compress/CompressIntoArchiveAction.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public CompressIntoArchiveAction()
2020

2121
public override async Task ExecuteAsync()
2222
{
23+
if (context.ShellPage is null)
24+
return;
25+
2326
var (sources, directory, fileName) = CompressHelper.GetCompressDestination(context.ShellPage);
2427

2528
var dialog = new CreateArchiveDialog

src/Files.App/Actions/Content/RefreshItemsAction.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ public RefreshItemsAction()
3434

3535
public async Task ExecuteAsync()
3636
{
37-
context.ShellPage?.Refresh_ClickAsync();
37+
if (context.ShellPage is null)
38+
return;
39+
40+
await context.ShellPage.Refresh_Click();
3841
}
3942

4043
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)

src/Files.App/Actions/Content/Run/RunWithPowershellAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public RunWithPowershellAction()
3131

3232
public Task ExecuteAsync()
3333
{
34-
return Win32API.RunPowershellCommandAsync($"{context.ShellPage?.SlimContentPage?.SelectedItem.ItemPath}", false);
34+
return Win32API.RunPowershellCommandAsync($"{context.ShellPage?.SlimContentPage?.SelectedItem?.ItemPath}", false);
3535
}
3636

3737
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)

src/Files.App/Actions/FileSystem/CopyItemAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public string Description
1414
=> "CopyItemDescription".GetLocalizedResource();
1515

1616
public RichGlyph Glyph
17-
=> new RichGlyph(opacityStyle: "ColorIconCopy");
17+
=> new(opacityStyle: "ColorIconCopy");
1818

1919
public HotKey HotKey
2020
=> new(Keys.C, KeyModifiers.Ctrl);

src/Files.App/Actions/FileSystem/OpenFileLocationAction.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public RichGlyph Glyph
1919
=> new(baseGlyph: "\uE8DA");
2020

2121
public bool IsExecutable =>
22+
context.ShellPage is not null &&
2223
context.HasSelection &&
2324
context.SelectedItem is ShortcutItem;
2425

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

3233
public async Task ExecuteAsync()
3334
{
35+
if (context.ShellPage?.FilesystemViewModel is null)
36+
return;
37+
3438
var item = context.SelectedItem as ShortcutItem;
3539

3640
if (string.IsNullOrWhiteSpace(item?.TargetPath))
3741
return;
3842

3943
// Check if destination path exists
4044
var folderPath = Path.GetDirectoryName(item.TargetPath);
41-
var destFolder = await context.ShellPage?.FilesystemViewModel.GetFolderWithPathFromPathAsync(folderPath);
45+
var destFolder = await context.ShellPage.FilesystemViewModel.GetFolderWithPathFromPathAsync(folderPath);
4246

4347
if (destFolder)
4448
{
45-
context.ShellPage?.NavigateWithArguments(context.ShellPage?.InstanceViewModel.FolderSettings.GetLayoutType(folderPath), new NavigationArguments()
49+
context.ShellPage?.NavigateWithArguments(context.ShellPage.InstanceViewModel.FolderSettings.GetLayoutType(folderPath), new NavigationArguments()
4650
{
4751
NavPathParam = folderPath,
4852
SelectItems = new[] { Path.GetFileName(item.TargetPath.TrimPath()) },

src/Files.App/Actions/FileSystem/OpenItemAction.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public RichGlyph Glyph
102102

103103
public bool IsExecutable =>
104104
context.HasSelection &&
105+
context.ShellPage is not null &&
105106
context.ShellPage.InstanceViewModel.IsPageTypeSearchResults;
106107

107108
public OpenParentFolderAction()
@@ -113,8 +114,14 @@ public OpenParentFolderAction()
113114

114115
public async Task ExecuteAsync()
115116
{
117+
if (context.ShellPage is null)
118+
return;
119+
116120
var item = context.SelectedItem;
117-
var folderPath = Path.GetDirectoryName(item.ItemPath.TrimEnd('\\'));
121+
var folderPath = Path.GetDirectoryName(item?.ItemPath.TrimEnd('\\'));
122+
123+
if (folderPath is null || item is null)
124+
return;
118125

119126
context.ShellPage.NavigateWithArguments(context.ShellPage.InstanceViewModel.FolderSettings.GetLayoutType(folderPath), new NavigationArguments()
120127
{

src/Files.App/Actions/Navigation/OpenInNewWindowItemAction.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public RichGlyph Glyph
2121
=> new(opacityStyle: "ColorIconOpenInNewWindow");
2222

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

3638
public async Task ExecuteAsync()
3739
{
40+
if (context.ShellPage?.SlimContentPage?.SelectedItems is null)
41+
return;
42+
3843
List<ListedItem> items = context.ShellPage.SlimContentPage.SelectedItems;
3944

4045
foreach (ListedItem listedItem in items)

src/Files.App/Actions/Start/PinToStartAction.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,24 @@ public string Description
1616
public RichGlyph Glyph
1717
=> new(opacityStyle: "ColorIconPinToFavorites");
1818

19+
public bool IsExecutable =>
20+
context.ShellPage is not null;
21+
1922
public PinToStartAction()
2023
{
2124
context = Ioc.Default.GetRequiredService<IContentPageContext>();
2225
}
2326

2427
public async Task ExecuteAsync()
2528
{
26-
if (context.SelectedItems.Count > 0)
29+
if (context.SelectedItems.Count > 0 && context.ShellPage?.SlimContentPage?.SelectedItems is not null)
2730
{
28-
foreach (ListedItem listedItem in context.ShellPage?.SlimContentPage.SelectedItems)
31+
foreach (ListedItem listedItem in context.ShellPage.SlimContentPage.SelectedItems)
2932
await App.SecondaryTileHelper.TryPinFolderAsync(listedItem.ItemPath, listedItem.Name);
3033
}
31-
else
34+
else if (context.ShellPage?.FilesystemViewModel?.CurrentFolder is not null)
3235
{
33-
await App.SecondaryTileHelper.TryPinFolderAsync(context.ShellPage?.FilesystemViewModel.CurrentFolder.ItemPath, context.ShellPage?.FilesystemViewModel.CurrentFolder.Name);
36+
await App.SecondaryTileHelper.TryPinFolderAsync(context.ShellPage.FilesystemViewModel.CurrentFolder.ItemPath, context.ShellPage.FilesystemViewModel.CurrentFolder.Name);
3437
}
3538
}
3639
}

src/Files.App/Views/Shells/BaseShellPage.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ protected async void ShellPage_TextChanged(ISearchBox sender, SearchBoxTextChang
366366

367367
protected void ShellPage_RefreshRequested(object sender, EventArgs e)
368368
{
369-
Refresh_ClickAsync();
369+
Refresh_Click();
370370
}
371371

372372
protected void AppSettings_SortDirectionPreferenceUpdated(object sender, SortDirection e)
@@ -511,10 +511,10 @@ public Task TabItemDrop(object sender, DragEventArgs e)
511511
public async Task RefreshIfNoWatcherExistsAsync()
512512
{
513513
if (FilesystemViewModel.HasNoWatcher)
514-
await Refresh_ClickAsync();
514+
await Refresh_Click();
515515
}
516516

517-
public async Task Refresh_ClickAsync()
517+
public async Task Refresh_Click()
518518
{
519519
if (InstanceViewModel.IsPageTypeSearchResults)
520520
{

src/Files.App/Views/Shells/IShellPage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public interface IShellPage : ITabBarItemContent, IMultiPaneInfo, IDisposable, I
3838

3939
Task RefreshIfNoWatcherExistsAsync();
4040

41-
Task Refresh_ClickAsync();
41+
Task Refresh_Click();
4242

4343
void Back_Click();
4444

0 commit comments

Comments
 (0)