Skip to content

Commit

Permalink
Code Quality: Introduced ICommonDialogService (#15386)
Browse files Browse the repository at this point in the history
Co-authored-by: Yair <[email protected]>
  • Loading branch information
0x5bfa and yaira2 authored May 17, 2024
1 parent 9b4aec7 commit b5a7eac
Show file tree
Hide file tree
Showing 17 changed files with 442 additions and 309 deletions.
48 changes: 48 additions & 0 deletions src/Files.App/Data/Contracts/ICommonDialogService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

namespace Files.App.Data.Contracts
{
/// <summary>
/// Provides service to launch common dialog through Win32API.
/// </summary>
public interface ICommonDialogService
{
/// <summary>
/// Opens a common dialog called FileOpenDialog through native Win32API.
/// </summary>
/// <param name="hWnd">The Window handle that the dialog launches based on.</param>
/// <param name="pickFoldersOnly">The value that indicates whether the picker is only for folders.</param>
/// <param name="filters">The extension filters that the dialog uses to exclude unnecessary files.<br/>The filter must have a pair:<code>[ "Application", ".exe" ]</code></param>
/// <param name="filePath">The file that that user chose.</param>
/// <remarks>
/// NOTE: There's a WinRT API to launch this dialog, but the API doesn't support windows that are launched by those who is in Administrators group or has broader privileges.
/// </remarks>
/// <returns>True if the 'Open' button was clicked; otherwise, false.</returns>
bool Open_FileOpenDialog(nint hWnd, bool pickFoldersOnly, string[] filters, Environment.SpecialFolder defaultFolder, out string filePath);

/// <summary>
/// Opens a common dialog called FileSaveDialog through native Win32API.
/// </summary>
/// <param name="hWnd">The Window handle that the dialog launches based on.</param>
/// <param name="pickFoldersOnly">The value that indicates whether the picker is only for folders.</param>
/// <param name="filters">The extension filters that the dialog uses to exclude unnecessary files.<br/>The filter must have a pair:<code>[ "Application", ".exe" ]</code></param>
/// <param name="filePath">The file that that user chose.</param>
/// <remarks>
/// NOTE: There's a WinRT API to launch this dialog, but the API doesn't support windows that are launched by those who is in Administrators group or has broader privileges.
/// </remarks>
/// <returns>True if the 'Open' button was clicked; otherwise, false.</returns>
bool Open_FileSaveDialog(nint hWnd, bool pickFoldersOnly, string[] filters, Environment.SpecialFolder defaultFolder, out string filePath);

/// <summary>
/// Opens a common dialog called NetworkConnectionDialog through native Win32API.
/// </summary>
/// <param name="hideRestoreConnectionCheckBox">The value indicating whether to hide the check box allowing the user to restore the connection at logon.</param>
/// <param name="persistConnectionAtLogon">The value indicating whether restore the connection at logon.</param>
/// <param name="readOnlyPath">The value indicating whether to display a read-only path instead of allowing the user to type in a path. This is only valid if <see cref="RemoteNetworkName"/> is not <see langword="null"/>.</param>
/// <param name="remoteNetworkName">The name of the remote network.</param>
/// <param name="useMostRecentPath">The value indicating whether to enter the most recently used paths into the combination box.</param>
/// <returns>True if the 'OK' button was clicked; otherwise, false.</returns>
bool Open_NetworkConnectionDialog(nint hWind, bool hideRestoreConnectionCheckBox = false, bool persistConnectionAtLogon = false, bool readOnlyPath = false, string? remoteNetworkName = null, bool useMostRecentPath = false);
}
}
15 changes: 0 additions & 15 deletions src/Files.App/Data/Contracts/IFileExplorerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,5 @@ public interface IFileExplorerService
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that cancels this action.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
Task OpenInFileExplorerAsync(ILocatableFolder folder, CancellationToken cancellationToken = default);

/// <summary>
/// Awaits the user input and picks single file from the file explorer dialog.
/// </summary>
/// <param name="filter">The filter to apply when picking files.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that cancels this action.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous operation. If successful and a file has been picked, returns <see cref="ILocatableFile"/>, otherwise null.</returns>
Task<ILocatableFile?> PickSingleFileAsync(IEnumerable<string>? filter, CancellationToken cancellationToken = default);

/// <summary>
/// Awaits the user input and picks single folder from the file explorer dialog.
/// </summary>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that cancels this action.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous operation. If successful and a folder has been picked, returns <see cref="ILocatableFolder"/>, otherwise null.</returns>
Task<ILocatableFolder?> PickSingleFolderAsync(CancellationToken cancellationToken = default);
}
}
118 changes: 0 additions & 118 deletions src/Files.App/Data/Models/NetworkConnectionDialog.cs

This file was deleted.

1 change: 1 addition & 0 deletions src/Files.App/Helpers/Application/AppLifecycleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public static IHost ConfigureHost()
// Services
.AddSingleton<IAppThemeModeService, AppThemeModeService>()
.AddSingleton<IDialogService, DialogService>()
.AddSingleton<ICommonDialogService, CommonDialogService>()
.AddSingleton<IImageService, ImagingService>()
.AddSingleton<IThreadingService, ThreadingService>()
.AddSingleton<ILocalizationService, LocalizationService>()
Expand Down
8 changes: 7 additions & 1 deletion src/Files.App/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,17 @@ DeleteFileFromApp
RemoveDirectoryFromApp
GetKeyState
CreateDirectoryFromApp
CoCreateInstance
FileOpenDialog
IFileOpenDialog
SHCreateItemFromParsingName
FileSaveDialog
IFileSaveDialog
D3D_DRIVER_TYPE
D3D_FEATURE_LEVEL
ID3D11Device
ID3D11DeviceContext
D3D11CreateDevice
IDXGIDevice
DCompositionCreateDevice
IDCompositionDevice
IDCompositionDevice
Loading

0 comments on commit b5a7eac

Please sign in to comment.