mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57: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 IsCommitterVisible => !Author.Equals(Committer) || AuthorTime != CommitterTime;
|
||||||
public bool IsCurrentHead => Decorators.Find(x => x.Type is DecoratorType.CurrentBranchHead or DecoratorType.CurrentCommitHead) != null;
|
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>
|
<DataGridTemplateColumn.CellTemplate>
|
||||||
<DataTemplate x:DataType="{x:Type m:Commit}">
|
<DataTemplate x:DataType="{x:Type m:Commit}">
|
||||||
|
<Border Background="Transparent" ToolTip.Tip="{Binding CommitterTimeFromNowString}">
|
||||||
<TextBlock Classes="monospace"
|
<TextBlock Classes="monospace"
|
||||||
Text="{Binding CommitterTimeStr}"
|
Text="{Binding CommitterTimeStr}"
|
||||||
Margin="8,0"
|
Margin="8,0"
|
||||||
Opacity="{Binding IsMerged, Converter={x:Static c:BoolConverters.HalfIfFalse}}"
|
Opacity="{Binding IsMerged, Converter={x:Static c:BoolConverters.HalfIfFalse}}"
|
||||||
FontWeight="{Binding IsCurrentHead, Converter={x:Static c:BoolConverters.BoldIfTrue}}"/>
|
FontWeight="{Binding IsCurrentHead, Converter={x:Static c:BoolConverters.BoldIfTrue}}"/>
|
||||||
|
</Border>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</DataGridTemplateColumn.CellTemplate>
|
</DataGridTemplateColumn.CellTemplate>
|
||||||
</DataGridTemplateColumn>
|
</DataGridTemplateColumn>
|
||||||
|
|
Loading…
Reference in a new issue