diff --git a/ColorKraken/CommandMixins.cs b/ColorKraken/CommandMixins.cs
new file mode 100644
index 0000000..842a216
--- /dev/null
+++ b/ColorKraken/CommandMixins.cs
@@ -0,0 +1,13 @@
+using System.Windows;
+
+using Microsoft.Toolkit.Mvvm.Input;
+
+namespace ColorKraken;
+
+public static class CommandMixins
+{
+ public static void RaiseCanExecuteChanged(this IRelayCommand command)
+ {
+ Application.Current.Dispatcher.Invoke(() => command.NotifyCanExecuteChanged());
+ }
+}
diff --git a/ColorKraken/MainWindow.xaml b/ColorKraken/MainWindow.xaml
index f310ebb..ef208f6 100644
--- a/ColorKraken/MainWindow.xaml
+++ b/ColorKraken/MainWindow.xaml
@@ -39,11 +39,13 @@
-
+
@@ -90,23 +92,35 @@
-
-
+
+
-
+
+
+
+
+
+
@@ -124,7 +138,7 @@
-
+
diff --git a/ColorKraken/MainWindowViewModel.cs b/ColorKraken/MainWindowViewModel.cs
index cdf3ed8..d7b7593 100644
--- a/ColorKraken/MainWindowViewModel.cs
+++ b/ColorKraken/MainWindowViewModel.cs
@@ -36,6 +36,8 @@ public class MainWindowViewModel : ObservableObject, IRecipient
public SnackbarMessageQueue MessageQueue { get; } = new();
public AsyncRelayCommand NewThemeCommand { get; }
+ public IRelayCommand DeleteCommand { get; }
+ public IRelayCommand RefreshCommand { get; }
public IRelayCommand OpenThemeFolderCommand { get; }
public ObservableCollection Themes { get; } = new();
@@ -59,6 +61,7 @@ public Theme? SelectedTheme
{
if (SetProperty(ref _selectedTheme, value))
{
+ DeleteCommand.RaiseCanExecuteChanged();
UndoStack.Clear();
Task.Run(async () =>
{
@@ -74,6 +77,8 @@ public MainWindowViewModel()
NewThemeCommand = new AsyncRelayCommand(NewTheme);
OpenThemeFolderCommand = new RelayCommand(OnOpenThemeFolder);
+ DeleteCommand = new RelayCommand(OnDelete, () => SelectedTheme != null && SelectedTheme.IsDefault == false);
+ RefreshCommand = new AsyncRelayCommand(OnRefresh);
BindingOperations.EnableCollectionSynchronization(Themes, new object());
@@ -342,6 +347,32 @@ private async void OnShowErrorDetails(string? details)
if (string.IsNullOrEmpty(details)) return;
await DialogHost.Show(new ErrorDetailsViewModel(details), "Root");
}
+
+ private void OnDelete()
+ {
+ //TODO: prompt
+ if (SelectedTheme is { } selectedTheme && selectedTheme.IsDefault == false)
+ {
+ try
+ {
+ File.Delete(selectedTheme.FilePath);
+ }
+ catch(Exception e)
+ {
+ ShowError($"Error deleting {Path.GetFileName(selectedTheme.FilePath)}", e.ToString());
+ return;
+ }
+ SelectedTheme = null;
+ Themes.Remove(selectedTheme);
+ }
+ }
+
+ public async Task OnRefresh()
+ {
+ SelectedTheme = null;
+ Themes.Clear();
+ await Task.Run(LoadThemes);
+ }
}
public record class ErrorDetailsViewModel(string Details) { }