Skip to content

Commit

Permalink
asynchrofy the async validation of favorites
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn committed Jul 7, 2024
1 parent 52cb64e commit 5a4420e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
5 changes: 3 additions & 2 deletions OneMore/Commands/Favorites/FavoritesDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,16 @@ private void ValidateOnCellFormatting(object sender, DataGridViewCellFormattingE
gridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ToolTipText =
Resx.Favorites_unknown;

e.CellStyle.BackColor = Color.Pink;
e.CellStyle.ForeColor = manager.GetColor("ErrorText");
e.FormattingApplied = true;
}
else if (favorite.Status == FavoriteStatus.Suspect)
{
gridView.Rows[e.RowIndex].Cells[e.ColumnIndex].ToolTipText =
Resx.Favorites_suspect;

e.CellStyle.BackColor = Color.LightGoldenrodYellow;
e.CellStyle.BackColor = manager.GetColor("Info");
e.CellStyle.ForeColor = manager.GetColor("InfoText");
e.FormattingApplied = true;
}
}
Expand Down
26 changes: 16 additions & 10 deletions OneMore/Commands/Settings/FavoritesSheet.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion OneMore/Commands/Settings/FavoritesSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ internal partial class FavoritesSheet : SheetBase
private readonly IRibbonUI ribbon;
private readonly bool shortcuts;
private BindingList<Favorite> favorites;
private Task validator;
private bool updated = false;


Expand Down Expand Up @@ -65,13 +66,30 @@ private async void LoadData(object sender, EventArgs e)

await using var provider = new FavoritesProvider(null);
var list = provider.LoadFavorites();
await provider.ValidateFavorites(list);

// capture Task so it can be completed later in RowEnter
validator = provider.ValidateFavorites(list);

favorites = new BindingList<Favorite>(list);

gridView.DataSource = favorites;
}


private async void FinishValidationOnRowEnter(object sender, DataGridViewCellEventArgs e)
{
// executed once (by unsetting 'validator') to update the data source binding
// after validation is completed

if (validator is not null)
{
await Task.WhenAll(validator);
validator = null;
favorites.ResetBindings();
}
}


private void FormatCell(object sender, DataGridViewCellFormattingEventArgs e)
{
if (gridView.Rows[e.RowIndex].DataBoundItem is Favorite favorite)
Expand Down

0 comments on commit 5a4420e

Please sign in to comment.