From ee377d993865857a34e1eb8251f085b3ece7819f Mon Sep 17 00:00:00 2001 From: bluepilledgreat <97983689+bluepilledgreat@users.noreply.github.com> Date: Thu, 23 Jan 2025 14:49:53 +0000 Subject: [PATCH] use snackbars for saving --- .../UI/Elements/Editor/BootstrapperEditorWindow.xaml | 7 +++++++ .../Elements/Editor/BootstrapperEditorWindow.xaml.cs | 9 +++++++++ .../Editor/BootstrapperEditorWindowViewModel.cs | 11 +++++++---- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Bloxstrap/UI/Elements/Editor/BootstrapperEditorWindow.xaml b/Bloxstrap/UI/Elements/Editor/BootstrapperEditorWindow.xaml index 274d1d58..93952ac7 100644 --- a/Bloxstrap/UI/Elements/Editor/BootstrapperEditorWindow.xaml +++ b/Bloxstrap/UI/Elements/Editor/BootstrapperEditorWindow.xaml @@ -71,5 +71,12 @@ Command="{Binding Path=SaveCommand, Mode=OneTime}" Content="Save" /> + + diff --git a/Bloxstrap/UI/Elements/Editor/BootstrapperEditorWindow.xaml.cs b/Bloxstrap/UI/Elements/Editor/BootstrapperEditorWindow.xaml.cs index 852310d3..38aab7ac 100644 --- a/Bloxstrap/UI/Elements/Editor/BootstrapperEditorWindow.xaml.cs +++ b/Bloxstrap/UI/Elements/Editor/BootstrapperEditorWindow.xaml.cs @@ -142,6 +142,7 @@ public BootstrapperEditorWindow(string name) themeContents = ToCRLF(themeContents); // make sure the theme is in CRLF. a function expects CRLF. var viewModel = new BootstrapperEditorWindowViewModel(); + viewModel.ThemeSavedCallback = ThemeSavedCallback; viewModel.Directory = directory; viewModel.Name = name; viewModel.Title = $"Editing \"{name}\""; @@ -166,6 +167,14 @@ private void LoadHighlightingTheme() UIXML.TextArea.TextView.SetResourceReference(ICSharpCode.AvalonEdit.Rendering.TextView.LinkTextForegroundBrushProperty, "NewTextEditorLink"); } + private void ThemeSavedCallback(bool success, string message) + { + if (success) + Snackbar.Show("Settings saved!", message, Wpf.Ui.Common.SymbolRegular.CheckmarkCircle32, Wpf.Ui.Common.ControlAppearance.Success); + else + Snackbar.Show("Error", message, Wpf.Ui.Common.SymbolRegular.ErrorCircle24, Wpf.Ui.Common.ControlAppearance.Danger); + } + private static string ToCRLF(string text) { return text.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\r\n"); diff --git a/Bloxstrap/UI/ViewModels/Editor/BootstrapperEditorWindowViewModel.cs b/Bloxstrap/UI/ViewModels/Editor/BootstrapperEditorWindowViewModel.cs index b3b99fe8..7fc60243 100644 --- a/Bloxstrap/UI/ViewModels/Editor/BootstrapperEditorWindowViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Editor/BootstrapperEditorWindowViewModel.cs @@ -18,6 +18,8 @@ public class BootstrapperEditorWindowViewModel : NotifyPropertyChangedViewModel public ICommand SaveCommand => new RelayCommand(Save); public ICommand OpenThemeFolderCommand => new RelayCommand(OpenThemeFolder); + public Action ThemeSavedCallback { get; set; } = null!; + public string Directory { get; set; } = ""; public string Name { get; set; } = ""; @@ -34,8 +36,7 @@ private void Preview() dialog.ApplyCustomTheme(Name, Code); - if (_dialog != null) - _dialog.CloseBootstrapper(); + _dialog?.CloseBootstrapper(); _dialog = dialog; dialog.Message = Strings.Bootstrapper_StylePreview_TextCancel; @@ -55,18 +56,20 @@ private void Save() { const string LOG_IDENT = "BootstrapperEditorWindowViewModel::Save"; - string path = Path.Combine(Paths.CustomThemes, Name, "Theme.xml"); + string path = Path.Combine(Directory, "Theme.xml"); try { File.WriteAllText(path, Code); + ThemeSavedCallback.Invoke(true, "Your theme has been saved!"); } catch (Exception ex) { App.Logger.WriteLine(LOG_IDENT, "Failed to save custom theme"); App.Logger.WriteException(LOG_IDENT, ex); - Frontend.ShowMessageBox($"Failed to save theme: {ex.Message}", MessageBoxImage.Error, MessageBoxButton.OK); + //Frontend.ShowMessageBox($"Failed to save theme: {ex.Message}", MessageBoxImage.Error, MessageBoxButton.OK); + ThemeSavedCallback.Invoke(false, ex.Message); } }