mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2025-01-11 23:57:21 -08:00
feature: allows to change DateTime
format (#755)
This commit is contained in:
parent
dc649e6142
commit
c058b4744b
12 changed files with 118 additions and 37 deletions
|
@ -65,7 +65,7 @@ namespace SourceGit.Commands
|
|||
var commit = match.Groups[1].Value;
|
||||
var author = match.Groups[2].Value;
|
||||
var timestamp = int.Parse(match.Groups[3].Value);
|
||||
var when = DateTime.UnixEpoch.AddSeconds(timestamp).ToLocalTime().ToString("yyyy/MM/dd");
|
||||
var when = DateTime.UnixEpoch.AddSeconds(timestamp).ToLocalTime().ToString(_dateFormat);
|
||||
|
||||
var info = new Models.BlameLineInfo()
|
||||
{
|
||||
|
@ -87,6 +87,7 @@ namespace SourceGit.Commands
|
|||
|
||||
private readonly Models.BlameData _result = new Models.BlameData();
|
||||
private readonly StringBuilder _content = new StringBuilder();
|
||||
private readonly string _dateFormat = Models.DateTimeFormat.Actived.DateOnly;
|
||||
private string _lastSHA = string.Empty;
|
||||
private bool _needUnifyCommitSHA = false;
|
||||
private int _minSHALen = 64;
|
||||
|
|
|
@ -31,9 +31,9 @@ namespace SourceGit.Models
|
|||
public List<Decorator> Decorators { get; set; } = new List<Decorator>();
|
||||
public bool HasDecorators => Decorators.Count > 0;
|
||||
|
||||
public string AuthorTimeStr => DateTime.UnixEpoch.AddSeconds(AuthorTime).ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss");
|
||||
public string CommitterTimeStr => DateTime.UnixEpoch.AddSeconds(CommitterTime).ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss");
|
||||
public string AuthorTimeShortStr => DateTime.UnixEpoch.AddSeconds(AuthorTime).ToLocalTime().ToString("yyyy/MM/dd");
|
||||
public string AuthorTimeStr => DateTime.UnixEpoch.AddSeconds(AuthorTime).ToLocalTime().ToString(DateTimeFormat.Actived.DateTime);
|
||||
public string CommitterTimeStr => DateTime.UnixEpoch.AddSeconds(CommitterTime).ToLocalTime().ToString(DateTimeFormat.Actived.DateTime);
|
||||
public string AuthorTimeShortStr => DateTime.UnixEpoch.AddSeconds(AuthorTime).ToLocalTime().ToString(DateTimeFormat.Actived.DateOnly);
|
||||
|
||||
public bool IsMerged { get; set; } = false;
|
||||
public bool IsCommitterVisible => !Author.Equals(Committer) || AuthorTime != CommitterTime;
|
||||
|
|
45
src/Models/DateTimeFormat.cs
Normal file
45
src/Models/DateTimeFormat.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace SourceGit.Models
|
||||
{
|
||||
public class DateTimeFormat
|
||||
{
|
||||
public string DisplayText { get; set; }
|
||||
public string DateOnly { get; set; }
|
||||
public string DateTime { get; set; }
|
||||
|
||||
public DateTimeFormat(string displayText, string dateOnly, string dateTime)
|
||||
{
|
||||
DisplayText = displayText;
|
||||
DateOnly = dateOnly;
|
||||
DateTime = dateTime;
|
||||
}
|
||||
|
||||
public static int ActiveIndex
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = 0;
|
||||
|
||||
public static DateTimeFormat Actived
|
||||
{
|
||||
get => Supported[ActiveIndex];
|
||||
}
|
||||
|
||||
public static readonly List<DateTimeFormat> Supported = new List<DateTimeFormat>
|
||||
{
|
||||
new DateTimeFormat("2025/01/31 08:00:00", "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss"),
|
||||
new DateTimeFormat("2025.01.31 08:00:00", "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss"),
|
||||
new DateTimeFormat("2025-01-31 08:00:00", "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss"),
|
||||
new DateTimeFormat("01/31/2025 08:00:00", "MM/dd/yyyy", "MM/dd/yyyy HH:mm:ss"),
|
||||
new DateTimeFormat("01.31.2025 08:00:00", "MM.dd.yyyy", "MM.dd.yyyy HH:mm:ss"),
|
||||
new DateTimeFormat("01-31-2025 08:00:00", "MM-dd-yyyy", "MM-dd-yyyy HH:mm:ss"),
|
||||
new DateTimeFormat("31/01/2025 08:00:00", "dd/MM/yyyy", "dd/MM/yyyy HH:mm:ss"),
|
||||
new DateTimeFormat("31.01.2025 08:00:00", "dd.MM.yyyy", "dd.MM.yyyy HH:mm:ss"),
|
||||
new DateTimeFormat("31-01-2025 08:00:00", "dd-MM-yyyy", "dd-MM-yyyy HH:mm:ss"),
|
||||
|
||||
new DateTimeFormat("Jun 31 2025 08:00:00", "MMM d yyyy", "MMM d yyyy HH:mm:ss"),
|
||||
new DateTimeFormat("31 Jun 2025 08:00:00", "d MMM yyyy", "d MMM yyyy HH:mm:ss"),
|
||||
};
|
||||
}
|
||||
}
|
|
@ -9,6 +9,6 @@ namespace SourceGit.Models
|
|||
public ulong Time { get; set; } = 0;
|
||||
public string Message { get; set; } = "";
|
||||
|
||||
public string TimeStr => DateTime.UnixEpoch.AddSeconds(Time).ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss");
|
||||
public string TimeStr => DateTime.UnixEpoch.AddSeconds(Time).ToLocalTime().ToString(DateTimeFormat.Actived.DateTime);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -465,6 +465,7 @@
|
|||
<x:String x:Key="Text.Preference.DiffMerge.Type" xml:space="preserve">Tool</x:String>
|
||||
<x:String x:Key="Text.Preference.General" xml:space="preserve">GENERAL</x:String>
|
||||
<x:String x:Key="Text.Preference.General.Check4UpdatesOnStartup" xml:space="preserve">Check for updates on startup</x:String>
|
||||
<x:String x:Key="Text.Preference.General.DateFormat" xml:space="preserve">Date Format</x:String>
|
||||
<x:String x:Key="Text.Preference.General.Locale" xml:space="preserve">Language</x:String>
|
||||
<x:String x:Key="Text.Preference.General.MaxHistoryCommits" xml:space="preserve">History Commits</x:String>
|
||||
<x:String x:Key="Text.Preference.General.ShowAuthorTime" xml:space="preserve">Show author time instead of commit time in graph</x:String>
|
||||
|
|
|
@ -469,6 +469,7 @@
|
|||
<x:String x:Key="Text.Preference.DiffMerge.Type" xml:space="preserve">工具</x:String>
|
||||
<x:String x:Key="Text.Preference.General" xml:space="preserve">通用配置</x:String>
|
||||
<x:String x:Key="Text.Preference.General.Check4UpdatesOnStartup" xml:space="preserve">启动时检测软件更新</x:String>
|
||||
<x:String x:Key="Text.Preference.General.DateFormat" xml:space="preserve">日期时间格式</x:String>
|
||||
<x:String x:Key="Text.Preference.General.Locale" xml:space="preserve">显示语言</x:String>
|
||||
<x:String x:Key="Text.Preference.General.MaxHistoryCommits" xml:space="preserve">最大历史提交数</x:String>
|
||||
<x:String x:Key="Text.Preference.General.ShowAuthorTime" xml:space="preserve">在提交路线图中显示修改时间而非提交时间</x:String>
|
||||
|
|
|
@ -468,6 +468,7 @@
|
|||
<x:String x:Key="Text.Preference.DiffMerge.Type" xml:space="preserve">工具</x:String>
|
||||
<x:String x:Key="Text.Preference.General" xml:space="preserve">一般設定</x:String>
|
||||
<x:String x:Key="Text.Preference.General.Check4UpdatesOnStartup" xml:space="preserve">啟動時檢查軟體更新</x:String>
|
||||
<x:String x:Key="Text.Preference.General.DateFormat" xml:space="preserve">日期時間格式</x:String>
|
||||
<x:String x:Key="Text.Preference.General.Locale" xml:space="preserve">顯示語言</x:String>
|
||||
<x:String x:Key="Text.Preference.General.MaxHistoryCommits" xml:space="preserve">最大歷史提交數</x:String>
|
||||
<x:String x:Key="Text.Preference.General.ShowAuthorTime" xml:space="preserve">在提交路線圖中顯示修改時間而非提交時間</x:String>
|
||||
|
|
|
@ -129,6 +129,21 @@ namespace SourceGit.ViewModels
|
|||
set => SetProperty(ref _subjectGuideLength, value);
|
||||
}
|
||||
|
||||
public int DateTimeFormat
|
||||
{
|
||||
get => Models.DateTimeFormat.ActiveIndex;
|
||||
set
|
||||
{
|
||||
if (value != Models.DateTimeFormat.ActiveIndex &&
|
||||
value >= 0 &&
|
||||
value < Models.DateTimeFormat.Supported.Count)
|
||||
{
|
||||
Models.DateTimeFormat.ActiveIndex = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool UseFixedTabWidth
|
||||
{
|
||||
get => _useFixedTabWidth;
|
||||
|
|
|
@ -37,6 +37,7 @@ namespace SourceGit.Views
|
|||
{
|
||||
var typeface = view.CreateTypeface();
|
||||
var underlinePen = new Pen(Brushes.DarkOrange);
|
||||
var width = Bounds.Width;
|
||||
|
||||
foreach (var line in view.VisualLines)
|
||||
{
|
||||
|
@ -64,16 +65,6 @@ namespace SourceGit.Views
|
|||
context.DrawLine(underlinePen, new Point(x, y + shaLink.Baseline + 2), new Point(x + shaLink.Width, y + shaLink.Baseline + 2));
|
||||
x += shaLink.Width + 8;
|
||||
|
||||
var time = new FormattedText(
|
||||
info.Time,
|
||||
CultureInfo.CurrentCulture,
|
||||
FlowDirection.LeftToRight,
|
||||
typeface,
|
||||
_editor.FontSize,
|
||||
_editor.Foreground);
|
||||
context.DrawText(time, new Point(x, y));
|
||||
x += time.Width + 8;
|
||||
|
||||
var author = new FormattedText(
|
||||
info.Author,
|
||||
CultureInfo.CurrentCulture,
|
||||
|
@ -82,6 +73,15 @@ namespace SourceGit.Views
|
|||
_editor.FontSize,
|
||||
_editor.Foreground);
|
||||
context.DrawText(author, new Point(x, y));
|
||||
|
||||
var time = new FormattedText(
|
||||
info.Time,
|
||||
CultureInfo.CurrentCulture,
|
||||
FlowDirection.LeftToRight,
|
||||
typeface,
|
||||
_editor.FontSize,
|
||||
_editor.Foreground);
|
||||
context.DrawText(time, new Point(width - time.Width, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,15 +116,6 @@ namespace SourceGit.Views
|
|||
Brushes.DarkOrange);
|
||||
x += shaLink.Width + 8;
|
||||
|
||||
var time = new FormattedText(
|
||||
info.Time,
|
||||
CultureInfo.CurrentCulture,
|
||||
FlowDirection.LeftToRight,
|
||||
typeface,
|
||||
_editor.FontSize,
|
||||
_editor.Foreground);
|
||||
x += time.Width + 8;
|
||||
|
||||
var author = new FormattedText(
|
||||
info.Author,
|
||||
CultureInfo.CurrentCulture,
|
||||
|
@ -132,7 +123,16 @@ namespace SourceGit.Views
|
|||
typeface,
|
||||
_editor.FontSize,
|
||||
_editor.Foreground);
|
||||
x += author.Width;
|
||||
x += author.Width + 8;
|
||||
|
||||
var time = new FormattedText(
|
||||
info.Time,
|
||||
CultureInfo.CurrentCulture,
|
||||
FlowDirection.LeftToRight,
|
||||
typeface,
|
||||
_editor.FontSize,
|
||||
_editor.Foreground);
|
||||
x += time.Width;
|
||||
|
||||
if (maxWidth < x)
|
||||
maxWidth = x;
|
||||
|
|
|
@ -78,7 +78,7 @@
|
|||
<DataTemplate DataType="m:Commit">
|
||||
<Border BorderBrush="{DynamicResource Brush.Border2}" BorderThickness="0,0,0,1" Padding="4">
|
||||
<Grid RowDefinitions="Auto,*">
|
||||
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto,Auto">
|
||||
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto,96">
|
||||
<v:Avatar Grid.Column="0" Width="16" Height="16" VerticalAlignment="Center" IsHitTestVisible="False" User="{Binding Author}"/>
|
||||
<TextBlock Grid.Column="1" Classes="primary" Text="{Binding Author.Name}" Margin="8,0,0,0" TextTrimming="CharacterEllipsis"/>
|
||||
<TextBlock Grid.Column="2"
|
||||
|
@ -90,7 +90,7 @@
|
|||
TextDecorations="Underline"
|
||||
Margin="8,0,0,0"
|
||||
PointerPressed="OnPressCommitSHA"/>
|
||||
<TextBlock Grid.Column="3" Classes="primary" Text="{Binding AuthorTimeShortStr}" Foreground="{DynamicResource Brush.FG2}" Margin="8,0,0,0"/>
|
||||
<TextBlock Grid.Column="3" Classes="primary" Text="{Binding AuthorTimeShortStr}" Foreground="{DynamicResource Brush.FG2}" HorizontalAlignment="Right"/>
|
||||
</Grid>
|
||||
|
||||
<TextBlock Grid.Row="1" Classes="primary" Text="{Binding Subject}" VerticalAlignment="Bottom"/>
|
||||
|
|
|
@ -428,7 +428,7 @@ namespace SourceGit.Views
|
|||
|
||||
var timestamp = UseAuthorTime ? commit.AuthorTime : commit.CommitterTime;
|
||||
if (ShowAsDateTime)
|
||||
return DateTime.UnixEpoch.AddSeconds(timestamp).ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss");
|
||||
return DateTime.UnixEpoch.AddSeconds(timestamp).ToLocalTime().ToString(Models.DateTimeFormat.Actived.DateTime);
|
||||
|
||||
var now = DateTime.Now;
|
||||
var localTime = DateTime.UnixEpoch.AddSeconds(timestamp).ToLocalTime();
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
<TabItem.Header>
|
||||
<TextBlock Classes="tab_header" Text="{DynamicResource Text.Preference.General}"/>
|
||||
</TabItem.Header>
|
||||
<Grid Margin="8" RowDefinitions="32,32,32,32,32,32,Auto" ColumnDefinitions="Auto,*">
|
||||
<Grid Margin="8" RowDefinitions="32,32,32,32,32,32,32,Auto" ColumnDefinitions="Auto,*">
|
||||
<TextBlock Grid.Row="0" Grid.Column="0"
|
||||
Text="{DynamicResource Text.Preference.General.Locale}"
|
||||
HorizontalAlignment="Right"
|
||||
|
@ -60,10 +60,27 @@
|
|||
SelectedItem="{Binding Locale, Mode=TwoWay, Converter={x:Static c:StringConverters.ToLocale}}"/>
|
||||
|
||||
<TextBlock Grid.Row="1" Grid.Column="0"
|
||||
Text="{DynamicResource Text.Preference.General.DateFormat}"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0,0,16,0"/>
|
||||
<ComboBox Grid.Row="1" Grid.Column="1"
|
||||
MinHeight="28"
|
||||
Padding="8,0"
|
||||
HorizontalAlignment="Stretch"
|
||||
ItemsSource="{Binding Source={x:Static m:DateTimeFormat.Supported}}"
|
||||
SelectedIndex="{Binding DateTimeFormat, Mode=TwoWay}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate x:DataType="{x:Type m:DateTimeFormat}">
|
||||
<TextBlock FontFamily="{DynamicResource Fonts.Monospace}" Text="{Binding DisplayText}"/>
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
|
||||
<TextBlock Grid.Row="2" Grid.Column="0"
|
||||
Text="{DynamicResource Text.Preference.Git.DefaultCloneDir}"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0,0,16,0"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="1"
|
||||
<TextBox Grid.Row="2" Grid.Column="1"
|
||||
Height="28"
|
||||
CornerRadius="3"
|
||||
Text="{Binding GitDefaultCloneDir, Mode=TwoWay}">
|
||||
|
@ -74,11 +91,11 @@
|
|||
</TextBox.InnerRightContent>
|
||||
</TextBox>
|
||||
|
||||
<TextBlock Grid.Row="2" Grid.Column="0"
|
||||
<TextBlock Grid.Row="3" Grid.Column="0"
|
||||
Text="{DynamicResource Text.Preference.General.SubjectGuideLength}"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0,0,16,0"/>
|
||||
<NumericUpDown Grid.Row="2" Grid.Column="1"
|
||||
<NumericUpDown Grid.Row="3" Grid.Column="1"
|
||||
Minimum="50" Maximum="1000" Increment="1"
|
||||
Height="28"
|
||||
Padding="4"
|
||||
|
@ -87,11 +104,11 @@
|
|||
CornerRadius="3"
|
||||
Value="{Binding SubjectGuideLength, Mode=TwoWay}"/>
|
||||
|
||||
<TextBlock Grid.Row="3" Grid.Column="0"
|
||||
<TextBlock Grid.Row="4" Grid.Column="0"
|
||||
Text="{DynamicResource Text.Preference.General.MaxHistoryCommits}"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0,0,16,0"/>
|
||||
<Grid Grid.Row="3" Grid.Column="1" ColumnDefinitions="*,64">
|
||||
<Grid Grid.Row="4" Grid.Column="1" ColumnDefinitions="*,64">
|
||||
<Slider Grid.Column="0"
|
||||
Minimum="5000" Maximum="100000"
|
||||
TickPlacement="BottomRight" TickFrequency="5000"
|
||||
|
@ -106,17 +123,17 @@
|
|||
Text="{Binding MaxHistoryCommits}"/>
|
||||
</Grid>
|
||||
|
||||
<CheckBox Grid.Row="4" Grid.Column="1"
|
||||
<CheckBox Grid.Row="5" Grid.Column="1"
|
||||
Height="32"
|
||||
Content="{DynamicResource Text.Preference.General.ShowAuthorTime}"
|
||||
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowAuthorTimeInGraph, Mode=TwoWay}"/>
|
||||
|
||||
<CheckBox Grid.Row="5" Grid.Column="1"
|
||||
<CheckBox Grid.Row="6" Grid.Column="1"
|
||||
Height="32"
|
||||
Content="{DynamicResource Text.Preference.General.ShowChildren}"
|
||||
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowChildren, Mode=TwoWay}"/>
|
||||
|
||||
<CheckBox Grid.Row="6" Grid.Column="1"
|
||||
<CheckBox Grid.Row="7" Grid.Column="1"
|
||||
Height="32"
|
||||
Content="{DynamicResource Text.Preference.General.Check4UpdatesOnStartup}"
|
||||
IsVisible="{x:Static s:App.IsCheckForUpdateCommandVisible}"
|
||||
|
|
Loading…
Reference in a new issue