This commit is contained in:
Michael Bucari-Tovo 2022-07-15 00:49:38 -06:00
parent 180d591b0a
commit d62821cd60
12 changed files with 104 additions and 138 deletions

View File

@ -1,5 +0,0 @@
<MenuItem xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="LibationWinForms.AvaloniaUI.Controls.FormattableMenuItem">
</MenuItem>

View File

@ -1,29 +0,0 @@
using Avalonia.Controls;
using Avalonia.Styling;
using System;
namespace LibationWinForms.AvaloniaUI.Controls
{
public partial class FormattableMenuItem : MenuItem, IStyleable
{
Type IStyleable.StyleKey => typeof(MenuItem);
private string _formatText;
public string FormatText
{
get => _formatText;
set
{
_formatText = value;
Header = value;
}
}
public string Format(params object[] args)
{
var formatText = string.Format(FormatText, args);
Header = formatText;
return formatText;
}
}
}

View File

@ -1,5 +0,0 @@
<TextBlock xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="LibationWinForms.AvaloniaUI.Controls.FormattableTextBlock">
</TextBlock>

View File

@ -1,27 +0,0 @@
using Avalonia.Controls;
using Avalonia.Styling;
using System;
namespace LibationWinForms.AvaloniaUI.Controls
{
public partial class FormattableTextBlock : TextBlock, IStyleable
{
Type IStyleable.StyleKey => typeof(TextBlock);
private string _formatText;
public string FormatText
{
get => _formatText;
set
{
_formatText = value;
Text = value;
}
}
public string Format(params object[] args)
{
return Text = string.Format(FormatText, args);
}
}
}

View File

@ -1,6 +1,7 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using DataLayer;
using LibationWinForms.AvaloniaUI.ViewModels.Dialogs;
using LibationWinForms.AvaloniaUI.Views.Dialogs;
using System;
@ -200,13 +201,35 @@ namespace LibationWinForms.AvaloniaUI
return await ShowCore(owner, text, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
}
public static async Task<DialogResult> ShowConfirmationDialog(Window owner, IEnumerable<LibraryBook> libraryBooks, string format, string title)
{
if (libraryBooks is null || !libraryBooks.Any())
return DialogResult.Cancel;
var count = libraryBooks.Count();
string thisThese = count > 1 ? "these" : "this";
string bookBooks = count > 1 ? "books" : "book";
string titlesAgg = libraryBooks.AggregateTitles();
var message
= string.Format(format, $"{thisThese} {count} {bookBooks}")
+ $"\r\n\r\n{titlesAgg}";
return await ShowCore(owner,
message,
title,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1);
}
private static async Task<DialogResult> 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<DialogResult> ShowCore2(Window owner, string message, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
{
@ -242,23 +265,6 @@ namespace LibationWinForms.AvaloniaUI
dialog.Height = dialog.MinHeight;
dialog.Width = dialog.MinWidth;
dialog.Opened += (_, _) =>
{
switch (defaultButton)
{
case MessageBoxDefaultButton.Button1:
dialog.FindControl<Button>("Button1").Focus();
break;
case MessageBoxDefaultButton.Button2:
dialog.FindControl<Button>("Button2").Focus();
break;
case MessageBoxDefaultButton.Button3:
dialog.FindControl<Button>("Button3").Focus();
break;
}
};
if (owner is null)
{
if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)

View File

@ -1,12 +1,4 @@
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;
using System;
namespace LibationWinForms.AvaloniaUI.ViewModels.Dialogs
{
@ -19,6 +11,7 @@ namespace LibationWinForms.AvaloniaUI.ViewModels.Dialogs
private MessageBoxIcon _icon;
private MessageBoxDefaultButton _defaultButton;
public MessageBoxDefaultButton DefaultButton => _defaultButton;
public MessageBoxButtons Buttons => _button;
public bool IsAsterisk => _icon == MessageBoxIcon.Asterisk;
@ -69,7 +62,7 @@ namespace LibationWinForms.AvaloniaUI.ViewModels.Dialogs
public double FormWidthFromTboxWidth(double tboxWidth)
{
int iconWidth = _icon is MessageBoxIcon.None ? 0 : 42;
return tboxWidth + 20 + iconWidth;
return tboxWidth + 30 + iconWidth;
}
public MessageBoxViewModel() { }
@ -85,7 +78,7 @@ namespace LibationWinForms.AvaloniaUI.ViewModels.Dialogs
int numBtns = HasButton3 ? 3 : HasButton2 ? 2 : 1;
int iconWidth = icon is MessageBoxIcon.None ? 0 : 42;
int formMinWidth = Math.Max(85 * numBtns + 10, 71 + iconWidth + 20);
TextBlockMinWidth = formMinWidth - 20 - iconWidth;
TextBlockMinWidth = formMinWidth - 30 - iconWidth;
}
}
}

View File

@ -10,7 +10,7 @@
Icon="/AvaloniaUI/Assets/1x1.png">
<Grid ColumnDefinitions="*" RowDefinitions="*,Auto">
<DockPanel Margin="5,10,10,10" Grid.Row="0" Background="White">
<DockPanel Margin="5,10,10,20" Grid.Row="0" Background="White">
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal"
VerticalAlignment="Top">
@ -21,15 +21,16 @@
<Image IsVisible="{Binding IsExclamation}" Stretch="None" Source="/AvaloniaUI/Assets/MBIcons/Exclamation.png"/>
</Panel>
<TextBlock Margin="5,0,0,0" Name="messageTextBlock" MinHeight="45" MinWidth="203" TextWrapping="WrapWithOverflow" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="12" Text="{Binding Message}" />
<TextBlock Margin="5,0,0,0" Name="messageTextBlock" MinHeight="45" MinWidth="193" TextWrapping="WrapWithOverflow" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="12" Text="{Binding Message}" />
</StackPanel>
</DockPanel>
<DockPanel Height="45" Grid.Row="1" Background="LightGray">
<DockPanel Height="45" Grid.Row="1" Background="WhiteSmoke">
<DockPanel.Styles>
<Style Selector="Button:focus">
<Setter Property="Background" Value="{DynamicResource SystemAccentColor}" />
<Setter Property="BorderBrush" Value="{DynamicResource SystemAccentColor}" />
<Setter Property="BorderThickness" Value="2" />
</Style>
</DockPanel.Styles>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="5" DockPanel.Dock="Bottom">

View File

@ -20,6 +20,24 @@ namespace LibationWinForms.AvaloniaUI.Views.Dialogs
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
this.Opened += MessageBoxWindow_Opened;
}
private void MessageBoxWindow_Opened(object sender, System.EventArgs e)
{
var vm = this.DataContext as MessageBoxViewModel;
switch (vm.DefaultButton)
{
case MessageBoxDefaultButton.Button1:
this.FindControl<Button>("Button1").Focus();
break;
case MessageBoxDefaultButton.Button2:
this.FindControl<Button>("Button2").Focus();
break;
case MessageBoxDefaultButton.Button3:
this.FindControl<Button>("Button3").Focus();
break;
}
}
public DialogResult DialogResult { get; private set; }

View File

@ -16,21 +16,6 @@ namespace LibationWinForms.AvaloniaUI.Views
_viewModel.RemoveButtonsVisible = false;
}
public async void removeBooksBtn_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
{
await productsDisplay.RemoveCheckedBooksAsync();
}
public async void doneRemovingBtn_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
{
_viewModel.RemoveButtonsVisible = false;
productsDisplay.CloseRemoveBooksColumn();
//Restore the filter
await performFilter(_viewModel.FilterString);
}
public void removeLibraryBooksToolStripMenuItem_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
{
// if 0 accounts, this will not be visible
@ -81,6 +66,21 @@ namespace LibationWinForms.AvaloniaUI.Views
await productsDisplay.ScanAndRemoveBooksAsync(accounts);
}
public async void removeBooksBtn_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
{
await productsDisplay.RemoveCheckedBooksAsync();
}
public async void doneRemovingBtn_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
{
_viewModel.RemoveButtonsVisible = false;
productsDisplay.CloseRemoveBooksColumn();
//Restore the filter
await performFilter(lastGoodFilter);
}
public void productsDisplay_RemovableCountChanged(object sender, int removeCount)
{
_viewModel.RemoveBooksButtonText = removeCount switch

View File

@ -38,7 +38,7 @@ namespace LibationWinForms.AvaloniaUI.Views
Serilog.Log.Logger.Error(ex, "An error occurred while backing up visible library books");
}
}
public void replaceTagsToolStripMenuItem_Click(object sender, Avalonia.Interactivity.RoutedEventArgs args)
public async void replaceTagsToolStripMenuItem_Click(object sender, Avalonia.Interactivity.RoutedEventArgs args)
{
var dialog = new TagsBatchDialog();
var result = dialog.ShowDialog();
@ -47,12 +47,13 @@ namespace LibationWinForms.AvaloniaUI.Views
var visibleLibraryBooks = productsDisplay.GetVisibleBookEntries();
var confirmationResult = MessageBoxLib.ShowConfirmationDialog(
var confirmationResult = await MessageBox.ShowConfirmationDialog(
this,
visibleLibraryBooks,
$"Are you sure you want to replace tags in {0}?",
"Are you sure you want to replace tags in {0}?",
"Replace tags?");
if (confirmationResult != System.Windows.Forms.DialogResult.Yes)
if (confirmationResult != DialogResult.Yes)
return;
foreach (var libraryBook in visibleLibraryBooks)
@ -60,7 +61,7 @@ namespace LibationWinForms.AvaloniaUI.Views
LibraryCommands.UpdateUserDefinedItem(visibleLibraryBooks.Select(lb => lb.Book));
}
public void setDownloadedToolStripMenuItem_Click(object sender, Avalonia.Interactivity.RoutedEventArgs args)
public async void setDownloadedToolStripMenuItem_Click(object sender, Avalonia.Interactivity.RoutedEventArgs args)
{
var dialog = new LiberatedStatusBatchDialog();
var result = dialog.ShowDialog();
@ -69,12 +70,13 @@ namespace LibationWinForms.AvaloniaUI.Views
var visibleLibraryBooks = productsDisplay.GetVisibleBookEntries();
var confirmationResult = MessageBoxLib.ShowConfirmationDialog(
var confirmationResult = await MessageBox.ShowConfirmationDialog(
this,
visibleLibraryBooks,
$"Are you sure you want to replace downloaded status in {0}?",
"Are you sure you want to replace downloaded status in {0}?",
"Replace downloaded status?");
if (confirmationResult != System.Windows.Forms.DialogResult.Yes)
if (confirmationResult != DialogResult.Yes)
return;
foreach (var libraryBook in visibleLibraryBooks)
@ -86,12 +88,13 @@ namespace LibationWinForms.AvaloniaUI.Views
{
var visibleLibraryBooks = productsDisplay.GetVisibleBookEntries();
var confirmationResult = MessageBoxLib.ShowConfirmationDialog(
var confirmationResult = await MessageBox.ShowConfirmationDialog(
this,
visibleLibraryBooks,
$"Are you sure you want to remove {0} from Libation's library?",
"Are you sure you want to remove {0} from Libation's library?",
"Remove books from Libation?");
if (confirmationResult != System.Windows.Forms.DialogResult.Yes)
if (confirmationResult != DialogResult.Yes)
return;
var visibleIds = visibleLibraryBooks.Select(lb => lb.Book.AudibleProductId).ToList();

View File

@ -47,12 +47,13 @@ namespace LibationWinForms.AvaloniaUI.Views.ProductsGrid
return;
var libraryBooks = selectedBooks.Select(rge => rge.LibraryBook).ToList();
var result = MessageBoxLib.ShowConfirmationDialog(
var result = await MessageBox.ShowConfirmationDialog(
null,
libraryBooks,
$"Are you sure you want to remove {selectedBooks.Count} books from Libation's library?",
"Remove books from Libation?");
if (result != System.Windows.Forms.DialogResult.Yes)
if (result != DialogResult.Yes)
return;
foreach (var book in selectedBooks)

View File

@ -89,27 +89,37 @@
<Compile Update="Dialogs\SettingsDialog.*.cs">
<DependentUpon>SettingsDialog.cs</DependentUpon>
</Compile>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<Compile Update="Form1.*.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
</ItemGroup> <ItemGroup>
<Compile Update="Form1.*.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<AvaloniaResource Update="AvaloniaUI\Assets\LibationStyles.xaml">
<Generator>MSBuild:Compile</Generator>
</AvaloniaResource>
</ItemGroup>
<ItemGroup>
<Compile Update="AvaloniaUI\Controls\FormattableTextBlock.axaml.cs">
<DependentUpon>FormattableTextBlock.axaml</DependentUpon>
</Compile>
<Compile Update="AvaloniaUI\Controls\FormattableMenuItem.axaml.cs">
<DependentUpon>FormattableMenuItem.axaml</DependentUpon>
</Compile>
<ItemGroup>
<Compile Update="AvaloniaUI\Views\ProcessQueueControl2.axaml.cs">
<DependentUpon>ProcessQueueControl2.axaml</DependentUpon>
</Compile>
</Compile>
<Compile Update="AvaloniaUI\Views\MainWindow\MainWindow.axaml.cs">
<DependentUpon>ProcessQueueControl2.axaml</DependentUpon>
</Compile>
<Compile Update="AvaloniaUI\Views\MainWindow\MainWindow.*.axaml.cs">
<DependentUpon>ProcessQueueControl2.axaml.cs</DependentUpon>
</Compile>
<Compile Update="AvaloniaUI\Views\ProcessBookControl2.axaml.cs">
<DependentUpon>ProcessBookControl2.axaml</DependentUpon>
</Compile>
</Compile>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>