Add color status bar
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.Json;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Media.Immutable;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using DotNetSolutionTools.App.Models;
|
||||
@@ -28,14 +30,41 @@ public partial class MainWindowViewModel : ObservableObject
|
||||
[ObservableProperty]
|
||||
private string _resultsLabel = "Ready";
|
||||
|
||||
[ObservableProperty]
|
||||
private IImmutableSolidColorBrush _resultsLabelColor = new ImmutableSolidColorBrush(Colors.Black);
|
||||
|
||||
public MainWindowViewModel()
|
||||
{
|
||||
LoadSavedState().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private void SetBeginCommandState()
|
||||
{
|
||||
OperationResults.Clear();
|
||||
ResultsLabel = "Running...";
|
||||
ResultsLabelColor = new ImmutableSolidColorBrush(Colors.Black);
|
||||
}
|
||||
|
||||
private void SetCommandSuccessState(string message)
|
||||
{
|
||||
ResultsLabel = message;
|
||||
ResultsLabelColor = new ImmutableSolidColorBrush(Colors.Green);
|
||||
}
|
||||
|
||||
private void SetCommandFailureState(string message, Exception e)
|
||||
{
|
||||
ResultsLabel = message;
|
||||
ResultsLabelColor = new ImmutableSolidColorBrush(Colors.DarkRed);
|
||||
OperationResults?.Add(e.Message);
|
||||
OperationResults?.Add(e.ToString());
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task ExecuteParityChecker(CancellationToken token)
|
||||
{
|
||||
OperationResults.Clear();
|
||||
ResultsLabel = string.Empty;
|
||||
SetBeginCommandState();
|
||||
try
|
||||
{
|
||||
ResultsLabel = "Running...";
|
||||
await Task.Run(
|
||||
() =>
|
||||
{
|
||||
@@ -45,27 +74,23 @@ public partial class MainWindowViewModel : ObservableObject
|
||||
);
|
||||
foreach (var result in results)
|
||||
OperationResults.Add(result);
|
||||
ResultsLabel = $"{results.Count} Projects in folder missing from solution";
|
||||
SetCommandSuccessState($"{results.Count} Projects in folder missing from solution");
|
||||
},
|
||||
token
|
||||
);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ResultsLabel = "Failed to compare solution and csharp projects";
|
||||
OperationResults?.Add(e.Message);
|
||||
OperationResults?.Add(e.ToString());
|
||||
SetCommandFailureState("Failed to compare solution and csharp projects", e);
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task FormatCsProjFile(CancellationToken token)
|
||||
{
|
||||
OperationResults.Clear();
|
||||
ResultsLabel = string.Empty;
|
||||
SetBeginCommandState();
|
||||
try
|
||||
{
|
||||
ResultsLabel = "Running...";
|
||||
await Task.Run(
|
||||
() =>
|
||||
{
|
||||
@@ -73,24 +98,20 @@ public partial class MainWindowViewModel : ObservableObject
|
||||
},
|
||||
token
|
||||
);
|
||||
ResultsLabel = "Successfully formatted csproj file";
|
||||
SetCommandSuccessState("Successfully formatted csproj file");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ResultsLabel = "Failed to format csproj file";
|
||||
OperationResults?.Add(e.Message);
|
||||
OperationResults?.Add(e.ToString());
|
||||
SetCommandFailureState("Failed to format csproj file", e);
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task FormatAllCsprojFilesInSolutionFile(CancellationToken token)
|
||||
{
|
||||
OperationResults.Clear();
|
||||
ResultsLabel = string.Empty;
|
||||
SetBeginCommandState();
|
||||
try
|
||||
{
|
||||
ResultsLabel = "Running...";
|
||||
await Task.Run(
|
||||
() =>
|
||||
{
|
||||
@@ -103,23 +124,20 @@ public partial class MainWindowViewModel : ObservableObject
|
||||
},
|
||||
token
|
||||
);
|
||||
ResultsLabel = "Successfully formatted all csproj files in solution file";
|
||||
SetCommandSuccessState("Successfully formatted all csproj files in solution file");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ResultsLabel = "Failed to format all csproj files in solution file";
|
||||
OperationResults?.Add(e.Message);
|
||||
OperationResults?.Add(e.ToString());
|
||||
SetCommandFailureState("Failed to format all csproj files in solution file", e);
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task FormatAllCsprojFilesInSolutionFolder(CancellationToken token)
|
||||
{
|
||||
OperationResults.Clear();
|
||||
SetBeginCommandState();
|
||||
try
|
||||
{
|
||||
ResultsLabel = "Running...";
|
||||
await Task.Run(
|
||||
() =>
|
||||
{
|
||||
@@ -131,76 +149,64 @@ public partial class MainWindowViewModel : ObservableObject
|
||||
},
|
||||
token
|
||||
);
|
||||
ResultsLabel = "Successfully formatted all csproj files in folder";
|
||||
SetCommandSuccessState("Successfully formatted all csproj files in folder");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ResultsLabel = "Failed to format all csproj files in solution folder";
|
||||
OperationResults?.Add(e.Message);
|
||||
OperationResults?.Add(e.ToString());
|
||||
SetCommandFailureState("Failed to format all csproj files in folder", e);
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task CheckForMissingImplicitUsingsInSolutionFile(CancellationToken token)
|
||||
{
|
||||
OperationResults.Clear();
|
||||
ResultsLabel = string.Empty;
|
||||
SetBeginCommandState();
|
||||
try
|
||||
{
|
||||
ResultsLabel = "Running...";
|
||||
await Task.Run(
|
||||
() =>
|
||||
{
|
||||
var results = ImplicitUsings.FindCSharpProjectsMissingImplicitUsings(SolutionFilePath);
|
||||
results.ForEach(s => OperationResults.Add(s));
|
||||
ResultsLabel = $"{results.Count} Projects missing ImplicitUsings";
|
||||
SetCommandSuccessState($"{results.Count} Projects missing ImplicitUsings");
|
||||
},
|
||||
token
|
||||
);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ResultsLabel = "Failed to check for missing implicit usings in solution file";
|
||||
OperationResults?.Add(e.Message);
|
||||
OperationResults?.Add(e.ToString());
|
||||
SetCommandFailureState("Failed to check for missing implicit usings in solution file", e);
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task CheckForMissingTreatWarningsAsErrorsInSolutionFile(CancellationToken token)
|
||||
{
|
||||
OperationResults.Clear();
|
||||
ResultsLabel = string.Empty;
|
||||
SetBeginCommandState();
|
||||
try
|
||||
{
|
||||
ResultsLabel = "Running...";
|
||||
await Task.Run(
|
||||
() =>
|
||||
{
|
||||
var results = WarningsAsErrors.FindCSharpProjectsMissingTreatWarningsAsErrors(SolutionFilePath);
|
||||
results.ForEach(s => OperationResults.Add(s));
|
||||
ResultsLabel = $"{results.Count} Projects missing TreatWarningsAsErrors";
|
||||
SetCommandSuccessState($"{results.Count} Projects missing TreatWarningsAsErrors");
|
||||
},
|
||||
token
|
||||
);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ResultsLabel = "Error";
|
||||
OperationResults?.Add(e.Message);
|
||||
OperationResults?.Add(e.ToString());
|
||||
SetCommandFailureState("Failed to check for missing treat warnings as errors in solution file", e);
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task DeleteBinAndObjFoldersInFolder(CancellationToken token)
|
||||
{
|
||||
OperationResults.Clear();
|
||||
ResultsLabel = string.Empty;
|
||||
SetBeginCommandState();
|
||||
try
|
||||
{
|
||||
ResultsLabel = "Running...";
|
||||
await Task.Run(
|
||||
() =>
|
||||
{
|
||||
@@ -208,24 +214,20 @@ public partial class MainWindowViewModel : ObservableObject
|
||||
},
|
||||
token
|
||||
);
|
||||
ResultsLabel = "Successfully deleted bin and obj folders";
|
||||
SetCommandSuccessState("Successfully deleted bin and obj folders");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ResultsLabel = "Failed to delete bin and obj folders";
|
||||
OperationResults?.Add(e.Message);
|
||||
OperationResults?.Add(e.ToString());
|
||||
SetCommandFailureState("Failed to delete bin and obj folders", e);
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task UpdateAllProjectsToNet80(CancellationToken token)
|
||||
{
|
||||
OperationResults.Clear();
|
||||
ResultsLabel = string.Empty;
|
||||
SetBeginCommandState();
|
||||
try
|
||||
{
|
||||
ResultsLabel = "Running...";
|
||||
await Task.Run(
|
||||
async () =>
|
||||
{
|
||||
@@ -233,24 +235,20 @@ public partial class MainWindowViewModel : ObservableObject
|
||||
},
|
||||
token
|
||||
);
|
||||
ResultsLabel = "Successfully updated all projects in solution to .NET 8";
|
||||
SetCommandSuccessState("Successfully updated all projects in solution to .NET 8");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ResultsLabel = "Failed to update all projects in solution to .NET 8";
|
||||
OperationResults?.Add(e.Message);
|
||||
OperationResults?.Add(e.ToString());
|
||||
SetCommandFailureState("Failed to update all projects in solution to .NET 8", e);
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task UpdateProjectToNet80(CancellationToken token)
|
||||
{
|
||||
OperationResults.Clear();
|
||||
ResultsLabel = string.Empty;
|
||||
SetBeginCommandState();
|
||||
try
|
||||
{
|
||||
ResultsLabel = "Running...";
|
||||
await Task.Run(
|
||||
async () =>
|
||||
{
|
||||
@@ -258,12 +256,11 @@ public partial class MainWindowViewModel : ObservableObject
|
||||
},
|
||||
token
|
||||
);
|
||||
ResultsLabel = "Successfully updated project to .NET 8";
|
||||
SetCommandSuccessState("Successfully updated project to .NET 8");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ResultsLabel = "Failed to update project to .NET 8";
|
||||
OperationResults?.Add(e.Message);
|
||||
SetCommandFailureState("Failed to update project to .NET 8", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -376,9 +373,4 @@ public partial class MainWindowViewModel : ObservableObject
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
|
||||
public MainWindowViewModel()
|
||||
{
|
||||
LoadSavedState().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user