forked from gitextensions/gitextensions
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ fix crash and display default avatar when author email is null (because we have a bug in blame :( )
- Loading branch information
Showing
7 changed files
with
145 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Linq; | ||
using GitExtUtils.GitUI; | ||
using ICSharpCode.TextEditor; | ||
using Microsoft.VisualStudio.Threading; | ||
|
||
namespace GitUI.Editor | ||
{ | ||
/// <summary> | ||
/// This class display avatars in the gutter in a blame. | ||
/// </summary> | ||
public class BlameAuthorMargin : AbstractMargin | ||
{ | ||
private List<Image> _avatars; | ||
private readonly int _lineHeight; | ||
private readonly Color _backgroundColor; | ||
|
||
public BlameAuthorMargin(TextArea textArea) : base(textArea) | ||
{ | ||
_lineHeight = textArea.Font.Height + 1; | ||
_backgroundColor = ((SolidBrush)SystemBrushes.Window).Color; | ||
} | ||
|
||
public void SetAvatars(List<JoinableTask<Image>> avatars) | ||
{ | ||
_avatars = avatars.Select(a => ThreadHelper.JoinableTaskFactory.Run(async () => await a)).ToList(); | ||
|
||
// Update the resolution otherwise the image is not drawn at the good size :( | ||
foreach (var avatar in _avatars) | ||
{ | ||
if (avatar is Bitmap bitmapAvatar) | ||
{ | ||
bitmapAvatar.SetResolution(DpiUtil.DpiX, DpiUtil.DpiY); | ||
} | ||
} | ||
} | ||
|
||
public override int Width => _lineHeight; | ||
|
||
public override bool IsVisible => true; | ||
|
||
public override void Paint(Graphics g, Rectangle rect) | ||
{ | ||
if (rect.Width <= 0 || rect.Height <= 0) | ||
{ | ||
return; | ||
} | ||
|
||
g.Clear(_backgroundColor); | ||
|
||
if (_avatars == null || _avatars.Count == 0) | ||
{ | ||
return; | ||
} | ||
|
||
var verticalOffset = textArea.VirtualTop.Y; | ||
var lineStart = verticalOffset / _lineHeight; | ||
var negativeOffset = (lineStart * _lineHeight) - verticalOffset; | ||
var lineCount = (int)rect.Height / _lineHeight; | ||
|
||
for (int i = 0; i < lineCount; i++) | ||
{ | ||
if (lineStart + i >= _avatars.Count) | ||
{ | ||
break; | ||
} | ||
|
||
if (_avatars[lineStart + i] != null) | ||
{ | ||
g.DrawImage(_avatars[lineStart + i], new Point(0, negativeOffset + (i * _lineHeight))); | ||
} | ||
} | ||
|
||
base.Paint(g, rect); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters