mirror of
https://github.com/rmcrackan/Libation.git
synced 2026-03-25 18:31:23 -04:00
Make fields readonly Remove unnecessary casts Format document Remove unnecessary usings Sort usings Use file-level namespaces Order modifiers
59 lines
1.5 KiB
C#
59 lines
1.5 KiB
C#
using Avalonia.Controls;
|
|
using FileManager;
|
|
using LibationAvalonia.ViewModels.Settings;
|
|
using LibationFileManager;
|
|
using LibationUiBase.Forms;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace LibationAvalonia.Dialogs;
|
|
|
|
public partial class SettingsDialog : DialogWindow
|
|
{
|
|
private readonly SettingsVM settingsDisp;
|
|
|
|
private readonly Configuration config = Design.IsDesignMode ? Configuration.CreateMockInstance() : Configuration.Instance;
|
|
public SettingsDialog()
|
|
{
|
|
InitializeComponent();
|
|
|
|
DataContext = settingsDisp = new(config);
|
|
}
|
|
|
|
protected override async Task SaveAndCloseAsync()
|
|
{
|
|
#region validation
|
|
|
|
if (string.IsNullOrWhiteSpace(settingsDisp.ImportantSettings.BooksDirectory))
|
|
{
|
|
await MessageBox.Show(this.GetParentWindow(), "Cannot set Books Location to blank", "Location is blank", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
|
|
#endregion
|
|
|
|
settingsDisp.SaveSettings(config);
|
|
|
|
await MessageBox.VerboseLoggingWarning_ShowIfTrue();
|
|
await base.SaveAndCloseAsync();
|
|
}
|
|
|
|
public async void SaveButton_Clicked(object sender, Avalonia.Interactivity.RoutedEventArgs e)
|
|
{
|
|
LongPath lonNewBooks = settingsDisp.ImportantSettings.GetBooksDirectory();
|
|
if (!System.IO.Directory.Exists(lonNewBooks))
|
|
{
|
|
try
|
|
{
|
|
System.IO.Directory.CreateDirectory(lonNewBooks);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await MessageBox.Show(this, $"Error creating Books Location:\n\n{ex.Message}", "Error creating directory", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
}
|
|
await SaveAndCloseAsync();
|
|
}
|
|
}
|