diff --git a/Bloxstrap/UI/Elements/Editor/BootstrapperEditorWindow.xaml b/Bloxstrap/UI/Elements/Editor/BootstrapperEditorWindow.xaml index 274d1d5..93952ac 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 852310d..38aab7a 100644 --- a/Bloxstrap/UI/Elements/Editor/BootstrapperEditorWindow.xaml.cs +++ b/Bloxstrap/UI/Elements/Editor/BootstrapperEditorWindow.xaml.cs @@ -142,6 +142,7 @@ namespace Bloxstrap.UI.Elements.Editor 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 @@ namespace Bloxstrap.UI.Elements.Editor 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 b3b99fe..7fc6024 100644 --- a/Bloxstrap/UI/ViewModels/Editor/BootstrapperEditorWindowViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Editor/BootstrapperEditorWindowViewModel.cs @@ -18,6 +18,8 @@ namespace Bloxstrap.UI.ViewModels.Editor 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 @@ namespace Bloxstrap.UI.ViewModels.Editor dialog.ApplyCustomTheme(Name, Code); - if (_dialog != null) - _dialog.CloseBootstrapper(); + _dialog?.CloseBootstrapper(); _dialog = dialog; dialog.Message = Strings.Bootstrapper_StylePreview_TextCancel; @@ -55,18 +56,20 @@ namespace Bloxstrap.UI.ViewModels.Editor { 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); } }