forked from gitextensions/gitextensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommitSummaryUserControl.cs
111 lines (98 loc) · 4.3 KB
/
CommitSummaryUserControl.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
using System.Drawing;
using System.Linq;
using GitCommands;
using ResourceManager;
namespace GitUI.UserControls
{
/// <summary>
/// TODO: replace with some better looking RTF control (similar to Commit Tab in main window)
/// Tried RichTextBox: strangely it does not show any formatting, just plain text.
/// </summary>
public partial class CommitSummaryUserControl : GitExtensionsControl
{
private readonly TranslationString _noRevision = new TranslationString("No revision");
private readonly TranslationString _notAvailable = new TranslationString("n/a");
private readonly string _tagsCaption;
private readonly string _branchesCaption;
private readonly Color _tagsBackColor = Color.LightSteelBlue;
private readonly Color _branchesBackColor = Color.LightSalmon;
public CommitSummaryUserControl()
{
InitializeComponent();
Translate();
_tagsCaption = labelTagsCaption.Text;
_branchesCaption = labelBranchesCaption.Text;
_messageY = labelMessage.Location.Y;
_messageHeight = labelMessage.Height;
labelMessage.AutoSize = true;
}
private GitRevision _revision;
private readonly int _messageY;
private readonly int _messageHeight;
public GitRevision Revision
{
get
{
return _revision;
}
set
{
_revision = value;
labelAuthorCaption.Text = Strings.GetAuthorText() + ":";
labelTagsCaption.Text = _tagsCaption;
labelBranchesCaption.Text = _branchesCaption;
if (Revision != null)
{
groupBox1.Text = Revision.Guid.Substring(0, 10);
labelAuthor.Text = string.Format("{0}", Revision.Author);
labelDate.Text = string.Format(Strings.GetCommitDateText() + ": {0}", Revision.CommitDate);
labelMessage.Text = string.Format("{0}", Revision.Message);
var tagList = Revision.Refs.Where(r => r.IsTag).ToList();
string tagListStr = string.Join(", ", tagList.Select(h => h.LocalName).ToArray());
labelTags.Text = string.Format("{0}", tagListStr.IsNullOrEmpty() ? _notAvailable.Text : tagListStr);
if (tagList.Any())
{
labelTags.BackColor = _tagsBackColor;
}
else
{
labelTags.Font = new Font(labelTags.Font, FontStyle.Regular);
}
var branchesList = Revision.Refs.Where(r => r.IsHead).ToList();
string branchesListStr = string.Join(", ", branchesList.Select(h => h.LocalName).ToArray());
labelBranches.Text = string.Format("{0}", branchesListStr.IsNullOrEmpty() ? _notAvailable.Text : branchesListStr);
if (branchesList.Any())
{
labelBranches.BackColor = _branchesBackColor;
}
else
{
labelBranches.Font = new Font(labelBranches.Font, FontStyle.Regular);
}
}
else
{
groupBox1.Text = _noRevision.Text;
labelAuthor.Text = "---";
labelDate.Text = "---";
labelMessage.Text = "---";
labelTags.Text = "---";
labelTags.BackColor = DefaultBackColor;
labelBranches.Text = "---";
labelBranches.BackColor = DefaultBackColor;
}
}
}
private void labelMessage_SizeChanged(object sender, EventArgs e)
{
labelMessage.Location = new Point(
labelMessage.Location.X,
(int)(_messageY + _messageHeight / 2.0 - labelMessage.Height / 2.0));
}
private void groupBox1_Resize(object sender, EventArgs e)
{
labelMessage.MaximumSize = new Size(groupBox1.Width - 15, labelMessage.MaximumSize.Height);
}
}
}