App layout

This commit is contained in:
Matthew Parker
2023-08-31 23:38:32 +10:00
parent 701218a28b
commit fc55b195d6
11 changed files with 284 additions and 102 deletions

View File

@@ -1,21 +1,15 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Platform.Storage;
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using DotNetSolutionTools.App.Services;
using DotNetSolutionTools.Core;
namespace DotNetSolutionTools.App.ViewModels;
public partial class MainWindowViewModel : ViewModelBase
{
private readonly FileService _fileService = new();
[ObservableProperty]
private string _solutionFolderPath;
@@ -23,33 +17,57 @@ public partial class MainWindowViewModel : ViewModelBase
private string _solutionFilePath;
[ObservableProperty]
private string? _fileText;
private string _csprojFilePath;
[ObservableProperty]
private ObservableCollection<string> _parityResults = new ObservableCollection<string>()
{
"Test"
};
private ObservableCollection<string> _parityResults = new() { };
[RelayCommand]
private async Task ExecuteParityChecker(CancellationToken token)
{
var results =
DotNetSolutionTools.Core.SolutionParityChecker.CompareSolutionAndCSharpProjects(
SolutionFolderPath,
SolutionFilePath
);
var results = SolutionProjectParity.CompareSolutionAndCSharpProjects(
SolutionFolderPath,
SolutionFilePath
);
ParityResults.Clear();
foreach (var result in results)
{
ParityResults.Add(result);
}
}
[RelayCommand]
private async Task FormatCsProjFile(CancellationToken token)
{
FormatCsproj.FormatCsprojFile(SolutionFilePath);
FormatCsproj.FormatCsprojFile(CsprojFilePath);
}
[RelayCommand]
private async Task FormatAllCsprojFilesInSolutionFile(CancellationToken token)
{
var csprojList = SolutionProjectParity.RetrieveAllCSharpProjectFullPathsFromFolder(
SolutionFolderPath
);
foreach (var csproj in csprojList)
{
FormatCsproj.FormatCsprojFile(csproj);
}
}
[RelayCommand]
private async Task FormatAllCsprojFilesInSolutionFolder(CancellationToken token)
{
var csprojList = SolutionProjectParity.RetrieveAllCSharpProjectFullPathsFromFolder(
SolutionFolderPath
);
foreach (var csproj in csprojList)
{
FormatCsproj.FormatCsprojFile(csproj);
}
}
[RelayCommand]
private async Task CheckForMissingImplicitUsingsInSolutionFile(CancellationToken token)
{
ImplicitUsings.FindCSharpProjectsMissingImplicitUsings(SolutionFilePath);
}
[RelayCommand]
@@ -58,7 +76,7 @@ public partial class MainWindowViewModel : ViewModelBase
ErrorMessages?.Clear();
try
{
var file = await DoOpenFilePickerAsync();
var file = await _fileService.DoOpenFilePickerAsync();
if (file is null)
return;
@@ -70,13 +88,19 @@ public partial class MainWindowViewModel : ViewModelBase
}
}
[RelayCommand]
private async Task ClearSolutionFile(CancellationToken token)
{
SolutionFilePath = string.Empty;
}
[RelayCommand]
private async Task LoadSolutionFolder(CancellationToken token)
{
ErrorMessages?.Clear();
try
{
var folder = await DoOpenFolderPickerAsync();
var folder = await _fileService.DoOpenFolderPickerAsync();
if (folder is null)
return;
@@ -88,49 +112,33 @@ public partial class MainWindowViewModel : ViewModelBase
}
}
private async Task<IStorageFile?> DoOpenFilePickerAsync()
[RelayCommand]
private async Task ClearSolutionFolder(CancellationToken token)
{
// For learning purposes, we opted to directly get the reference
// for StorageProvider APIs here inside the ViewModel.
// For your real-world apps, you should follow the MVVM principles
// by making service classes and locating them with DI/IoC.
// See IoCFileOps project for an example of how to accomplish this.
if (
Application.Current?.ApplicationLifetime
is not IClassicDesktopStyleApplicationLifetime desktop
|| desktop.MainWindow?.StorageProvider is not { } provider
)
throw new NullReferenceException("Missing StorageProvider instance.");
var files = await provider.OpenFilePickerAsync(
new FilePickerOpenOptions() { Title = "Open Text File", AllowMultiple = false }
);
return files?.Count >= 1 ? files[0] : null;
SolutionFolderPath = string.Empty;
}
private async Task<IStorageFolder?> DoOpenFolderPickerAsync()
[RelayCommand]
private async Task LoadCsprojFile(CancellationToken token)
{
// For learning purposes, we opted to directly get the reference
// for StorageProvider APIs here inside the ViewModel.
ErrorMessages?.Clear();
try
{
var folder = await _fileService.DoOpenFilePickerAsync();
if (folder is null)
return;
// For your real-world apps, you should follow the MVVM principles
// by making service classes and locating them with DI/IoC.
CsprojFilePath = folder.Path.AbsolutePath;
}
catch (Exception e)
{
ErrorMessages?.Add(e.Message);
}
}
// See IoCFileOps project for an example of how to accomplish this.
if (
Application.Current?.ApplicationLifetime
is not IClassicDesktopStyleApplicationLifetime desktop
|| desktop.MainWindow?.StorageProvider is not { } provider
)
throw new NullReferenceException("Missing StorageProvider instance.");
var folder = await provider.OpenFolderPickerAsync(
new FolderPickerOpenOptions() { Title = "Open Text File", AllowMultiple = false }
);
return folder?.Count >= 1 ? folder[0] : null;
[RelayCommand]
private async Task ClearCsprojFile(CancellationToken token)
{
CsprojFilePath = string.Empty;
}
}

View File

@@ -0,0 +1,53 @@
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
namespace DotNetSolutionTools.App.ViewModels;
public partial class PreviewMainWindowViewModel : ViewModelBase
{
[ObservableProperty]
private string _solutionFolderPath =
"C:\\Users\\matt\\source\\repos\\DotNetSolutionTools\\DotNetSolutionTools.App";
[ObservableProperty]
private string _solutionFilePath =
"C:\\Users\\matt\\source\\repos\\DotNetSolutionTools\\DotNetSolutionTools.App.sln";
[ObservableProperty]
private string _csprojFilePath =
"C:\\Users\\matt\\source\\repos\\DotNetSolutionTools\\DotNetSolutionTools.App.csproj";
[ObservableProperty]
private ObservableCollection<string> _parityResults = new() { "Error Message" };
[RelayCommand]
private async Task ExecuteParityChecker(CancellationToken token)
{
throw new NotImplementedException();
}
[RelayCommand]
private async Task FormatCsProjFile(CancellationToken token)
{
throw new NotImplementedException();
}
[RelayCommand]
private async Task LoadSolutionFile(CancellationToken token)
{
throw new NotImplementedException();
}
[RelayCommand]
private async Task LoadSolutionFolder(CancellationToken token)
{
throw new NotImplementedException();
}
[RelayCommand]
private async Task LoadCsprojFile(CancellationToken token)
{
throw new NotImplementedException();
}
}