diff --git a/Source/LibationWinForms/AvaloniaUI/Assets/MBIcons/Asterisk.png b/Source/LibationWinForms/AvaloniaUI/Assets/MBIcons/Asterisk.png new file mode 100644 index 00000000..c345a8f9 Binary files /dev/null and b/Source/LibationWinForms/AvaloniaUI/Assets/MBIcons/Asterisk.png differ diff --git a/Source/LibationWinForms/AvaloniaUI/Assets/MBIcons/Exclamation.png b/Source/LibationWinForms/AvaloniaUI/Assets/MBIcons/Exclamation.png new file mode 100644 index 00000000..cc884984 Binary files /dev/null and b/Source/LibationWinForms/AvaloniaUI/Assets/MBIcons/Exclamation.png differ diff --git a/Source/LibationWinForms/AvaloniaUI/Assets/MBIcons/Question.png b/Source/LibationWinForms/AvaloniaUI/Assets/MBIcons/Question.png new file mode 100644 index 00000000..3aeb017c Binary files /dev/null and b/Source/LibationWinForms/AvaloniaUI/Assets/MBIcons/Question.png differ diff --git a/Source/LibationWinForms/AvaloniaUI/Assets/MBIcons/error.png b/Source/LibationWinForms/AvaloniaUI/Assets/MBIcons/error.png new file mode 100644 index 00000000..916e14f1 Binary files /dev/null and b/Source/LibationWinForms/AvaloniaUI/Assets/MBIcons/error.png differ diff --git a/Source/LibationWinForms/AvaloniaUI/ViewModels/Dialogs/MessageBoxViewModel.cs b/Source/LibationWinForms/AvaloniaUI/ViewModels/Dialogs/MessageBoxViewModel.cs new file mode 100644 index 00000000..51e0fab2 --- /dev/null +++ b/Source/LibationWinForms/AvaloniaUI/ViewModels/Dialogs/MessageBoxViewModel.cs @@ -0,0 +1,77 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Media; +using LibationWinForms.AvaloniaUI.Views.Dialogs; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LibationWinForms.AvaloniaUI.ViewModels.Dialogs +{ + public class MessageBoxViewModel + { + private string _message; + public string Message { get { return _message; } set { _message = value; } } + public string Caption { get; } = "Message Box"; + private MessageBoxButtons _button; + private MessageBoxIcon _icon; + private MessageBoxDefaultButton _defaultButton; + + public MessageBoxButtons Buttons => _button; + + public bool IsAsterisk => _icon == MessageBoxIcon.Asterisk; + public bool IsError => _icon == MessageBoxIcon.Error; + public bool IsQuestion => _icon == MessageBoxIcon.Question; + public bool IsExclamation => _icon == MessageBoxIcon.Exclamation; + + public bool HasButton3 => !string.IsNullOrEmpty(Button3Text); + public bool HasButton2 => !string.IsNullOrEmpty(Button2Text); + + public int WindowHeight { get;private set; } + public int WindowWidth { get;private set; } + + public string Button1Text => _button switch + { + MessageBoxButtons.OK => "OK", + MessageBoxButtons.OKCancel => "OK", + MessageBoxButtons.AbortRetryIgnore => "Abort", + MessageBoxButtons.YesNoCancel => "Yes", + MessageBoxButtons.YesNo => "Yes", + MessageBoxButtons.RetryCancel => "Retry", + MessageBoxButtons.CancelTryContinue => "Cancel", + _ => string.Empty, + }; + + public string Button2Text => _button switch + { + MessageBoxButtons.OKCancel => "Cancel", + MessageBoxButtons.AbortRetryIgnore => "Retry", + MessageBoxButtons.YesNoCancel => "No", + MessageBoxButtons.YesNo => "No", + MessageBoxButtons.RetryCancel => "Cancel", + MessageBoxButtons.CancelTryContinue => "Try", + _ => string.Empty, + }; + + public string Button3Text => _button switch + { + MessageBoxButtons.AbortRetryIgnore => "Ignore", + MessageBoxButtons.YesNoCancel => "Cancel", + MessageBoxButtons.CancelTryContinue => "Continue", + _ => string.Empty, + }; + + public MessageBoxViewModel() { } + public MessageBoxViewModel(string message, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultBtn) + { + + Message = message; + Caption = caption; + _button = buttons; + _icon = icon; + _defaultButton = defaultBtn; + } + } +} diff --git a/Source/LibationWinForms/AvaloniaUI/ViewModels/MainWindowViewModel.cs b/Source/LibationWinForms/AvaloniaUI/ViewModels/MainWindowViewModel.cs new file mode 100644 index 00000000..5edcb26b --- /dev/null +++ b/Source/LibationWinForms/AvaloniaUI/ViewModels/MainWindowViewModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LibationWinForms.AvaloniaUI.ViewModels +{ + public class MainWindowViewModel + { + } +} diff --git a/Source/LibationWinForms/AvaloniaUI/ViewModels/ProcessBook2.cs b/Source/LibationWinForms/AvaloniaUI/ViewModels/ProcessBook2.cs index 4e4e9290..5a56d6e0 100644 --- a/Source/LibationWinForms/AvaloniaUI/ViewModels/ProcessBook2.cs +++ b/Source/LibationWinForms/AvaloniaUI/ViewModels/ProcessBook2.cs @@ -9,6 +9,7 @@ using DataLayer; using Dinah.Core; using FileLiberator; using LibationFileManager; +using LibationWinForms.AvaloniaUI.Views.Dialogs; using ReactiveUI; namespace LibationWinForms.AvaloniaUI.ViewModels @@ -152,7 +153,7 @@ namespace LibationWinForms.AvaloniaUI.ViewModels finally { if (Result == ProcessBookResult.None) - Result = showRetry(LibraryBook); + Result = await showRetry(LibraryBook); Status = Result switch { @@ -313,15 +314,15 @@ namespace LibationWinForms.AvaloniaUI.ViewModels #region Failure Handler - private ProcessBookResult showRetry(LibraryBook libraryBook) + private async Task showRetry(LibraryBook libraryBook) { Logger.Error("ERROR. All books have not been processed. Most recent book: processing failed"); - System.Windows.Forms.DialogResult? dialogResult = Configuration.Instance.BadBook switch + DialogResult? dialogResult = Configuration.Instance.BadBook switch { - Configuration.BadBookAction.Abort => System.Windows.Forms.DialogResult.Abort, - Configuration.BadBookAction.Retry => System.Windows.Forms.DialogResult.Retry, - Configuration.BadBookAction.Ignore => System.Windows.Forms.DialogResult.Ignore, + Configuration.BadBookAction.Abort => DialogResult.Abort, + Configuration.BadBookAction.Retry => DialogResult.Retry, + Configuration.BadBookAction.Ignore => DialogResult.Ignore, Configuration.BadBookAction.Ask => null, _ => null }; @@ -346,9 +347,9 @@ $@" Title: {libraryBook.Book.Title} } // if null then ask user - dialogResult ??= System.Windows.Forms.MessageBox.Show(string.Format(SkipDialogText + "\r\n\r\nSee Settings to avoid this box in the future.", details), "Skip importing this book?", SkipDialogButtons, System.Windows.Forms.MessageBoxIcon.Question, SkipDialogDefaultButton); + dialogResult ??= await MessageBox.Show(string.Format(SkipDialogText + "\r\n\r\nSee Settings to avoid this box in the future.", details), "Skip importing this book?", SkipDialogButtons, MessageBoxIcon.Question, SkipDialogDefaultButton); - if (dialogResult == System.Windows.Forms.DialogResult.Abort) + if (dialogResult == DialogResult.Abort) return ProcessBookResult.FailedAbort; if (dialogResult == SkipResult) @@ -373,9 +374,9 @@ An error occurred while trying to process this book. - IGNORE: Permanently ignore this book. Continue processing books. (Will not try this book again later.) ".Trim(); - private System.Windows.Forms.MessageBoxButtons SkipDialogButtons => System.Windows.Forms.MessageBoxButtons.AbortRetryIgnore; - private System.Windows.Forms.MessageBoxDefaultButton SkipDialogDefaultButton => System.Windows.Forms.MessageBoxDefaultButton.Button1; - private System.Windows.Forms.DialogResult SkipResult => System.Windows.Forms.DialogResult.Ignore; + private MessageBoxButtons SkipDialogButtons => MessageBoxButtons.AbortRetryIgnore; + private MessageBoxDefaultButton SkipDialogDefaultButton => MessageBoxDefaultButton.Button1; + private DialogResult SkipResult => DialogResult.Ignore; } #endregion diff --git a/Source/LibationWinForms/AvaloniaUI/Views/Dialogs/MessageBox.cs b/Source/LibationWinForms/AvaloniaUI/Views/Dialogs/MessageBox.cs new file mode 100644 index 00000000..bf71753a --- /dev/null +++ b/Source/LibationWinForms/AvaloniaUI/Views/Dialogs/MessageBox.cs @@ -0,0 +1,240 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Controls.ApplicationLifetimes; +using LibationWinForms.AvaloniaUI.ViewModels.Dialogs; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace LibationWinForms.AvaloniaUI.Views.Dialogs +{ + public class MessageBox + { + + /// Displays a message box with the specified text, caption, buttons, icon, and default button. + /// The text to display in the message box. + /// The text to display in the title bar of the message box. + /// One of the values that specifies which buttons to display in the message box. + /// One of the values that specifies which icon to display in the message box. + /// One of the values that specifies the default button for the message box. + /// One of the values. + /// + /// is not a member of . + /// -or- + /// is not a member of . + /// -or- + /// is not a member of . + /// An attempt was made to display the in a process that is not running in User Interactive mode. This is specified by the property. + public static async Task Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton) + { + return await ShowCore(null, text, caption, buttons, icon, defaultButton); + } + + + /// Displays a message box with specified text, caption, buttons, and icon. + /// The text to display in the message box. + /// The text to display in the title bar of the message box. + /// One of the values that specifies which buttons to display in the message box. + /// One of the values that specifies which icon to display in the message box. + /// One of the values. + /// The parameter specified is not a member of . + /// -or- + /// The parameter specified is not a member of . + /// An attempt was made to display the in a process that is not running in User Interactive mode. This is specified by the property. + public static async Task Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon) + { + return await ShowCore(null, text, caption, buttons, icon, MessageBoxDefaultButton.Button1); + } + + + /// Displays a message box with specified text, caption, and buttons. + /// The text to display in the message box. + /// The text to display in the title bar of the message box. + /// One of the values that specifies which buttons to display in the message box. + /// One of the values. + /// The parameter specified is not a member of . + /// An attempt was made to display the in a process that is not running in User Interactive mode. This is specified by the property. + public static async Task Show(string text, string caption, MessageBoxButtons buttons) + { + return await ShowCore(null, text, caption, buttons, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); + } + + + /// Displays a message box with specified text and caption. + /// The text to display in the message box. + /// The text to display in the title bar of the message box. + /// One of the values. + public static async Task Show(string text, string caption) + { + return await ShowCore(null, text, caption, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); + } + + /// Displays a message box with specified text. + /// The text to display in the message box. + /// One of the values. + public static async Task Show(string text) + { + return await ShowCore(null, text, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); + } + + + /// Displays a message box in front of the specified object and with the specified text, caption, buttons, icon, default button, and options. + /// An implementation of that will own the modal dialog box. + /// The text to display in the message box. + /// The text to display in the title bar of the message box. + /// One of the values that specifies which buttons to display in the message box. + /// One of the values that specifies which icon to display in the message box. + /// One of the values the specifies the default button for the message box. + /// One of the values that specifies which display and association options will be used for the message box. You may pass in 0 if you wish to use the defaults. + /// One of the values. + /// + /// is not a member of . + /// -or- + /// is not a member of . + /// -or- + /// is not a member of . + /// An attempt was made to display the in a process that is not running in User Interactive mode. This is specified by the property. + /// + /// -or- + /// specified an invalid combination of . + public static async Task Show(Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton) + { + return await ShowCore(owner, text, caption, buttons, icon, defaultButton); + } + + + /// Displays a message box in front of the specified object and with the specified text, caption, buttons, and icon. + /// An implementation of that will own the modal dialog box. + /// The text to display in the message box. + /// The text to display in the title bar of the message box. + /// One of the values that specifies which buttons to display in the message box. + /// One of the values that specifies which icon to display in the message box. + /// One of the values. + /// + /// is not a member of . + /// -or- + /// is not a member of . + /// An attempt was made to display the in a process that is not running in User Interactive mode. This is specified by the property. + public static async Task Show(Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon) + { + return await ShowCore(owner, text, caption, buttons, icon, MessageBoxDefaultButton.Button1); + } + + /// Displays a message box in front of the specified object and with the specified text, caption, and buttons. + /// An implementation of that will own the modal dialog box. + /// The text to display in the message box. + /// The text to display in the title bar of the message box. + /// One of the values that specifies which buttons to display in the message box. + /// One of the values. + /// + /// is not a member of . + /// An attempt was made to display the in a process that is not running in User Interactive mode. This is specified by the property. + public static async Task Show(Window owner, string text, string caption, MessageBoxButtons buttons) + { + return await ShowCore(owner, text, caption, buttons, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); + } + + /// Displays a message box in front of the specified object and with the specified text and caption. + /// An implementation of that will own the modal dialog box. + /// The text to display in the message box. + /// The text to display in the title bar of the message box. + /// One of the values. + public static async Task Show(Window owner, string text, string caption) + { + return await ShowCore(owner, text, caption, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); + } + + /// Displays a message box in front of the specified object and with the specified text. + /// An implementation of that will own the modal dialog box. + /// The text to display in the message box. + /// One of the values. + public static async Task Show(Window owner, string text) + { + return await ShowCore(owner, text, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); + } + + private static async Task ShowCore(Window owner, string message, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton) + { + if (Avalonia.Threading.Dispatcher.UIThread.CheckAccess()) + return await ShowCore2(owner, message, caption, buttons, icon, defaultButton); + else + return await Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() => ShowCore2(owner, message, caption, buttons, icon, defaultButton)); + + } + private static async Task ShowCore2(Window owner, string message, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton) + { + var dialog = new MessageBoxWindow(); + var vm = new MessageBoxViewModel(message, caption, buttons, icon, defaultButton); + dialog.DataContext = vm; + dialog.CanResize = false; + + var thisScreen = (owner ?? dialog).Screens.ScreenFromVisual(owner ?? dialog); + var tbx = dialog.FindControl("messageTextBlock"); + tbx.Text = message; + + var maxSize = new Size(0.6 * thisScreen.Bounds.Width - 72, 0.9 * thisScreen.Bounds.Height); + + var desiredMax = maxSize; + + //Try to minimize the TextBlock area. + List<(double, Size)> areas = new(); + for (int i = 0; i < 20; i++) + { + tbx.Measure(desiredMax); + + var area = tbx.DesiredSize.Width * tbx.DesiredSize.Height; + areas.Add((area, new Size(tbx.DesiredSize.Width, tbx.DesiredSize.Height))); + + if (tbx.DesiredSize.Height < maxSize.Height - 20) + { + if (desiredMax.Width / 2 < tbx.MinWidth) + desiredMax = new Size(desiredMax.Width * 1.5 + 1, desiredMax.Height); + else + desiredMax = new Size(desiredMax.Width / 2, desiredMax.Height); + } + } + + var min = areas.Min(a => a.Item1); + var mindim = areas.First(a => a.Item1 == min); + + var desiredSize = new Size(dialog.MinWidth - tbx.MinWidth + mindim.Item2.Width, dialog.MinHeight - tbx.MinHeight + mindim.Item2.Height); + + dialog.Width = desiredSize.Width; + dialog.Height = desiredSize.Height; + tbx.Width = mindim.Item2.Width; + tbx.Height = mindim.Item2.Height; + + if (owner is null) + { + if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + return await dialog.ShowDialog(desktop.MainWindow); + } + else + { + var window = new Window + { + IsVisible = false, + Height = 1, + Width = 1, + SystemDecorations = SystemDecorations.None, + ShowInTaskbar = false + }; + + window.Show(); + var result = await dialog.ShowDialog(window); + window.Close(); + return result; + } + + } + else + { + return await dialog.ShowDialog(owner); + } + } + } +} diff --git a/Source/LibationWinForms/AvaloniaUI/Views/Dialogs/MessageBoxWindow.axaml b/Source/LibationWinForms/AvaloniaUI/Views/Dialogs/MessageBoxWindow.axaml new file mode 100644 index 00000000..1e88cbc8 --- /dev/null +++ b/Source/LibationWinForms/AvaloniaUI/Views/Dialogs/MessageBoxWindow.axaml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Source/LibationWinForms/AvaloniaUI/Views/Dialogs/MessageBoxWindow.axaml.cs b/Source/LibationWinForms/AvaloniaUI/Views/Dialogs/MessageBoxWindow.axaml.cs new file mode 100644 index 00000000..f0e61464 --- /dev/null +++ b/Source/LibationWinForms/AvaloniaUI/Views/Dialogs/MessageBoxWindow.axaml.cs @@ -0,0 +1,115 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; +using Avalonia.ReactiveUI; +using LibationWinForms.AvaloniaUI.ViewModels.Dialogs; + +namespace LibationWinForms.AvaloniaUI.Views.Dialogs +{ + + public enum DialogResult + { + None = 0, + OK = 1, + Cancel = 2, + Abort = 3, + Retry = 4, + Ignore = 5, + Yes = 6, + No = 7, + TryAgain = 10, + Continue = 11 + } + + + public enum MessageBoxIcon + { + None = 0, + Error = 16, + Hand = 16, + Stop = 16, + Question = 32, + Exclamation = 48, + Warning = 48, + Asterisk = 64, + Information = 64 + } + public enum MessageBoxButtons + { + OK, + OKCancel, + AbortRetryIgnore, + YesNoCancel, + YesNo, + RetryCancel, + CancelTryContinue + } + + public enum MessageBoxDefaultButton + { + Button1, + Button2 = 256, + Button3 = 512, + } + public partial class MessageBoxWindow : ReactiveWindow + { + public MessageBoxWindow() + { + InitializeComponent(); +#if DEBUG + this.AttachDevTools(); +#endif + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + } + + public DialogResult DialogResult { get; private set; } + + public void Button1_Click(object sender, Avalonia.Interactivity.RoutedEventArgs args) + { + var vm = DataContext as MessageBoxViewModel; + DialogResult = vm.Buttons switch + { + MessageBoxButtons.OK => DialogResult.OK, + MessageBoxButtons.OKCancel => DialogResult.OK, + MessageBoxButtons.AbortRetryIgnore => DialogResult.Abort, + MessageBoxButtons.YesNoCancel => DialogResult.Yes, + MessageBoxButtons.YesNo => DialogResult.Yes, + MessageBoxButtons.RetryCancel => DialogResult.Retry, + MessageBoxButtons.CancelTryContinue => DialogResult.Cancel, + _ => DialogResult.None + }; + Close(DialogResult); + } + public void Button2_Click(object sender, Avalonia.Interactivity.RoutedEventArgs args) + { + var vm = DataContext as MessageBoxViewModel; + DialogResult = vm.Buttons switch + { + MessageBoxButtons.OKCancel => DialogResult.Cancel, + MessageBoxButtons.AbortRetryIgnore => DialogResult.Retry, + MessageBoxButtons.YesNoCancel => DialogResult.No, + MessageBoxButtons.YesNo => DialogResult.No, + MessageBoxButtons.RetryCancel => DialogResult.Cancel, + MessageBoxButtons.CancelTryContinue => DialogResult.TryAgain, + _ => DialogResult.None + }; + Close(DialogResult); + } + public void Button3_Click(object sender, Avalonia.Interactivity.RoutedEventArgs args) + { + var vm = DataContext as MessageBoxViewModel; + DialogResult = vm.Buttons switch + { + MessageBoxButtons.AbortRetryIgnore => DialogResult.Ignore, + MessageBoxButtons.YesNoCancel => DialogResult.Cancel, + MessageBoxButtons.CancelTryContinue => DialogResult.Continue, + _ => DialogResult.None + }; + Close(DialogResult); + } + } +} diff --git a/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.Export.axaml.cs b/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.Export.axaml.cs index 445ba0cd..bac291bf 100644 --- a/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.Export.axaml.cs +++ b/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.Export.axaml.cs @@ -1,4 +1,5 @@ using ApplicationServices; +using LibationWinForms.AvaloniaUI.Views.Dialogs; using System; using System.Linq; @@ -9,7 +10,7 @@ namespace LibationWinForms.AvaloniaUI.Views { private void Configure_Export() { } - public void exportLibraryToolStripMenuItem_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e) + public async void exportLibraryToolStripMenuItem_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e) { try { @@ -37,7 +38,7 @@ namespace LibationWinForms.AvaloniaUI.Views break; } - System.Windows.Forms.MessageBox.Show("Library exported to:\r\n" + saveFileDialog.FileName); + await MessageBox.Show("Library exported to:\r\n" + saveFileDialog.FileName); } catch (Exception ex) { diff --git a/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.Filter.axaml.cs b/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.Filter.axaml.cs index cb97905f..e9f08819 100644 --- a/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.Filter.axaml.cs +++ b/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.Filter.axaml.cs @@ -1,7 +1,9 @@ using Avalonia.Input; +using LibationWinForms.AvaloniaUI.Views.Dialogs; using LibationWinForms.Dialogs; using System; using System.Linq; +using System.Threading.Tasks; namespace LibationWinForms.AvaloniaUI.Views { @@ -13,22 +15,22 @@ namespace LibationWinForms.AvaloniaUI.Views public void filterHelpBtn_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e) => new SearchSyntaxDialog().ShowDialog(); - public void filterSearchTb_KeyPress(object sender, KeyEventArgs e) + public async void filterSearchTb_KeyPress(object sender, KeyEventArgs e) { if (e.Key == Key.Return) { - performFilter(this.filterSearchTb.Text); + await performFilter(this.filterSearchTb.Text); // silence the 'ding' e.Handled = true; } } - public void filterBtn_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e) - => performFilter(this.filterSearchTb.Text); + public async void filterBtn_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e) + => await performFilter(this.filterSearchTb.Text); private string lastGoodFilter = ""; - private void performFilter(string filterString) + private async Task performFilter(string filterString) { this.filterSearchTb.Text = filterString; @@ -39,10 +41,10 @@ namespace LibationWinForms.AvaloniaUI.Views } catch (Exception ex) { - System.Windows.Forms.MessageBox.Show($"Bad filter string:\r\n\r\n{ex.Message}", "Bad filter string", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); + await MessageBox.Show($"Bad filter string:\r\n\r\n{ex.Message}", "Bad filter string", MessageBoxButtons.OK, MessageBoxIcon.Error); // re-apply last good filter - performFilter(lastGoodFilter); + await performFilter(lastGoodFilter); } } } diff --git a/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.Liberate.axaml.cs b/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.Liberate.axaml.cs index a9da48d6..82c27a02 100644 --- a/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.Liberate.axaml.cs +++ b/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.Liberate.axaml.cs @@ -1,4 +1,5 @@ using DataLayer; +using LibationWinForms.AvaloniaUI.Views.Dialogs; using System; using System.Linq; using System.Threading.Tasks; @@ -40,15 +41,15 @@ namespace LibationWinForms.AvaloniaUI.Views public async void convertAllM4bToMp3ToolStripMenuItem_Click(object sender, Avalonia.Interactivity.RoutedEventArgs args) { - var result = System.Windows.Forms.MessageBox.Show( + var result = await MessageBox.Show( "This converts all m4b titles in your library to mp3 files. Original files are not deleted." + "\r\nFor large libraries this will take a long time and will take up more disk space." + "\r\n\r\nContinue?" + "\r\n\r\n(To always download titles as mp3 instead of m4b, go to Settings: Download my books as .MP3 files)", "Convert all M4b => Mp3?", - System.Windows.Forms.MessageBoxButtons.YesNo, - System.Windows.Forms.MessageBoxIcon.Warning); - if (result == System.Windows.Forms.DialogResult.Yes) + MessageBoxButtons.YesNo, + MessageBoxIcon.Warning); + if (result == DialogResult.Yes) { SetQueueCollapseState(false); await Task.Run(() => processBookQueue1.AddConvertMp3(ApplicationServices.DbContexts.GetLibrary_Flat_NoTracking() diff --git a/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.ProcessQueue.axaml.cs b/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.ProcessQueue.axaml.cs index 5d166aba..d2d069f3 100644 --- a/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.ProcessQueue.axaml.cs +++ b/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.ProcessQueue.axaml.cs @@ -1,6 +1,7 @@ using DataLayer; using Dinah.Core; using LibationFileManager; +using LibationWinForms.AvaloniaUI.Views.Dialogs; using System; using System.Linq; @@ -15,7 +16,7 @@ namespace LibationWinForms.AvaloniaUI.Views SetQueueCollapseState(collapseState); } - public void ProductsDisplay_LiberateClicked(object sender, LibraryBook libraryBook) + public async void ProductsDisplay_LiberateClicked(object sender, LibraryBook libraryBook) { try { @@ -38,7 +39,7 @@ namespace LibationWinForms.AvaloniaUI.Views if (!Go.To.File(filePath?.ShortPathName)) { var suffix = string.IsNullOrWhiteSpace(filePath) ? "" : $":\r\n{filePath}"; - System.Windows.Forms.MessageBox.Show($"File not found" + suffix); + await MessageBox.Show($"File not found" + suffix); } } } diff --git a/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.ScanManual.axaml.cs b/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.ScanManual.axaml.cs index 719b7e1a..ff158e0c 100644 --- a/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.ScanManual.axaml.cs +++ b/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.ScanManual.axaml.cs @@ -2,6 +2,7 @@ using AudibleUtilities; using Avalonia.Controls; using LibationFileManager; +using LibationWinForms.AvaloniaUI.Views.Dialogs; using LibationWinForms.Dialogs; using System; using System.Collections.Generic; @@ -49,9 +50,9 @@ namespace LibationWinForms.AvaloniaUI.Views } } - public void noAccountsYetAddAccountToolStripMenuItem_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e) + public async void noAccountsYetAddAccountToolStripMenuItem_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e) { - System.Windows.Forms.MessageBox.Show("To load your Audible library, come back here to the Import menu after adding your account"); + await MessageBox.Show("To load your Audible library, come back here to the Import menu after adding your account"); new AccountsDialog().ShowDialog(); } @@ -91,7 +92,7 @@ namespace LibationWinForms.AvaloniaUI.Views // this is here instead of ScanEnd so that the following is only possible when it's user-initiated, not automatic loop if (Configuration.Instance.ShowImportedStats && newAdded > 0) - System.Windows.Forms.MessageBox.Show($"Total processed: {totalProcessed}\r\nNew: {newAdded}"); + await MessageBox.Show($"Total processed: {totalProcessed}\r\nNew: {newAdded}"); } catch (Exception ex) { diff --git a/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.Settings.axaml.cs b/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.Settings.axaml.cs index cc84bbe8..f0ac8324 100644 --- a/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.Settings.axaml.cs +++ b/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.Settings.axaml.cs @@ -1,4 +1,5 @@ -using LibationWinForms.Dialogs; +using LibationWinForms.AvaloniaUI.Views.Dialogs; +using LibationWinForms.Dialogs; using System; using System.Linq; @@ -13,7 +14,7 @@ namespace LibationWinForms.AvaloniaUI.Views public void basicSettingsToolStripMenuItem_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e) => new SettingsDialog().ShowDialog(); - public void aboutToolStripMenuItem_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e) - => System.Windows.Forms.MessageBox.Show($"Running Libation version {AppScaffolding.LibationScaffolding.BuildVersion}", $"Libation v{AppScaffolding.LibationScaffolding.BuildVersion}"); + public async void aboutToolStripMenuItem_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e) + => await MessageBox.Show($"Running Libation version {AppScaffolding.LibationScaffolding.BuildVersion}", $"Libation v{AppScaffolding.LibationScaffolding.BuildVersion}"); } } diff --git a/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.axaml b/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.axaml index 22204a5a..d6853ad0 100644 --- a/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.axaml +++ b/Source/LibationWinForms/AvaloniaUI/Views/MainWindow/MainWindow.axaml @@ -14,7 +14,7 @@ - + @@ -106,7 +106,9 @@ +