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