mirror of
https://github.com/rmcrackan/Libation.git
synced 2026-05-12 01:31:33 -04:00
- Added `MockLibraryBook` which contains factories for easily creating mock LibraryBooks and Books
- Added mock Configuration
- New `IPersistentDictionary` interface
- New `MockPersistentDictionary` class which uses a `JObject` as its data store
- Added `public static Configuration CreateMockInstance()`
- This method returns a mock Configuration instance **and also sets the `Configuration.Instance` property**
- Throws an exception if not in debug
- Updated all chardonnay controls to use the mocks in design mode. Previously I was using my actual database and settings file, but that approach is fragile and is unfriendly towards anyone else trying to work on it.
60 lines
1.6 KiB
C#
60 lines
1.6 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 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();
|
|
}
|
|
}
|
|
}
|