This commit is contained in:
Michael Bucari-Tovo 2022-05-23 22:24:45 -06:00
parent 632b432b7c
commit 43a4d0d1d7
9 changed files with 50 additions and 58 deletions

View File

@ -1,7 +1,5 @@
using System; using System;
using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Windows.Forms; using System.Windows.Forms;
@ -11,7 +9,7 @@ namespace LibationWinForms.GridView
{ {
private int borderThickness = 5; private int borderThickness = 5;
public int BorderThickness public int BorderThickness
{ {
get => borderThickness; get => borderThickness;
set set

View File

@ -81,21 +81,21 @@ namespace LibationWinForms.GridView
~GridEntry() ~GridEntry()
{ {
PictureStorage.PictureCached -= PictureStorage_PictureCached; PictureStorage.PictureCached -= PictureStorage_PictureCached;
} }
} }
internal static class GridEntryExtensions internal static class GridEntryExtensions
{ {
#nullable enable #nullable enable
public static IEnumerable<SeriesEntry> Series(this IEnumerable<GridEntry> gridEntries) public static IEnumerable<SeriesEntry> Series(this IEnumerable<GridEntry> gridEntries)
=> gridEntries.Where(i => i is SeriesEntry).Cast<SeriesEntry>(); => gridEntries.Where(i => i is SeriesEntry).Cast<SeriesEntry>();
public static IEnumerable<LibraryBookEntry> LibraryBooks(this IEnumerable<GridEntry> gridEntries) public static IEnumerable<LibraryBookEntry> LibraryBooks(this IEnumerable<GridEntry> gridEntries)
=> gridEntries.Where(i => i is LibraryBookEntry).Cast<LibraryBookEntry>(); => gridEntries.Where(i => i is LibraryBookEntry).Cast<LibraryBookEntry>();
public static LibraryBookEntry? FindBookByAsin(this IEnumerable<LibraryBookEntry> gridEntries, string audibleProductID) public static LibraryBookEntry? FindBookByAsin(this IEnumerable<LibraryBookEntry> gridEntries, string audibleProductID)
=> gridEntries.FirstOrDefault(i => i.AudibleProductId == audibleProductID); => gridEntries.FirstOrDefault(i => i.AudibleProductId == audibleProductID);
public static SeriesEntry? FindBookSeriesEntry(this IEnumerable<GridEntry> gridEntries, IEnumerable<SeriesBook> matchSeries) public static SeriesEntry? FindBookSeriesEntry(this IEnumerable<GridEntry> gridEntries, IEnumerable<SeriesBook> matchSeries)
=> gridEntries.Series().FirstOrDefault(i => matchSeries.Any(s => s.Series.Name == i.Series)); => gridEntries.Series().FirstOrDefault(i => matchSeries.Any(s => s.Series.Name == i.Series));
public static IEnumerable<SeriesEntry> EmptySeries(this IEnumerable<GridEntry> gridEntries) public static IEnumerable<SeriesEntry> EmptySeries(this IEnumerable<GridEntry> gridEntries)
=> gridEntries.Series().Where(i => i.Children.Count == 0); => gridEntries.Series().Where(i => i.Children.Count == 0);
} }
} }

View File

@ -1,6 +1,4 @@
using FileLiberator; using System;
using LibationFileManager;
using System;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Windows.Forms; using System.Windows.Forms;

View File

@ -1,8 +1,7 @@
using System; using DataLayer;
using System;
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using System.Linq;
using DataLayer;
namespace LibationWinForms.GridView namespace LibationWinForms.GridView
{ {

View File

@ -1,10 +1,10 @@
using System; using ApplicationServices;
using DataLayer;
using Dinah.Core;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
using ApplicationServices;
using DataLayer;
using Dinah.Core;
namespace LibationWinForms.GridView namespace LibationWinForms.GridView
{ {
@ -183,7 +183,7 @@ namespace LibationWinForms.GridView
{ nameof(Liberate), () => Liberate }, { nameof(Liberate), () => Liberate },
{ nameof(DateAdded), () => DateAdded }, { nameof(DateAdded), () => DateAdded },
}; };
#endregion #endregion

View File

@ -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.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using ApplicationServices;
using DataLayer;
using FileLiberator;
using LibationFileManager;
using LibationWinForms.Dialogs;
namespace LibationWinForms.GridView namespace LibationWinForms.GridView
{ {

View File

@ -46,17 +46,15 @@ namespace LibationWinForms.GridView
private void DataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) private void DataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{ {
// handle grid button click: https://stackoverflow.com/a/13687844 // handle grid button click: https://stackoverflow.com/a/13687844
if ( e.RowIndex < 0) if (e.RowIndex < 0)
return; return;
var column = gridEntryDataGridView.Columns[e.ColumnIndex];
var entry = getGridEntry(e.RowIndex); var entry = getGridEntry(e.RowIndex);
if (entry is LibraryBookEntry lbEntry) if (entry is LibraryBookEntry lbEntry)
{ {
if (e.ColumnIndex == liberateGVColumn.Index) if (e.ColumnIndex == liberateGVColumn.Index)
LiberateClicked?.Invoke(lbEntry); LiberateClicked?.Invoke(lbEntry);
else if (e.ColumnIndex == tagAndDetailsGVColumn.Index && entry is LibraryBookEntry) else if (e.ColumnIndex == tagAndDetailsGVColumn.Index)
DetailsClicked?.Invoke(lbEntry); DetailsClicked?.Invoke(lbEntry);
else if (e.ColumnIndex == descriptionGVColumn.Index) else if (e.ColumnIndex == descriptionGVColumn.Index)
DescriptionClicked?.Invoke(lbEntry, gridEntryDataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false)); DescriptionClicked?.Invoke(lbEntry, gridEntryDataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false));

View File

@ -31,14 +31,14 @@ namespace LibationWinForms.GridView
} }
public override string Series { get; protected set; } public override string Series { get; protected set; }
public override string Title { get; protected set; } public override string Title { get; protected set; }
public override string Length public override string Length
{ {
get get
{ {
int bookLenMins = Children.Sum(c => c.LibraryBook.Book.LengthInMinutes); int bookLenMins = Children.Sum(c => c.LibraryBook.Book.LengthInMinutes);
return bookLenMins == 0 ? "" : $"{bookLenMins / 60} hr {bookLenMins % 60} min"; 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 Authors { get; protected set; }
public override string Narrators { get; protected set; } public override string Narrators { get; protected set; }
@ -57,7 +57,7 @@ namespace LibationWinForms.GridView
public SeriesEntry(SeriesBook seriesBook, IEnumerable<LibraryBook> children) public SeriesEntry(SeriesBook seriesBook, IEnumerable<LibraryBook> children)
{ {
Children = children.Select(c=>new LibraryBookEntry(c) { Parent = this }).ToList(); Children = children.Select(c => new LibraryBookEntry(c) { Parent = this }).ToList();
SetSeriesBook(seriesBook); SetSeriesBook(seriesBook);
} }
public SeriesEntry(SeriesBook seriesBook, LibraryBook child) public SeriesEntry(SeriesBook seriesBook, LibraryBook child)
@ -96,9 +96,9 @@ namespace LibationWinForms.GridView
{ {
{ nameof(Title), () => Book.SeriesSortable() }, { nameof(Title), () => Book.SeriesSortable() },
{ nameof(Series), () => Book.SeriesSortable() }, { nameof(Series), () => Book.SeriesSortable() },
{ nameof(Length), () => Children.Sum(c=>c.LibraryBook.Book.LengthInMinutes) }, { nameof(Length), () => Children.Sum(c => c.LibraryBook.Book.LengthInMinutes) },
{ nameof(MyRating), () => Children.Average(c=>c.LibraryBook.Book.UserDefinedItem.Rating.FirstScore()) }, { nameof(MyRating), () => Children.Average(c => c.LibraryBook.Book.UserDefinedItem.Rating.FirstScore()) },
{ nameof(PurchaseDate), () => Children.Min(c=>c.LibraryBook.DateAdded) }, { nameof(PurchaseDate), () => Children.Min(c => c.LibraryBook.DateAdded) },
{ nameof(ProductRating), () => Children.Average(c => c.LibraryBook.Book.Rating.FirstScore()) }, { nameof(ProductRating), () => Children.Average(c => c.LibraryBook.Book.Rating.FirstScore()) },
{ nameof(Authors), () => string.Empty }, { nameof(Authors), () => string.Empty },
{ nameof(Narrators), () => string.Empty }, { nameof(Narrators), () => string.Empty },

View File

@ -1,30 +1,29 @@
using System; using System.ComponentModel;
using System.ComponentModel;
using System.Threading; using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
// https://stackoverflow.com/a/32886415 // https://stackoverflow.com/a/32886415
namespace LibationWinForms.GridView namespace LibationWinForms.GridView
{ {
public class SyncBindingSource : BindingSource public class SyncBindingSource : BindingSource
{ {
private SynchronizationContext syncContext { get; } private SynchronizationContext syncContext { get; }
public SyncBindingSource() : base() public SyncBindingSource() : base()
=> syncContext = SynchronizationContext.Current; => syncContext = SynchronizationContext.Current;
public SyncBindingSource(IContainer container) : base(container) public SyncBindingSource(IContainer container) : base(container)
=> syncContext = SynchronizationContext.Current; => syncContext = SynchronizationContext.Current;
public SyncBindingSource(object dataSource, string dataMember) : base(dataSource, dataMember) public SyncBindingSource(object dataSource, string dataMember) : base(dataSource, dataMember)
=> syncContext = SynchronizationContext.Current; => syncContext = SynchronizationContext.Current;
public override bool SupportsFiltering => true; public override bool SupportsFiltering => true;
protected override void OnListChanged(ListChangedEventArgs e) protected override void OnListChanged(ListChangedEventArgs e)
{ {
if (syncContext is not null) if (syncContext is not null)
syncContext.Send(_ => base.OnListChanged(e), null); syncContext.Send(_ => base.OnListChanged(e), null);
else else
base.OnListChanged(e); base.OnListChanged(e);
} }
} }
} }