mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
feature: add a toggle button to change the commit time display mode to time period it is passed from now (#259)
This commit is contained in:
parent
9b21269844
commit
1eb77a5e49
5 changed files with 167 additions and 8 deletions
|
@ -5,6 +5,7 @@
|
|||
<StreamGeometry x:Key="Icons.Bookmark">M832 64H192c-18 0-32 14-32 32v832c0 18 14 32 32 32h640c18 0 32-14 32-32V96c0-18-14-32-32-32zM736 596 624 502 506 596V131h230v318z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.Branch">M757 226a143 143 0 00-55 276 96 96 0 01-88 59h-191a187 187 0 00-96 27V312a143 143 0 10-96 0v399a143 143 0 10103 2 96 96 0 0188-59h191a191 191 0 00187-151 143 143 0 00-43-279zM280 130a48 48 0 110 96 48 48 0 010-96zm0 764a48 48 0 110-96 48 48 0 010 96zM757 417a48 48 0 110-96 48 48 0 010 96z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.Branch.Add">M896 128h-64V64c0-35-29-64-64-64s-64 29-64 64v64h-64c-35 0-64 29-64 64s29 64 64 64h64v64c0 35 29 64 64 64s64-29 64-64V256h64c35 0 64-29 64-64s-29-64-64-64zm-204 307C673 481 628 512 576 512H448c-47 0-90 13-128 35V372C394 346 448 275 448 192c0-106-86-192-192-192S64 86 64 192c0 83 54 154 128 180v280c-74 26-128 97-128 180c0 106 86 192 192 192s192-86 192-192c0-67-34-125-84-159c22-20 52-33 84-33h128c122 0 223-85 249-199c-19 4-37 7-57 7c-26 0-51-5-76-13zM256 128c35 0 64 29 64 64s-29 64-64 64s-64-29-64-64s29-64 64-64zm0 768c-35 0-64-29-64-64s29-64 64-64s64 29 64 64s-29 64-64 64z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.Calender">M378 116l265 0 0 47-265 0 0-47ZM888 116 748 116l0 47 124 0c18 0 33 15 33 33l0 93L115 290l0-93c0-18 15-33 33-33l124 0 0-47L132 116c-35 0-64 29-64 64l0 714c0 35 29 64 64 64l757 0c35 0 64-29 64-64l-0-714C952 145 924 116 888 116zM905 337l0 540c0 18-15 33-33 33L148 910c-18 0-33-15-33-33L115 337 905 337zM301 65l47 0 0 170-47 0 0-170ZM673 65l47 0 0 170-47 0 0-170ZM358 548l0 231 53 0L411 459l-35 0-3 4c-18 26-41 49-70 68l-4 3 0 54 13-8C331 569 346 559 358 548zM618 727c-10 6-24 8-42 5-16-3-28-18-35-46l-2-9-48 13 2 8c6 30 18 52 36 65 17 13 36 20 55 21 3 0 7 0 10 0 15 0 28-2 40-7 14-6 27-13 37-23 10-10 18-22 23-37 5-14 8-28 8-42 1-14-1-27-4-39l-0-0c-3-12-8-24-15-36-7-13-19-23-35-30-15-7-31-11-47-11-11-0-23 1-36 5 4-15 8-32 11-52l114 0 0-49L536 464l-1 7c-25 116-32 145-33 150l-3 10 46 5 3-4c8-11 18-18 31-21 13-3 25-3 35-0 10 3 18 9 24 18 7 9 10 20 11 34 1 14-2 26-6 37C636 711 629 720 618 727z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.Check">M512 597m-1 0a1 1 0 103 0a1 1 0 10-3 0ZM810 393 732 315 448 600 293 444 214 522l156 156 78 78 362-362z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.CherryPick">M529 511c115 0 212 79 239 185h224a62 62 0 017 123l-7 0-224 0a247 247 0 01-479 0H65a62 62 0 01-7-123l7-0h224a247 247 0 01239-185zm0 124a124 124 0 100 247 124 124 0 000-247zm0-618c32 0 58 24 61 55l0 7V206c89 11 165 45 225 103a74 74 0 0122 45l0 9v87a62 62 0 01-123 7l-0-7v-65l-6-4c-43-33-97-51-163-53l-17-0c-74 0-133 18-180 54l-6 4v65a62 62 0 01-55 61l-7 0a62 62 0 01-61-55l-0-7V362c0-20 8-39 23-53 60-58 135-92 224-103V79c0-34 28-62 62-62z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.Clear">M512 57c251 0 455 204 455 455S763 967 512 967 57 763 57 512 261 57 512 57zm181 274c-11-11-29-11-40 0L512 472 371 331c-11-11-29-11-40 0-11 11-11 29 0 40L471 512 331 653c-11 11-11 29 0 40 11 11 29 11 40 0l141-141 141 141c11 11 29 11 40 0 11-11 11-29 0-40L552 512l141-141c11-11 11-29 0-40z</StreamGeometry>
|
||||
|
@ -83,6 +84,7 @@
|
|||
<StreamGeometry x:Key="Icons.SquashIntoParent">M512 939C465 939 427 900 427 853 427 806 465 768 512 768 559 768 597 806 597 853 597 900 559 939 512 939M555 85 555 555 747 363 807 423 512 719 217 423 277 363 469 555 469 85 555 85Z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.Stashes">M961 320 512 577 63 320 512 62l449 258zM512 628 185 442 63 512 512 770 961 512l-123-70L512 628zM512 821 185 634 63 704 512 962l449-258L839 634 512 821z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.Statistics">M447 561a26 26 0 0126 26v171H421v-171a26 26 0 0126-26zm-98 65a26 26 0 0126 26v104H323v-104a26 26 0 0126-26zm0 0M561 268a32 32 0 0132 30v457h-65V299a32 32 0 0132-32zm0 0M675 384a26 26 0 0126 26v348H649v-350a26 26 0 0126-24zm0 0M801 223v579H223V223h579M805 171H219A49 49 0 00171 219v585A49 49 0 00219 853h585A49 49 0 00853 805V219A49 49 0 00805 171z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.Stopwatch">M576 160H448c-18 0-32-14-32-32s14-32 32-32h128c18 0 32 14 32 32s-14 32-32 32zm243 186 36-36c13-13 13-33 0-45s-33-13-45 0l-33 33C708 233 614 192 512 192c-212 0-384 172-384 384s172 384 384 384 384-172 384-384c0-86-29-166-77-230zM544 894V864c0-18-14-32-32-32s-32 14-32 32v30C329 879 209 759 194 608H224c18 0 32-14 32-32s-14-32-32-32h-30C209 393 329 273 480 258V288c0 18 14 32 32 32s32-14 32-32v-30C695 273 815 393 830 544H800c-18 0-32 14-32 32s14 32 32 32h30C815 759 695 879 544 894zm108-471-160 128c-14 11-16 31-5 45 6 8 16 12 25 12 7 0 14-2 20-7l160-128c14-11 16-31 5-45-11-14-31-16-45-5z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.Submodule">M557.7 545.3 789.9 402.7c24-15 31.3-46.5 16.4-70.5c-14.8-23.8-46-31.2-70-16.7L506.5 456.6 277.1 315.4c-24.1-14.8-55.6-7.3-70.5 16.8c-14.8 24.1-7.3 55.6 16.8 70.5l231.8 142.6V819.1c0 28.3 22.9 51.2 51.2 51.2c28.3 0 51.2-22.9 51.2-51.2V545.3h.1zM506.5 0l443.4 256v511.9L506.5 1023.9 63.1 767.9v-511.9L506.5 0z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.Submodule.Add">M770 320a41 41 0 00-56-14l-252 153L207 306a41 41 0 10-43 70l255 153 2 296a41 41 0 0082 0l-2-295 255-155a41 41 0 0014-56zM481 935a42 42 0 01-42 0L105 741a42 42 0 01-21-36v-386a42 42 0 0121-36L439 89a42 42 0 0142 0l335 193a42 42 0 0121 36v87h84v-87a126 126 0 00-63-109L523 17a126 126 0 00-126 0L63 210a126 126 0 00-63 109v386a126 126 0 0063 109l335 193a126 126 0 00126 0l94-54-42-72zM1029 700h-126v-125a42 42 0 00-84 0v126h-126a42 42 0 000 84h126v126a42 42 0 1084 0v-126h126a42 42 0 000-84z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.SyntaxHighlight">M875 128h-725A107 107 0 0043 235v555A107 107 0 00149 896h725a107 107 0 00107-107v-555A107 107 0 00875 128zm-115 640h-183v-58l25-3c15 0 19-8 14-24l-22-61H419l-28 82 39 2V768h-166v-58l18-3c18-2 22-11 26-24l125-363-40-4V256h168l160 448 39 3zM506 340l-72 218h145l-71-218h-2z</StreamGeometry>
|
||||
|
|
|
@ -1099,6 +1099,31 @@
|
|||
</Style>
|
||||
</Style>
|
||||
|
||||
<Style Selector="ToggleButton.time_display_mode">
|
||||
<Setter Property="Margin" Value="0" />
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate>
|
||||
<Border Background="Transparent"
|
||||
Width="{TemplateBinding Width}"
|
||||
Height="{TemplateBinding Height}"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center">
|
||||
<Path x:Name="ChevronPath"
|
||||
Data="{StaticResource Icons.Calender}"
|
||||
Fill="{DynamicResource TreeViewItemForeground}"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Opacity="0.65"/>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
|
||||
<Style Selector="^:checked /template/ Path#ChevronPath">
|
||||
<Setter Property="Data" Value="{StaticResource Icons.Stopwatch}" />
|
||||
</Style>
|
||||
</Style>
|
||||
|
||||
<Style Selector="ToggleButton.folder">
|
||||
<Setter Property="Margin" Value="0" />
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
|
|
|
@ -159,6 +159,12 @@ namespace SourceGit.ViewModels
|
|||
set => SetProperty(ref _useTwoColumnsLayoutInHistories, value);
|
||||
}
|
||||
|
||||
public bool DisplayTimeAsPeriodInHistories
|
||||
{
|
||||
get => _displayTimeAsPeriodInHistories;
|
||||
set => SetProperty(ref _displayTimeAsPeriodInHistories, value);
|
||||
}
|
||||
|
||||
public bool UseSideBySideDiff
|
||||
{
|
||||
get => _useSideBySideDiff;
|
||||
|
@ -494,6 +500,7 @@ namespace SourceGit.ViewModels
|
|||
private bool _check4UpdatesOnStartup = true;
|
||||
|
||||
private bool _useTwoColumnsLayoutInHistories = false;
|
||||
private bool _displayTimeAsPeriodInHistories = false;
|
||||
private bool _useSideBySideDiff = false;
|
||||
private bool _useSyntaxHighlighting = false;
|
||||
private bool _enableDiffViewWordWrap = false;
|
||||
|
|
|
@ -155,18 +155,24 @@
|
|||
|
||||
<DataGridTemplateColumn CanUserResize="False" MinWidth="156">
|
||||
<DataGridTemplateColumn.Header>
|
||||
<TextBlock Classes="table_header" Text="{DynamicResource Text.Histories.Header.Time}"/>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<ToggleButton Classes="time_display_mode"
|
||||
Width="10" Height="10"
|
||||
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=DisplayTimeAsPeriodInHistories, Mode=TwoWay}"/>
|
||||
<TextBlock Classes="table_header" Margin="4,0,0,0" Text="{DynamicResource Text.Histories.Header.Time}"/>
|
||||
</StackPanel>
|
||||
|
||||
</DataGridTemplateColumn.Header>
|
||||
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate x:DataType="{x:Type m:Commit}">
|
||||
<Border Background="Transparent" ToolTip.Tip="{Binding CommitterTimeFromNowString}">
|
||||
<TextBlock Classes="monospace"
|
||||
Text="{Binding CommitterTimeStr}"
|
||||
<v:CommitTimeTextBlock Classes="monospace"
|
||||
Margin="8,0"
|
||||
HorizontalAlignment="Center"
|
||||
Opacity="{Binding IsMerged, Converter={x:Static c:BoolConverters.HalfIfFalse}}"
|
||||
FontWeight="{Binding IsCurrentHead, Converter={x:Static c:BoolConverters.BoldIfTrue}}"/>
|
||||
</Border>
|
||||
FontWeight="{Binding IsCurrentHead, Converter={x:Static c:BoolConverters.BoldIfTrue}}"
|
||||
Timestamp="{Binding CommitterTime}"
|
||||
ShowAsDateTime="{Binding Source={x:Static vm:Preference.Instance}, Path=!DisplayTimeAsPeriodInHistories}"/>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
|
|
@ -3,7 +3,9 @@ using System;
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Threading;
|
||||
using Avalonia.VisualTree;
|
||||
|
||||
namespace SourceGit.Views
|
||||
|
@ -67,6 +69,123 @@ namespace SourceGit.Views
|
|||
}
|
||||
}
|
||||
|
||||
public class CommitTimeTextBlock : TextBlock
|
||||
{
|
||||
public static readonly StyledProperty<bool> ShowAsDateTimeProperty =
|
||||
AvaloniaProperty.Register<CommitTimeTextBlock, bool>(nameof(ShowAsDateTime), true);
|
||||
|
||||
public bool ShowAsDateTime
|
||||
{
|
||||
get => GetValue(ShowAsDateTimeProperty);
|
||||
set => SetValue(ShowAsDateTimeProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<ulong> TimestampProperty =
|
||||
AvaloniaProperty.Register<CommitTimeTextBlock, ulong>(nameof(Timestamp));
|
||||
|
||||
public ulong Timestamp
|
||||
{
|
||||
get => GetValue(TimestampProperty);
|
||||
set => SetValue(TimestampProperty, value);
|
||||
}
|
||||
|
||||
protected override Type StyleKeyOverride => typeof(TextBlock);
|
||||
|
||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
||||
{
|
||||
base.OnPropertyChanged(change);
|
||||
|
||||
if (change.Property == TimestampProperty)
|
||||
{
|
||||
SetCurrentValue(TextProperty, GetDisplayText());
|
||||
}
|
||||
else if (change.Property == ShowAsDateTimeProperty)
|
||||
{
|
||||
SetCurrentValue(TextProperty, GetDisplayText());
|
||||
|
||||
if (ShowAsDateTime)
|
||||
StopTimer();
|
||||
else
|
||||
StartTimer();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnLoaded(RoutedEventArgs e)
|
||||
{
|
||||
base.OnLoaded(e);
|
||||
|
||||
if (!ShowAsDateTime)
|
||||
StartTimer();
|
||||
}
|
||||
|
||||
protected override void OnUnloaded(RoutedEventArgs e)
|
||||
{
|
||||
base.OnUnloaded(e);
|
||||
StopTimer();
|
||||
}
|
||||
|
||||
private void StartTimer()
|
||||
{
|
||||
if (_refreshTimer != null)
|
||||
return;
|
||||
|
||||
_refreshTimer = DispatcherTimer.Run(() =>
|
||||
{
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
var text = GetDisplayText();
|
||||
if (!text.Equals(Text, StringComparison.Ordinal))
|
||||
Text = text;
|
||||
});
|
||||
|
||||
return true;
|
||||
}, TimeSpan.FromSeconds(4));
|
||||
}
|
||||
|
||||
private void StopTimer()
|
||||
{
|
||||
if (_refreshTimer != null)
|
||||
{
|
||||
_refreshTimer.Dispose();
|
||||
_refreshTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
private string GetDisplayText()
|
||||
{
|
||||
if (ShowAsDateTime)
|
||||
return DateTime.UnixEpoch.AddSeconds(Timestamp).ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss");
|
||||
|
||||
var today = DateTime.Today;
|
||||
var committerTime = DateTime.UnixEpoch.AddSeconds(Timestamp).ToLocalTime();
|
||||
|
||||
if (committerTime >= today)
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
var timespan = now - committerTime;
|
||||
if (timespan.TotalHours > 1)
|
||||
return $"{(int)timespan.TotalHours} hours ago";
|
||||
|
||||
return timespan.TotalMinutes < 1 ? "Just now" : $"{(int)timespan.TotalMinutes} minutes ago";
|
||||
}
|
||||
|
||||
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;
|
||||
return diffDay == 1 ? "Yesterday" : $"{diffDay} days ago";
|
||||
}
|
||||
|
||||
return diffYear == 1 ? "Last year" : $"{diffYear} years ago";
|
||||
}
|
||||
|
||||
private IDisposable _refreshTimer = null;
|
||||
}
|
||||
|
||||
public class CommitGraph : Control
|
||||
{
|
||||
public static readonly StyledProperty<Models.CommitGraph> GraphProperty =
|
||||
|
|
Loading…
Reference in a new issue