Skip to content

Commit

Permalink
feat(RevisionGrid): enforce HashColumn max width to hash length (#11675)
Browse files Browse the repository at this point in the history
to make resizing more convenient (as it is a column size reset at each startup...)
+ fix bug on size of hash string when column size is exactly the good length
  • Loading branch information
pmiossec committed Apr 11, 2024
1 parent 5cb4489 commit 8a552ac
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ internal sealed class CommitIdColumnProvider : ColumnProvider
private readonly Dictionary<Font, int[]> _widthByLengthByFont = new(capacity: 4);
private readonly RevisionGridControl _grid;
private int? _charCount = null;
private readonly int _maxWidth = TextRenderer.MeasureText(GitRevision.WorkTreeGuid, AppSettings.MonospaceFont).Width;

public CommitIdColumnProvider(RevisionGridControl grid)
: base("Commit ID")
Expand Down Expand Up @@ -60,7 +61,7 @@ private int GetCharLengthForColumnWidth(int width)

public override void OnCellPainting(DataGridViewCellPaintingEventArgs e, GitRevision revision, int rowHeight, in CellStyle style)
{
if (e.FormattedValue is null)
if (string.IsNullOrWhiteSpace(e.FormattedValue as string))
{
return;
}
Expand All @@ -71,6 +72,15 @@ public override void OnCellPainting(DataGridViewCellPaintingEventArgs e, GitRevi
public override void OnColumnWidthChanged(DataGridViewColumnEventArgs e)
{
_charCount = GetCharLengthForColumnWidth(e.Column.Width);
if (e.Column.Width > _maxWidth && Column.DataGridView != null)
{
// Enforce from outside the current method because it is not allowed (exception thrown...)
Task.Run(async () =>
{
await Column.DataGridView!.SwitchToMainThreadAsync();
e.Column.Width = _maxWidth;
});
}
}

public override void OnCellFormatting(DataGridViewCellFormattingEventArgs e, GitRevision revision)
Expand Down

0 comments on commit 8a552ac

Please sign in to comment.