Change liberate text buttons to images

This commit is contained in:
Robert McRackan 2019-12-20 16:37:50 -05:00
parent de66e5b405
commit 25f5f0ed14
22 changed files with 274 additions and 77 deletions

View File

@ -109,5 +109,125 @@ namespace LibationWinForms.Properties {
return ((System.Drawing.Bitmap)(obj)); return ((System.Drawing.Bitmap)(obj));
} }
} }
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap liberate_green {
get {
object obj = ResourceManager.GetObject("liberate_green", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap liberate_green_pdf_blank {
get {
object obj = ResourceManager.GetObject("liberate_green_pdf_blank", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap liberate_green_pdf_no {
get {
object obj = ResourceManager.GetObject("liberate_green_pdf_no", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap liberate_green_pdf_yes {
get {
object obj = ResourceManager.GetObject("liberate_green_pdf_yes", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap liberate_red {
get {
object obj = ResourceManager.GetObject("liberate_red", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap liberate_red_pdf_blank {
get {
object obj = ResourceManager.GetObject("liberate_red_pdf_blank", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap liberate_red_pdf_no {
get {
object obj = ResourceManager.GetObject("liberate_red_pdf_no", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap liberate_red_pdf_yes {
get {
object obj = ResourceManager.GetObject("liberate_red_pdf_yes", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap liberate_yellow {
get {
object obj = ResourceManager.GetObject("liberate_yellow", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap liberate_yellow_pdf_blank {
get {
object obj = ResourceManager.GetObject("liberate_yellow_pdf_blank", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap liberate_yellow_pdf_no {
get {
object obj = ResourceManager.GetObject("liberate_yellow_pdf_no", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap liberate_yellow_pdf_yes {
get {
object obj = ResourceManager.GetObject("liberate_yellow_pdf_yes", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
} }
} }

View File

@ -133,4 +133,40 @@
<data name="edit_tags_50x50" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="edit_tags_50x50" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\edit-tags-50x50.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\edit-tags-50x50.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="liberate_green" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\liberate_green.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="liberate_green_pdf_blank" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\liberate_green_pdf_blank.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="liberate_green_pdf_no" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\liberate_green_pdf_no.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="liberate_green_pdf_yes" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\liberate_green_pdf_yes.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="liberate_red" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\liberate_red.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="liberate_red_pdf_blank" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\liberate_red_pdf_blank.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="liberate_red_pdf_no" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\liberate_red_pdf_no.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="liberate_red_pdf_yes" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\liberate_red_pdf_yes.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="liberate_yellow" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\liberate_yellow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="liberate_yellow_pdf_blank" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\liberate_yellow_pdf_blank.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="liberate_yellow_pdf_no" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\liberate_yellow_pdf_no.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="liberate_yellow_pdf_yes" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\liberate_yellow_pdf_yes.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root> </root>

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -0,0 +1,2 @@
[InternetShortcut]
URL=https://www.flaticon.com/free-icon/pdf-file-format-symbol_29099

View File

@ -0,0 +1,2 @@
[InternetShortcut]
URL=https://www.flaticon.com/free-icon/semaphore_55291

View File

@ -26,44 +26,19 @@ namespace LibationWinForms
[Browsable(false)] [Browsable(false)]
public IEnumerable<string> TagsEnumerated => book.UserDefinedItem.TagsEnumerated; public IEnumerable<string> TagsEnumerated => book.UserDefinedItem.TagsEnumerated;
public enum LiberatedState { NotDownloaded, DRM, Liberated }
[Browsable(false)] [Browsable(false)]
public string Download_Status public LiberatedState Liberated_Status
{ => FileManager.AudibleFileStorage.Audio.Exists(book.AudibleProductId) ? LiberatedState.Liberated
get : FileManager.AudibleFileStorage.AAX.Exists(book.AudibleProductId) ? LiberatedState.DRM
{ : LiberatedState.NotDownloaded;
var print
= FileManager.AudibleFileStorage.Audio.Exists(book.AudibleProductId) ? "Liberated"
: FileManager.AudibleFileStorage.AAX.Exists(book.AudibleProductId) ? "DRM"
: "NOT d/l'ed";
if (!book.Supplements.Any()) public enum PdfState { NoPdf, Downloaded, NotDownloaded }
return print; [Browsable(false)]
public PdfState Pdf_Status
print += "\r\n"; => !book.Supplements.Any() ? PdfState.NoPdf
: FileManager.AudibleFileStorage.PDF.Exists(book.AudibleProductId) ? PdfState.Downloaded
var downloadStatuses = book.Supplements : PdfState.NotDownloaded;
.Select(d => FileManager.AudibleFileStorage.PDF.Exists(book.AudibleProductId))
// break delayed execution right now!
.ToList();
var count = downloadStatuses.Count;
if (count == 1)
{
print += downloadStatuses[0]
? "PDF d/l'ed"
: "PDF NOT d/l'ed";
}
else
{
var downloadedCount = downloadStatuses.Count(s => s);
print
+= downloadedCount == count ? $"{count} PDFs d/l'ed"
: downloadedCount == 0 ? $"{count} PDFs NOT d/l'ed"
: $"{downloadedCount} of {count} PDFs d/l'ed";
}
return print;
}
}
// displayValues is what gets displayed // displayValues is what gets displayed
// the value that gets returned from the property is the cell's value // the value that gets returned from the property is the cell's value

View File

@ -74,8 +74,16 @@ namespace LibationWinForms
private void replaceFormatted(object sender, DataGridViewCellFormattingEventArgs e) private void replaceFormatted(object sender, DataGridViewCellFormattingEventArgs e)
{ {
var col = ((DataGridView)sender).Columns[e.ColumnIndex]; var col = ((DataGridView)sender).Columns[e.ColumnIndex];
if (col is DataGridViewTextBoxColumn textCol && GetGridEntry(e.RowIndex).TryDisplayValue(textCol.Name, out string value)) if (col is DataGridViewTextBoxColumn textCol && getGridEntry(e.RowIndex).TryDisplayValue(textCol.Name, out string value))
{
// DO NOT DO THIS: getCell(e).Value = value;
// it's the wrong way and will infinitely call CellFormatting on each assign
// this is the correct way. will actually set FormattedValue (and EditedFormattedValue) while leaving Value as-is for sorting
e.Value = value; e.Value = value;
getCell(e).ToolTipText = value;
}
} }
private void hiddenFormatting(object sender, DataGridViewCellFormattingEventArgs e) private void hiddenFormatting(object sender, DataGridViewCellFormattingEventArgs e)
@ -85,9 +93,9 @@ namespace LibationWinForms
if (e.RowIndex < 0 || dgv.Columns[e.ColumnIndex] is DataGridViewButtonColumn) if (e.RowIndex < 0 || dgv.Columns[e.ColumnIndex] is DataGridViewButtonColumn)
return; return;
var isHidden = GetGridEntry(e.RowIndex).TagsEnumerated.Contains("hidden"); var isHidden = getGridEntry(e.RowIndex).TagsEnumerated.Contains("hidden");
dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Style getCell(e).Style
= isHidden = isHidden
? new DataGridViewCellStyle { ForeColor = Color.LightGray } ? new DataGridViewCellStyle { ForeColor = Color.LightGray }
: dgv.DefaultCellStyle; : dgv.DefaultCellStyle;
@ -105,22 +113,66 @@ namespace LibationWinForms
private void liberate_Paint(object sender, DataGridViewCellPaintingEventArgs e) private void liberate_Paint(object sender, DataGridViewCellPaintingEventArgs e)
{ {
var dgv = (DataGridView)sender; if (!isColumnValid(e, LIBERATE))
if (!isColumnValid(dgv, e.RowIndex, e.ColumnIndex, LIBERATE))
return; return;
dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = GetGridEntry(e.RowIndex).Download_Status; var cell = getCell(e);
var gridEntry = getGridEntry(e.RowIndex);
var liberatedStatus = gridEntry.Liberated_Status;
var pdfStatus = gridEntry.Pdf_Status;
// mouseover text
{
var libState = liberatedStatus switch
{
GridEntry.LiberatedState.Liberated => "Liberated",
GridEntry.LiberatedState.DRM => "Downloaded but needs DRM removed",
GridEntry.LiberatedState.NotDownloaded => "Book NOT downloaded",
_ => throw new Exception("Unexpected liberation state")
};
var pdfState = pdfStatus switch
{
GridEntry.PdfState.Downloaded => "\r\nPDF downloaded",
GridEntry.PdfState.NotDownloaded => "\r\nPDF NOT downloaded",
GridEntry.PdfState.NoPdf => "",
_ => throw new Exception("Unexpected PDF state")
};
var text = libState + pdfState;
if (liberatedStatus == GridEntry.LiberatedState.NotDownloaded ||
liberatedStatus == GridEntry.LiberatedState.DRM ||
pdfStatus == GridEntry.PdfState.NotDownloaded)
text += "\r\nClick to complete";
//DEBUG//cell.Value = text;
cell.ToolTipText = text;
}
// draw img
{
var image_lib
= liberatedStatus == GridEntry.LiberatedState.NotDownloaded ? "red"
: liberatedStatus == GridEntry.LiberatedState.DRM ? "yellow"
: liberatedStatus == GridEntry.LiberatedState.Liberated ? "green"
: throw new Exception("Unexpected liberation state");
var image_pdf
= pdfStatus == GridEntry.PdfState.NoPdf ? ""
: pdfStatus == GridEntry.PdfState.NotDownloaded ? "_pdf_no"
: pdfStatus == GridEntry.PdfState.Downloaded ? "_pdf_yes"
: throw new Exception("Unexpected PDF state");
var image = (Bitmap)Properties.Resources.ResourceManager.GetObject($"liberate_{image_lib}{image_pdf}");
drawImage(e, image);
}
} }
private async void liberate_Click(object sender, DataGridViewCellEventArgs e) private async void liberate_Click(object sender, DataGridViewCellEventArgs e)
{ {
var dgv = (DataGridView)sender; if (!isColumnValid(e, LIBERATE))
if (!isColumnValid(dgv, e.RowIndex, e.ColumnIndex, LIBERATE))
return; return;
var productId = GetGridEntry(e.RowIndex).GetBook().AudibleProductId; var productId = getGridEntry(e.RowIndex).GetBook().AudibleProductId;
// if liberated, open explorer to file // if liberated, open explorer to file
if (FileManager.AudibleFileStorage.Audio.Exists(productId)) if (FileManager.AudibleFileStorage.Audio.Exists(productId))
@ -139,7 +191,7 @@ namespace LibationWinForms
public void RefreshRow(string productId) public void RefreshRow(string productId)
{ {
var rowId = GetRowId((ge) => ge.GetBook().AudibleProductId == productId); var rowId = getRowId((ge) => ge.GetBook().AudibleProductId == productId);
// update cells incl Liberate button text // update cells incl Liberate button text
dataGridView.InvalidateRow(rowId); dataGridView.InvalidateRow(rowId);
@ -160,33 +212,21 @@ namespace LibationWinForms
{ {
// DataGridView Image for Button Column: https://stackoverflow.com/a/36253883 // DataGridView Image for Button Column: https://stackoverflow.com/a/36253883
var dgv = (DataGridView)sender; if (!isColumnValid(e, EDIT_TAGS))
if (!isColumnValid(dgv, e.RowIndex, e.ColumnIndex, EDIT_TAGS))
return; return;
var displayTags = GetGridEntry(e.RowIndex).TagsEnumerated.ToList(); var cell = getCell(e);
var gridEntry = getGridEntry(e.RowIndex);
var cell = dgv.Rows[e.RowIndex].Cells[e.ColumnIndex]; var displayTags = gridEntry.TagsEnumerated.ToList();
if (displayTags.Any()) if (displayTags.Any())
cell.Value = string.Join("\r\n", displayTags); cell.Value = string.Join("\r\n", displayTags);
else // no tags: use image else
{ {
// clear tag text // if removing all tags: clear previous tag text
cell.Value = ""; cell.Value = "";
drawImage(e, Properties.Resources.edit_tags_25x25);
var image = Properties.Resources.edit_tags_25x25;
e.Paint(e.CellBounds, DataGridViewPaintParts.All);
var w = image.Width;
var h = image.Height;
var x = e.CellBounds.Left + (e.CellBounds.Width - w) / 2;
var y = e.CellBounds.Top + (e.CellBounds.Height - h) / 2;
e.Graphics.DrawImage(image, new Rectangle(x, y, w, h));
e.Handled = true;
} }
} }
@ -196,10 +236,10 @@ namespace LibationWinForms
var dgv = (DataGridView)sender; var dgv = (DataGridView)sender;
if (!isColumnValid(dgv, e.RowIndex, e.ColumnIndex, EDIT_TAGS)) if (!isColumnValid(e, EDIT_TAGS))
return; return;
var liveGridEntry = GetGridEntry(e.RowIndex); var liveGridEntry = getGridEntry(e.RowIndex);
// EditTagsDialog should display better-formatted title // EditTagsDialog should display better-formatted title
liveGridEntry.TryDisplayValue(nameof(liveGridEntry.Title), out string value); liveGridEntry.TryDisplayValue(nameof(liveGridEntry.Title), out string value);
@ -221,10 +261,25 @@ namespace LibationWinForms
} }
#endregion #endregion
private static bool isColumnValid(DataGridView dgv, int rowIndex, int colIndex, string colName) private static void drawImage(DataGridViewCellPaintingEventArgs e, Bitmap image)
{ {
var col = dgv.Columns[colIndex]; e.Paint(e.CellBounds, DataGridViewPaintParts.All);
return rowIndex >= 0 && col.HeaderText == colName && col is DataGridViewButtonColumn;
var w = image.Width;
var h = image.Height;
var x = e.CellBounds.Left + (e.CellBounds.Width - w) / 2;
var y = e.CellBounds.Top + (e.CellBounds.Height - h) / 2;
e.Graphics.DrawImage(image, new Rectangle(x, y, w, h));
e.Handled = true;
}
private bool isColumnValid(DataGridViewCellEventArgs e, string colName) => isColumnValid(e.RowIndex, e.ColumnIndex, colName);
private bool isColumnValid(DataGridViewCellPaintingEventArgs e, string colName) => isColumnValid(e.RowIndex, e.ColumnIndex, colName);
private bool isColumnValid(int rowIndex, int colIndex, string colName)
{
var col = dataGridView.Columns[colIndex];
return rowIndex >= 0 && col.Name == colName && col is DataGridViewButtonColumn;
} }
private void formatColumns() private void formatColumns()
@ -243,6 +298,7 @@ namespace LibationWinForms
col.Width = col.Name switch col.Width = col.Name switch
{ {
LIBERATE => 70,
nameof(GridEntry.Cover) => 80, nameof(GridEntry.Cover) => 80,
nameof(GridEntry.Title) => col.Width * 2, nameof(GridEntry.Title) => col.Width * 2,
nameof(GridEntry.Misc) => (int)(col.Width * 1.35), nameof(GridEntry.Misc) => (int)(col.Width * 1.35),
@ -263,7 +319,7 @@ namespace LibationWinForms
=> dataGridView.UIThread(() => updateRowImage(pictureId)); => dataGridView.UIThread(() => updateRowImage(pictureId));
private void updateRowImage(string pictureId) private void updateRowImage(string pictureId)
{ {
var rowId = GetRowId((ge) => ge.GetBook().PictureId == pictureId); var rowId = getRowId((ge) => ge.GetBook().PictureId == pictureId);
if (rowId > -1) if (rowId > -1)
dataGridView.InvalidateRow(rowId); dataGridView.InvalidateRow(rowId);
} }
@ -331,7 +387,7 @@ namespace LibationWinForms
currencyManager.SuspendBinding(); currencyManager.SuspendBinding();
{ {
for (var r = dataGridView.RowCount - 1; r >= 0; r--) for (var r = dataGridView.RowCount - 1; r >= 0; r--)
dataGridView.Rows[r].Visible = productIds.Contains(GetGridEntry(r).GetBook().AudibleProductId); dataGridView.Rows[r].Visible = productIds.Contains(getGridEntry(r).GetBook().AudibleProductId);
} }
currencyManager.ResumeBinding(); currencyManager.ResumeBinding();
VisibleCountChanged?.Invoke(this, dataGridView.AsEnumerable().Count(r => r.Visible)); VisibleCountChanged?.Invoke(this, dataGridView.AsEnumerable().Count(r => r.Visible));
@ -340,8 +396,14 @@ namespace LibationWinForms
} }
#endregion #endregion
private int GetRowId(Func<GridEntry, bool> func) => dataGridView.GetRowIdOfBoundItem(func); private int getRowId(Func<GridEntry, bool> func) => dataGridView.GetRowIdOfBoundItem(func);
private GridEntry GetGridEntry(int rowIndex) => dataGridView.GetBoundItem<GridEntry>(rowIndex); private GridEntry getGridEntry(int rowIndex) => dataGridView.GetBoundItem<GridEntry>(rowIndex);
}
private DataGridViewCell getCell(DataGridViewCellFormattingEventArgs e) => getCell(e.RowIndex, e.ColumnIndex);
private DataGridViewCell getCell(DataGridViewCellPaintingEventArgs e) => getCell(e.RowIndex, e.ColumnIndex);
private DataGridViewCell getCell(int rowIndex, int columnIndex) => dataGridView.Rows[rowIndex].Cells[columnIndex];
}
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 314 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 573 B