Skip to content

Commit

Permalink
Restore highlighting by author
Browse files Browse the repository at this point in the history
  • Loading branch information
RussKie committed Dec 27, 2018
1 parent 6855642 commit 89201d6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
9 changes: 7 additions & 2 deletions GitUI/UserControls/RevisionGrid/AuthorRevisionHighlighting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using GitCommands;
using GitCommands.Config;
using GitUIPluginInterfaces;
using JetBrains.Annotations;

namespace GitUI.UserControls
Expand All @@ -14,7 +15,7 @@ internal sealed class AuthorRevisionHighlighting

/// <returns><c>true</c> if the UI should be refreshed in response to this change.</returns>
[MustUseReturnValue]
public bool ProcessRevisionSelectionChange(GitModule currentModule, IReadOnlyCollection<GitRevision> selectedRevisions)
public bool ProcessRevisionSelectionChange(IGitModule currentModule, IReadOnlyCollection<GitRevision> selectedRevisions)
{
if (selectedRevisions.Count > 1)
{
Expand All @@ -24,7 +25,6 @@ public bool ProcessRevisionSelectionChange(GitModule currentModule, IReadOnlyCol
var revision = selectedRevisions.FirstOrDefault();

var changed = !string.Equals(revision?.AuthorEmail, AuthorEmailToHighlight, StringComparison.OrdinalIgnoreCase);

if (changed)
{
AuthorEmailToHighlight = revision != null
Expand All @@ -38,6 +38,11 @@ public bool ProcessRevisionSelectionChange(GitModule currentModule, IReadOnlyCol

public bool IsHighlighted([CanBeNull] GitRevision revision)
{
if (string.IsNullOrWhiteSpace(revision?.AuthorEmail))
{
return false;
}

return string.Equals(revision?.AuthorEmail, AuthorEmailToHighlight, StringComparison.OrdinalIgnoreCase);
}
}
Expand Down
16 changes: 12 additions & 4 deletions GitUI/UserControls/RevisionGrid/RevisionDataGridView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void OnRowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
e.RowBounds.Height > 0)
{
// Draw row background
var backBrush = GetBackground(e.State, e.RowIndex);
var backBrush = GetBackground(e.State, e.RowIndex, null);
e.Graphics.FillRectangle(backBrush, e.RowBounds);
}
}
Expand Down Expand Up @@ -176,6 +176,8 @@ internal Font NormalFont
}
}

internal AuthorRevisionHighlighting AuthorHighlighting { get; set; }

// Contains the object Id's that will be selected as soon as they are loaded.
public HashSet<ObjectId> ToBeSelectedObjectIds { get; set; } = new HashSet<ObjectId>();

Expand Down Expand Up @@ -238,19 +240,24 @@ private Color GetForeground(DataGridViewElementStates state, int rowIndex)
: Color.Black;
}

private static Brush GetBackground(DataGridViewElementStates state, int rowIndex)
private Brush GetBackground(DataGridViewElementStates state, int rowIndex, GitRevision revision)
{
if (state.HasFlag(DataGridViewElementStates.Selected))
{
return SystemBrushes.Highlight;
}

if (revision != null && !revision.IsArtificial && AuthorHighlighting.IsHighlighted(revision))
{
return Brushes.LightYellow;
}

if (rowIndex % 2 == 0 && AppSettings.RevisionGraphDrawAlternateBackColor)
{
return _alternatingRowBackgroundBrush;
}

return Brushes.White;
return SystemBrushes.Window;
}

private void OnCellPainting(object sender, DataGridViewCellPaintingEventArgs e)
Expand All @@ -269,9 +276,10 @@ private void OnCellPainting(object sender, DataGridViewCellPaintingEventArgs e)

if (Columns[e.ColumnIndex].Tag is ColumnProvider provider)
{
var backBrush = GetBackground(e.State, e.RowIndex);
var backBrush = GetBackground(e.State, e.RowIndex, revision);
var foreColor = GetForeground(e.State, e.RowIndex);

e.Graphics.FillRectangle(backBrush, e.CellBounds);
provider.OnCellPainting(e, revision, _rowHeight, new CellStyle(backBrush, foreColor, _normalFont, _boldFont, _monospaceFont));

e.Handled = true;
Expand Down
9 changes: 9 additions & 0 deletions GitUI/UserControls/RevisionGrid/RevisionGridControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public RevisionGridControl()
HotkeysEnabled = true;

_gridView.ShowCellToolTips = false;
_gridView.AuthorHighlighting = _authorHighlighting;

_gridView.KeyPress += (_, e) => _quickSearchProvider.OnKeyPress(e);
_gridView.KeyUp += OnGridViewKeyUp;
Expand Down Expand Up @@ -994,9 +995,12 @@ void OnRevisionReadCompleted()
ThreadHelper.JoinableTaskFactory.RunAsync(async () =>
{
await this.SwitchToMainThreadAsync();
SetPage(_gridView);
_isRefreshingRevisions = false;
CheckAndRepairInitialRevision();
HighlightRevisionsByAuthor(GetSelectedRevisions());
if (ShowBuildServerInfo)
{
await _buildServerWatcher.LaunchBuildServerInfoFetchOperationAsync();
Expand Down Expand Up @@ -1188,6 +1192,11 @@ private void OnGridViewSelectionChanged(object sender, EventArgs e)
compareWithCurrentBranchToolStripMenuItem.Enabled = Module.GetSelectedBranch(setDefaultIfEmpty: false).IsNotNullOrWhitespace();
compareSelectedCommitsMenuItem.Enabled = firstSelectedRevision != null && secondSelectedRevision != null;

HighlightRevisionsByAuthor(selectedRevisions);
}

private void HighlightRevisionsByAuthor(in IReadOnlyList<GitRevision> selectedRevisions)
{
if (Parent != null &&
!_gridView.UpdatingVisibleRows &&
_authorHighlighting.ProcessRevisionSelectionChange(Module, selectedRevisions))
Expand Down

0 comments on commit 89201d6

Please sign in to comment.