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}"
|
Command="{Binding Path=SaveCommand, Mode=OneTime}"
|
||||||
Content="Save" />
|
Content="Save" />
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
<ui:Snackbar
|
||||||
|
x:Name="Snackbar"
|
||||||
|
Grid.RowSpan="3"
|
||||||
|
Margin="200,0,200,20"
|
||||||
|
Panel.ZIndex="9"
|
||||||
|
Timeout="3000" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</base:WpfUiWindow>
|
</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.
|
themeContents = ToCRLF(themeContents); // make sure the theme is in CRLF. a function expects CRLF.
|
||||||
|
|
||||||
var viewModel = new BootstrapperEditorWindowViewModel();
|
var viewModel = new BootstrapperEditorWindowViewModel();
|
||||||
|
viewModel.ThemeSavedCallback = ThemeSavedCallback;
|
||||||
viewModel.Directory = directory;
|
viewModel.Directory = directory;
|
||||||
viewModel.Name = name;
|
viewModel.Name = name;
|
||||||
viewModel.Title = $"Editing \"{name}\"";
|
viewModel.Title = $"Editing \"{name}\"";
|
||||||
@ -166,6 +167,14 @@ namespace Bloxstrap.UI.Elements.Editor
|
|||||||
UIXML.TextArea.TextView.SetResourceReference(ICSharpCode.AvalonEdit.Rendering.TextView.LinkTextForegroundBrushProperty, "NewTextEditorLink");
|
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)
|
private static string ToCRLF(string text)
|
||||||
{
|
{
|
||||||
return text.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\r\n");
|
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 SaveCommand => new RelayCommand(Save);
|
||||||
public ICommand OpenThemeFolderCommand => new RelayCommand(OpenThemeFolder);
|
public ICommand OpenThemeFolderCommand => new RelayCommand(OpenThemeFolder);
|
||||||
|
|
||||||
|
public Action<bool, string> ThemeSavedCallback { get; set; } = null!;
|
||||||
|
|
||||||
public string Directory { get; set; } = "";
|
public string Directory { get; set; } = "";
|
||||||
|
|
||||||
public string Name { get; set; } = "";
|
public string Name { get; set; } = "";
|
||||||
@ -34,8 +36,7 @@ namespace Bloxstrap.UI.ViewModels.Editor
|
|||||||
|
|
||||||
dialog.ApplyCustomTheme(Name, Code);
|
dialog.ApplyCustomTheme(Name, Code);
|
||||||
|
|
||||||
if (_dialog != null)
|
_dialog?.CloseBootstrapper();
|
||||||
_dialog.CloseBootstrapper();
|
|
||||||
_dialog = dialog;
|
_dialog = dialog;
|
||||||
|
|
||||||
dialog.Message = Strings.Bootstrapper_StylePreview_TextCancel;
|
dialog.Message = Strings.Bootstrapper_StylePreview_TextCancel;
|
||||||
@ -55,18 +56,20 @@ namespace Bloxstrap.UI.ViewModels.Editor
|
|||||||
{
|
{
|
||||||
const string LOG_IDENT = "BootstrapperEditorWindowViewModel::Save";
|
const string LOG_IDENT = "BootstrapperEditorWindowViewModel::Save";
|
||||||
|
|
||||||
string path = Path.Combine(Paths.CustomThemes, Name, "Theme.xml");
|
string path = Path.Combine(Directory, "Theme.xml");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File.WriteAllText(path, Code);
|
File.WriteAllText(path, Code);
|
||||||
|
ThemeSavedCallback.Invoke(true, "Your theme has been saved!");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
App.Logger.WriteLine(LOG_IDENT, "Failed to save custom theme");
|
App.Logger.WriteLine(LOG_IDENT, "Failed to save custom theme");
|
||||||
App.Logger.WriteException(LOG_IDENT, ex);
|
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