mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-22 20:37:19 -08:00
feature: add tooltip for commit time that shows how much time it is from now (#259)
* this tooltip does NOT update until it's owner row recreated or the DataContext of that row changed. You can scroll it out of bounds to force refresh the tooltip
This commit is contained in:
parent
684fedb9bd
commit
dc407b6033
2 changed files with 48 additions and 5 deletions
|
@ -25,5 +25,46 @@ namespace SourceGit.Models
|
|||
|
||||
public bool IsCommitterVisible => !Author.Equals(Committer) || AuthorTime != CommitterTime;
|
||||
public bool IsCurrentHead => Decorators.Find(x => x.Type is DecoratorType.CurrentBranchHead or DecoratorType.CurrentCommitHead) != null;
|
||||
|
||||
public string CommitterTimeFromNowString
|
||||
{
|
||||
get
|
||||
{
|
||||
var today = DateTime.Today;
|
||||
var committerTime = DateTime.UnixEpoch.AddSeconds(CommitterTime).ToLocalTime();
|
||||
|
||||
if (committerTime >= today)
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
var timespan = now - committerTime;
|
||||
if (timespan.TotalHours > 1)
|
||||
return $"{(int)timespan.TotalHours} hours ago";
|
||||
|
||||
if (timespan.TotalMinutes > 1)
|
||||
return $"{(int)timespan.TotalMinutes} minutes ago";
|
||||
|
||||
return $"Just now";
|
||||
}
|
||||
|
||||
var diffYear = today.Year - committerTime.Year;
|
||||
if (diffYear == 0)
|
||||
{
|
||||
var diffMonth = today.Month - committerTime.Month;
|
||||
if (diffMonth > 0)
|
||||
return diffMonth == 1 ? "Last month" : $"{diffMonth} months ago";
|
||||
|
||||
var diffDay = today.Day - committerTime.Day;
|
||||
if (diffDay > 0)
|
||||
return diffDay == 1 ? "Yesterday" : $"{diffDay} days ago";
|
||||
|
||||
return "Today";
|
||||
}
|
||||
|
||||
if (diffYear == 1)
|
||||
return "Last year";
|
||||
|
||||
return $"{diffYear} years ago";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -160,11 +160,13 @@
|
|||
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate x:DataType="{x:Type m:Commit}">
|
||||
<TextBlock Classes="monospace"
|
||||
Text="{Binding CommitterTimeStr}"
|
||||
Margin="8,0"
|
||||
Opacity="{Binding IsMerged, Converter={x:Static c:BoolConverters.HalfIfFalse}}"
|
||||
FontWeight="{Binding IsCurrentHead, Converter={x:Static c:BoolConverters.BoldIfTrue}}"/>
|
||||
<Border Background="Transparent" ToolTip.Tip="{Binding CommitterTimeFromNowString}">
|
||||
<TextBlock Classes="monospace"
|
||||
Text="{Binding CommitterTimeStr}"
|
||||
Margin="8,0"
|
||||
Opacity="{Binding IsMerged, Converter={x:Static c:BoolConverters.HalfIfFalse}}"
|
||||
FontWeight="{Binding IsCurrentHead, Converter={x:Static c:BoolConverters.BoldIfTrue}}"/>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
|
Loading…
Reference in a new issue