Skip to content
Open
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
41 changes: 27 additions & 14 deletions src/Files.App/Helpers/Navigation/NavigationHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ public static Task LaunchNewWindowAsync()
public static async Task OpenSelectedItemsAsync(IShellPage associatedInstance, bool openViaApplicationPicker = false)
{
// Don't open files and folders inside recycle bin
if (associatedInstance.ShellViewModel.WorkingDirectory.StartsWith(Constants.UserEnvironmentPaths.RecycleBinPath, StringComparison.Ordinal) ||
if (associatedInstance.ShellViewModel is null ||
associatedInstance.ShellViewModel.WorkingDirectory.StartsWith(Constants.UserEnvironmentPaths.RecycleBinPath, StringComparison.Ordinal) ||
associatedInstance.SlimContentPage?.SelectedItems is null)
{
return;
Expand Down Expand Up @@ -378,7 +379,8 @@ public static async Task OpenSelectedItemsAsync(IShellPage associatedInstance, b
public static async Task OpenItemsWithExecutableAsync(IShellPage associatedInstance, IEnumerable<IStorageItemWithPath> items, string executablePath)
{
// Don't open files and folders inside recycle bin
if (associatedInstance.ShellViewModel.WorkingDirectory.StartsWith(Constants.UserEnvironmentPaths.RecycleBinPath, StringComparison.Ordinal) ||
if (associatedInstance.ShellViewModel is null ||
associatedInstance.ShellViewModel.WorkingDirectory.StartsWith(Constants.UserEnvironmentPaths.RecycleBinPath, StringComparison.Ordinal) ||
associatedInstance.SlimContentPage is null)
return;

Expand All @@ -398,6 +400,9 @@ public static async Task OpenItemsWithExecutableAsync(IShellPage associatedInsta
/// <param name="forceOpenInNewTab">Open folders in a new tab regardless of the "OpenFoldersInNewTab" option</param>
public static async Task<bool> OpenPath(string path, IShellPage associatedInstance, FilesystemItemType? itemType = null, bool openSilent = false, bool openViaApplicationPicker = false, IEnumerable<string>? selectItems = null, string? args = default, bool forceOpenInNewTab = false)
{
if (associatedInstance.ShellViewModel is null)
return false;

string previousDir = associatedInstance.ShellViewModel.WorkingDirectory;
bool isHiddenItem = Win32Helper.HasFileAttribute(path, System.IO.FileAttributes.Hidden);
bool isDirectory = Win32Helper.HasFileAttribute(path, System.IO.FileAttributes.Directory);
Expand Down Expand Up @@ -550,13 +555,16 @@ private static async Task<FilesystemResult> OpenDirectory(string path, IShellPag
}
else
{
opened = await associatedInstance.ShellViewModel.GetFolderWithPathFromPathAsync(path)
.OnSuccess((childFolder) =>
{
// Add location to Recent Items List
if (childFolder.Item is SystemStorageFolder)
WindowsRecentItemsService.Add(childFolder.Path);
});
if (associatedInstance.ShellViewModel is not null)
{
opened = await associatedInstance.ShellViewModel.GetFolderWithPathFromPathAsync(path)
.OnSuccess((childFolder) =>
{
// Add location to Recent Items List
if (childFolder.Item is SystemStorageFolder)
WindowsRecentItemsService.Add(childFolder.Path);
});
}
if (!opened)
opened = (FilesystemResult)FolderHelpers.CheckFolderAccessWithWin32(path);

Expand All @@ -582,7 +590,7 @@ private static async Task<FilesystemResult> OpenFile(string path, IShellPage ass
}
else
{
if (!FileExtensionHelpers.IsWebLinkFile(path))
if (!FileExtensionHelpers.IsWebLinkFile(path) && associatedInstance.ShellViewModel is not null)
{
StorageFileWithPath childFile = await associatedInstance.ShellViewModel.GetFileWithPathFromPathAsync(shortcutInfo.TargetPath);
// Add location to Recent Items List
Expand All @@ -599,9 +607,11 @@ private static async Task<FilesystemResult> OpenFile(string path, IShellPage ass
}
else
{
opened = await associatedInstance.ShellViewModel.GetFileWithPathFromPathAsync(path)
.OnSuccess(async childFile =>
{
if (associatedInstance.ShellViewModel is not null)
{
opened = await associatedInstance.ShellViewModel.GetFileWithPathFromPathAsync(path)
.OnSuccess(async childFile =>
{
// Add location to Recent Items List
if (childFile.Item is SystemStorageFile)
WindowsRecentItemsService.Add(childFile.Path);
Expand All @@ -627,7 +637,9 @@ private static async Task<FilesystemResult> OpenFile(string path, IShellPage ass
bool launchSuccess = false;
BaseStorageFileQueryResult? fileQueryResult = null;
//Get folder to create a file query (to pass to apps like Photos, Movies & TV..., needed to scroll through the folder like what Windows Explorer does)
BaseStorageFolder currentFolder = await associatedInstance.ShellViewModel.GetFolderFromPathAsync(PathNormalization.GetParentDir(path));
BaseStorageFolder? currentFolder = associatedInstance.ShellViewModel is not null
? await associatedInstance.ShellViewModel.GetFolderFromPathAsync(PathNormalization.GetParentDir(path))
: null;
if (currentFolder is not null)
{
QueryOptions queryOptions = new(CommonFileQuery.DefaultQuery, null);
Expand Down Expand Up @@ -692,6 +704,7 @@ private static async Task<FilesystemResult> OpenFile(string path, IShellPage ass
}
}
});
}
}
return opened;
}
Expand Down