From 43a4d0d1d7bb99f0ce653322ce232b1839973bb1 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Mon, 23 May 2022 22:24:45 -0600 Subject: [PATCH] Cleanup --- .../GridView/DescriptionDisplay.cs | 4 +- Source/LibationWinForms/GridView/GridEntry.cs | 14 +++---- .../LibationWinForms/GridView/ImageDisplay.cs | 4 +- .../LiberateDataGridViewImageButtonColumn.cs | 5 +-- .../GridView/LibraryBookEntry.cs | 10 ++--- .../GridView/ProductsDisplay.cs | 12 +++--- .../LibationWinForms/GridView/ProductsGrid.cs | 6 +-- .../LibationWinForms/GridView/SeriesEntry.cs | 16 ++++---- .../GridView/SyncBindingSource.cs | 37 +++++++++---------- 9 files changed, 50 insertions(+), 58 deletions(-) diff --git a/Source/LibationWinForms/GridView/DescriptionDisplay.cs b/Source/LibationWinForms/GridView/DescriptionDisplay.cs index a39790d9..d3aefd52 100644 --- a/Source/LibationWinForms/GridView/DescriptionDisplay.cs +++ b/Source/LibationWinForms/GridView/DescriptionDisplay.cs @@ -1,7 +1,5 @@ using System; -using System.ComponentModel; using System.Drawing; -using System.Linq; using System.Runtime.InteropServices; using System.Windows.Forms; @@ -11,7 +9,7 @@ namespace LibationWinForms.GridView { private int borderThickness = 5; - public int BorderThickness + public int BorderThickness { get => borderThickness; set diff --git a/Source/LibationWinForms/GridView/GridEntry.cs b/Source/LibationWinForms/GridView/GridEntry.cs index 733bcac8..6757ef60 100644 --- a/Source/LibationWinForms/GridView/GridEntry.cs +++ b/Source/LibationWinForms/GridView/GridEntry.cs @@ -81,21 +81,21 @@ namespace LibationWinForms.GridView ~GridEntry() { PictureStorage.PictureCached -= PictureStorage_PictureCached; - } + } } internal static class GridEntryExtensions { - #nullable enable - public static IEnumerable Series(this IEnumerable gridEntries) +#nullable enable + public static IEnumerable Series(this IEnumerable gridEntries) => gridEntries.Where(i => i is SeriesEntry).Cast(); - public static IEnumerable LibraryBooks(this IEnumerable gridEntries) + public static IEnumerable LibraryBooks(this IEnumerable gridEntries) => gridEntries.Where(i => i is LibraryBookEntry).Cast(); - public static LibraryBookEntry? FindBookByAsin(this IEnumerable gridEntries, string audibleProductID) + public static LibraryBookEntry? FindBookByAsin(this IEnumerable gridEntries, string audibleProductID) => gridEntries.FirstOrDefault(i => i.AudibleProductId == audibleProductID); - public static SeriesEntry? FindBookSeriesEntry(this IEnumerable gridEntries, IEnumerable matchSeries) + public static SeriesEntry? FindBookSeriesEntry(this IEnumerable gridEntries, IEnumerable matchSeries) => gridEntries.Series().FirstOrDefault(i => matchSeries.Any(s => s.Series.Name == i.Series)); - public static IEnumerable EmptySeries(this IEnumerable gridEntries) + public static IEnumerable EmptySeries(this IEnumerable gridEntries) => gridEntries.Series().Where(i => i.Children.Count == 0); } } diff --git a/Source/LibationWinForms/GridView/ImageDisplay.cs b/Source/LibationWinForms/GridView/ImageDisplay.cs index a6bfa574..831b8ec9 100644 --- a/Source/LibationWinForms/GridView/ImageDisplay.cs +++ b/Source/LibationWinForms/GridView/ImageDisplay.cs @@ -1,6 +1,4 @@ -using FileLiberator; -using LibationFileManager; -using System; +using System; using System.Drawing; using System.IO; using System.Windows.Forms; diff --git a/Source/LibationWinForms/GridView/LiberateDataGridViewImageButtonColumn.cs b/Source/LibationWinForms/GridView/LiberateDataGridViewImageButtonColumn.cs index a237b7a0..f7291962 100644 --- a/Source/LibationWinForms/GridView/LiberateDataGridViewImageButtonColumn.cs +++ b/Source/LibationWinForms/GridView/LiberateDataGridViewImageButtonColumn.cs @@ -1,8 +1,7 @@ -using System; +using DataLayer; +using System; using System.Drawing; using System.Windows.Forms; -using System.Linq; -using DataLayer; namespace LibationWinForms.GridView { diff --git a/Source/LibationWinForms/GridView/LibraryBookEntry.cs b/Source/LibationWinForms/GridView/LibraryBookEntry.cs index 5fc606a1..8d93ebff 100644 --- a/Source/LibationWinForms/GridView/LibraryBookEntry.cs +++ b/Source/LibationWinForms/GridView/LibraryBookEntry.cs @@ -1,10 +1,10 @@ -using System; +using ApplicationServices; +using DataLayer; +using Dinah.Core; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; -using ApplicationServices; -using DataLayer; -using Dinah.Core; namespace LibationWinForms.GridView { @@ -183,7 +183,7 @@ namespace LibationWinForms.GridView { nameof(Liberate), () => Liberate }, { nameof(DateAdded), () => DateAdded }, }; - + #endregion diff --git a/Source/LibationWinForms/GridView/ProductsDisplay.cs b/Source/LibationWinForms/GridView/ProductsDisplay.cs index 66de694b..7e1b2d8a 100644 --- a/Source/LibationWinForms/GridView/ProductsDisplay.cs +++ b/Source/LibationWinForms/GridView/ProductsDisplay.cs @@ -1,14 +1,14 @@ -using System; +using ApplicationServices; +using DataLayer; +using FileLiberator; +using LibationFileManager; +using LibationWinForms.Dialogs; +using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; -using ApplicationServices; -using DataLayer; -using FileLiberator; -using LibationFileManager; -using LibationWinForms.Dialogs; namespace LibationWinForms.GridView { diff --git a/Source/LibationWinForms/GridView/ProductsGrid.cs b/Source/LibationWinForms/GridView/ProductsGrid.cs index e9a3bdb1..a715eb8e 100644 --- a/Source/LibationWinForms/GridView/ProductsGrid.cs +++ b/Source/LibationWinForms/GridView/ProductsGrid.cs @@ -46,17 +46,15 @@ namespace LibationWinForms.GridView private void DataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) { // handle grid button click: https://stackoverflow.com/a/13687844 - if ( e.RowIndex < 0) + if (e.RowIndex < 0) return; - var column = gridEntryDataGridView.Columns[e.ColumnIndex]; - var entry = getGridEntry(e.RowIndex); if (entry is LibraryBookEntry lbEntry) { if (e.ColumnIndex == liberateGVColumn.Index) LiberateClicked?.Invoke(lbEntry); - else if (e.ColumnIndex == tagAndDetailsGVColumn.Index && entry is LibraryBookEntry) + else if (e.ColumnIndex == tagAndDetailsGVColumn.Index) DetailsClicked?.Invoke(lbEntry); else if (e.ColumnIndex == descriptionGVColumn.Index) DescriptionClicked?.Invoke(lbEntry, gridEntryDataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false)); diff --git a/Source/LibationWinForms/GridView/SeriesEntry.cs b/Source/LibationWinForms/GridView/SeriesEntry.cs index 17eb8125..65cb648e 100644 --- a/Source/LibationWinForms/GridView/SeriesEntry.cs +++ b/Source/LibationWinForms/GridView/SeriesEntry.cs @@ -31,14 +31,14 @@ namespace LibationWinForms.GridView } public override string Series { get; protected set; } public override string Title { get; protected set; } - public override string Length - { + public override string Length + { get { int bookLenMins = Children.Sum(c => c.LibraryBook.Book.LengthInMinutes); return bookLenMins == 0 ? "" : $"{bookLenMins / 60} hr {bookLenMins % 60} min"; - } - protected set => throw new NotImplementedException(); + } + protected set => throw new NotImplementedException(); } public override string Authors { get; protected set; } public override string Narrators { get; protected set; } @@ -57,7 +57,7 @@ namespace LibationWinForms.GridView public SeriesEntry(SeriesBook seriesBook, IEnumerable children) { - Children = children.Select(c=>new LibraryBookEntry(c) { Parent = this }).ToList(); + Children = children.Select(c => new LibraryBookEntry(c) { Parent = this }).ToList(); SetSeriesBook(seriesBook); } public SeriesEntry(SeriesBook seriesBook, LibraryBook child) @@ -96,9 +96,9 @@ namespace LibationWinForms.GridView { { nameof(Title), () => Book.SeriesSortable() }, { nameof(Series), () => Book.SeriesSortable() }, - { nameof(Length), () => Children.Sum(c=>c.LibraryBook.Book.LengthInMinutes) }, - { nameof(MyRating), () => Children.Average(c=>c.LibraryBook.Book.UserDefinedItem.Rating.FirstScore()) }, - { nameof(PurchaseDate), () => Children.Min(c=>c.LibraryBook.DateAdded) }, + { nameof(Length), () => Children.Sum(c => c.LibraryBook.Book.LengthInMinutes) }, + { nameof(MyRating), () => Children.Average(c => c.LibraryBook.Book.UserDefinedItem.Rating.FirstScore()) }, + { nameof(PurchaseDate), () => Children.Min(c => c.LibraryBook.DateAdded) }, { nameof(ProductRating), () => Children.Average(c => c.LibraryBook.Book.Rating.FirstScore()) }, { nameof(Authors), () => string.Empty }, { nameof(Narrators), () => string.Empty }, diff --git a/Source/LibationWinForms/GridView/SyncBindingSource.cs b/Source/LibationWinForms/GridView/SyncBindingSource.cs index 5faafb0b..970e110a 100644 --- a/Source/LibationWinForms/GridView/SyncBindingSource.cs +++ b/Source/LibationWinForms/GridView/SyncBindingSource.cs @@ -1,30 +1,29 @@ -using System; -using System.ComponentModel; +using System.ComponentModel; using System.Threading; using System.Windows.Forms; // https://stackoverflow.com/a/32886415 namespace LibationWinForms.GridView { - public class SyncBindingSource : BindingSource - { - private SynchronizationContext syncContext { get; } + public class SyncBindingSource : BindingSource + { + private SynchronizationContext syncContext { get; } - public SyncBindingSource() : base() - => syncContext = SynchronizationContext.Current; - public SyncBindingSource(IContainer container) : base(container) - => syncContext = SynchronizationContext.Current; - public SyncBindingSource(object dataSource, string dataMember) : base(dataSource, dataMember) - => syncContext = SynchronizationContext.Current; + public SyncBindingSource() : base() + => syncContext = SynchronizationContext.Current; + public SyncBindingSource(IContainer container) : base(container) + => syncContext = SynchronizationContext.Current; + public SyncBindingSource(object dataSource, string dataMember) : base(dataSource, dataMember) + => syncContext = SynchronizationContext.Current; - public override bool SupportsFiltering => true; + public override bool SupportsFiltering => true; protected override void OnListChanged(ListChangedEventArgs e) - { - if (syncContext is not null) - syncContext.Send(_ => base.OnListChanged(e), null); - else - base.OnListChanged(e); - } - } + { + if (syncContext is not null) + syncContext.Send(_ => base.OnListChanged(e), null); + else + base.OnListChanged(e); + } + } }