File filters
This commit is contained in:
@@ -6,7 +6,26 @@ namespace DotNetSolutionTools.App.Services;
|
|||||||
|
|
||||||
public class FileService
|
public class FileService
|
||||||
{
|
{
|
||||||
public async Task<IStorageFile?> DoOpenFilePickerAsync()
|
private readonly FilePickerFileType _csprojFileType = new("C# Project File")
|
||||||
|
{
|
||||||
|
Patterns = new[] { "*.csproj" }
|
||||||
|
};
|
||||||
|
private readonly FilePickerFileType _slnFileType = new("C# Solution File")
|
||||||
|
{
|
||||||
|
Patterns = new[] { "*.sln" }
|
||||||
|
};
|
||||||
|
|
||||||
|
public async Task<IStorageFile?> DoOpenFilePickerCsprojAsync()
|
||||||
|
{
|
||||||
|
return await DoOpenFilePickerAsync(_csprojFileType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IStorageFile?> DoOpenFilePickerSlnAsync()
|
||||||
|
{
|
||||||
|
return await DoOpenFilePickerAsync(_slnFileType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IStorageFile?> DoOpenFilePickerAsync(FilePickerFileType fileType)
|
||||||
{
|
{
|
||||||
if (
|
if (
|
||||||
Application.Current?.ApplicationLifetime
|
Application.Current?.ApplicationLifetime
|
||||||
@@ -16,7 +35,7 @@ public class FileService
|
|||||||
throw new NullReferenceException("Missing StorageProvider instance.");
|
throw new NullReferenceException("Missing StorageProvider instance.");
|
||||||
|
|
||||||
var files = await provider.OpenFilePickerAsync(
|
var files = await provider.OpenFilePickerAsync(
|
||||||
new FilePickerOpenOptions() { Title = "Open Text File", AllowMultiple = false }
|
new FilePickerOpenOptions() { Title = "Open File", AllowMultiple = false, FileTypeFilter = [fileType] }
|
||||||
);
|
);
|
||||||
|
|
||||||
return files?.Count >= 1 ? files[0] : null;
|
return files?.Count >= 1 ? files[0] : null;
|
||||||
@@ -32,7 +51,7 @@ public class FileService
|
|||||||
throw new NullReferenceException("Missing StorageProvider instance.");
|
throw new NullReferenceException("Missing StorageProvider instance.");
|
||||||
|
|
||||||
var folder = await provider.OpenFolderPickerAsync(
|
var folder = await provider.OpenFolderPickerAsync(
|
||||||
new FolderPickerOpenOptions() { Title = "Open Text File", AllowMultiple = false }
|
new FolderPickerOpenOptions() { Title = "Select Folder", AllowMultiple = false }
|
||||||
);
|
);
|
||||||
|
|
||||||
return folder?.Count >= 1 ? folder[0] : null;
|
return folder?.Count >= 1 ? folder[0] : null;
|
||||||
|
|||||||
@@ -243,7 +243,7 @@ public partial class MainWindowViewModel : ViewModelBase
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var file = await _fileService.DoOpenFilePickerAsync();
|
var file = await _fileService.DoOpenFilePickerSlnAsync();
|
||||||
if (file is null)
|
if (file is null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -295,7 +295,7 @@ public partial class MainWindowViewModel : ViewModelBase
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var folder = await _fileService.DoOpenFilePickerAsync();
|
var folder = await _fileService.DoOpenFilePickerCsprojAsync();
|
||||||
if (folder is null)
|
if (folder is null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user