mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 10:01:27 -07:00
use snackbars for saving
This commit is contained in:
parent
4aee0a33f1
commit
ee377d9938
@ -71,5 +71,12 @@
|
||||
Command="{Binding Path=SaveCommand, Mode=OneTime}"
|
||||
Content="Save" />
|
||||
</Grid>
|
||||
|
||||
<ui:Snackbar
|
||||
x:Name="Snackbar"
|
||||
Grid.RowSpan="3"
|
||||
Margin="200,0,200,20"
|
||||
Panel.ZIndex="9"
|
||||
Timeout="3000" />
|
||||
</Grid>
|
||||
</base:WpfUiWindow>
|
||||
|
@ -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");
|
||||
|
@ -18,6 +18,8 @@ namespace Bloxstrap.UI.ViewModels.Editor
|
||||
public ICommand SaveCommand => new RelayCommand(Save);
|
||||
public ICommand OpenThemeFolderCommand => new RelayCommand(OpenThemeFolder);
|
||||
|
||||
public Action<bool, string> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user