mirror of
https://github.com/rmcrackan/Libation.git
synced 2026-05-18 05:30:43 -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.
64 lines
2.3 KiB
C#
64 lines
2.3 KiB
C#
using Avalonia.Controls;
|
|
using LibationAvalonia.Dialogs;
|
|
using LibationAvalonia.ViewModels.Settings;
|
|
using LibationFileManager;
|
|
using LibationFileManager.Templates;
|
|
using LibationUiBase.Forms;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace LibationAvalonia.Controls.Settings
|
|
{
|
|
public partial class DownloadDecrypt : UserControl
|
|
{
|
|
private DownloadDecryptSettingsVM _viewModel => DataContext as DownloadDecryptSettingsVM;
|
|
public DownloadDecrypt()
|
|
{
|
|
InitializeComponent();
|
|
if (Design.IsDesignMode)
|
|
{
|
|
DataContext = new DownloadDecryptSettingsVM(Configuration.CreateMockInstance());
|
|
}
|
|
}
|
|
|
|
public async void EditFolderTemplateButton_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
|
|
{
|
|
if (_viewModel is null) return;
|
|
var newTemplate = await editTemplate(TemplateEditor<Templates.FolderTemplate>.CreateFilenameEditor(_viewModel.Config.Books, _viewModel.FolderTemplate));
|
|
if (newTemplate is not null)
|
|
_viewModel.FolderTemplate = newTemplate;
|
|
}
|
|
|
|
public async void EditFileTemplateButton_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
|
|
{
|
|
if (_viewModel is null) return;
|
|
var newTemplate = await editTemplate(TemplateEditor<Templates.FileTemplate>.CreateFilenameEditor(_viewModel.Config.Books, _viewModel.FileTemplate));
|
|
if (newTemplate is not null)
|
|
_viewModel.FileTemplate = newTemplate;
|
|
}
|
|
|
|
public async void EditChapterFileTemplateButton_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
|
|
{
|
|
if (_viewModel is null) return;
|
|
var newTemplate = await editTemplate(TemplateEditor<Templates.ChapterFileTemplate>.CreateFilenameEditor(_viewModel.Config.Books, _viewModel.ChapterFileTemplate));
|
|
if (newTemplate is not null)
|
|
_viewModel.ChapterFileTemplate = newTemplate;
|
|
}
|
|
|
|
public async void EditCharReplacementButton_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
|
|
{
|
|
if (_viewModel is null) return;
|
|
var form = new EditReplacementChars(_viewModel.Config);
|
|
await form.ShowDialog<DialogResult>(this.GetParentWindow());
|
|
}
|
|
|
|
|
|
private async Task<string> editTemplate(ITemplateEditor template)
|
|
{
|
|
var form = new EditTemplateDialog(template);
|
|
if (await form.ShowDialog<DialogResult>(this.GetParentWindow()) == DialogResult.OK)
|
|
return template.EditingTemplate.TemplateText;
|
|
else return null;
|
|
}
|
|
}
|
|
}
|