mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-23 10:22:13 +08:00
refactor: use converters instead of store so many data in Models.Commit
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
@@ -247,8 +247,6 @@ namespace SourceGit
|
||||
else
|
||||
Models.CommitGraph.SetDefaultPens(overrides.GraphPenThickness);
|
||||
|
||||
Models.Commit.OpacityForNotMerged = overrides.OpacityForNotMergedCommits;
|
||||
|
||||
app.Resources.MergedDictionaries.Add(resDic);
|
||||
app._themeOverrides = resDic;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@ namespace SourceGit.Converters
|
||||
new FuncValueConverter<bool, double>(x => x ? 200 : double.NaN);
|
||||
|
||||
public static readonly FuncValueConverter<bool, FontWeight> IsBoldToFontWeight =
|
||||
new FuncValueConverter<bool, FontWeight>(x => x ? FontWeight.Bold : FontWeight.Normal);
|
||||
new FuncValueConverter<bool, FontWeight>(x => x ? FontWeight.Bold : FontWeight.Regular);
|
||||
|
||||
public static readonly FuncValueConverter<bool, double> IsMergedToOpacity =
|
||||
new FuncValueConverter<bool, double>(x => x ? 1 : 0.65);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Avalonia.Data.Converters;
|
||||
using Avalonia;
|
||||
using Avalonia.Data.Converters;
|
||||
|
||||
namespace SourceGit.Converters
|
||||
{
|
||||
@@ -15,5 +16,8 @@ namespace SourceGit.Converters
|
||||
|
||||
public static readonly FuncValueConverter<double, string> OneMinusToPercentage =
|
||||
new FuncValueConverter<double, string>(v => ((1.0 - v) * 100).ToString("F3") + "%");
|
||||
|
||||
public static readonly FuncValueConverter<double, Thickness> ToLeftMargin =
|
||||
new FuncValueConverter<double, Thickness>(v => new Thickness(v, 0, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Avalonia;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace SourceGit.Models
|
||||
{
|
||||
public enum CommitSearchMethod
|
||||
@@ -18,15 +15,8 @@ namespace SourceGit.Models
|
||||
|
||||
public class Commit
|
||||
{
|
||||
// As retrieved by: git mktree </dev/null
|
||||
public const string EmptyTreeSHA1 = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
|
||||
|
||||
public static double OpacityForNotMerged
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = 0.65;
|
||||
|
||||
public string SHA { get; set; } = string.Empty;
|
||||
public User Author { get; set; } = User.Invalid;
|
||||
public ulong AuthorTime { get; set; } = 0;
|
||||
@@ -35,22 +25,19 @@ namespace SourceGit.Models
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
public List<string> Parents { get; set; } = new();
|
||||
public List<Decorator> Decorators { get; set; } = new();
|
||||
public bool HasDecorators => Decorators.Count > 0;
|
||||
|
||||
public bool IsMerged { get; set; } = false;
|
||||
public int Color { get; set; } = 0;
|
||||
public double LeftMargin { get; set; } = 0;
|
||||
|
||||
public string AuthorTimeStr => DateTime.UnixEpoch.AddSeconds(AuthorTime).ToLocalTime().ToString(DateTimeFormat.Active.DateTime);
|
||||
public string CommitterTimeStr => DateTime.UnixEpoch.AddSeconds(CommitterTime).ToLocalTime().ToString(DateTimeFormat.Active.DateTime);
|
||||
public string AuthorTimeShortStr => DateTime.UnixEpoch.AddSeconds(AuthorTime).ToLocalTime().ToString(DateTimeFormat.Active.DateOnly);
|
||||
public string CommitterTimeShortStr => DateTime.UnixEpoch.AddSeconds(CommitterTime).ToLocalTime().ToString(DateTimeFormat.Active.DateOnly);
|
||||
|
||||
public bool IsMerged { get; set; } = false;
|
||||
public bool IsCommitterVisible => !Author.Equals(Committer) || AuthorTime != CommitterTime;
|
||||
public bool IsCurrentHead => Decorators.Find(x => x.Type is DecoratorType.CurrentBranchHead or DecoratorType.CurrentCommitHead) != null;
|
||||
|
||||
public int Color { get; set; } = 0;
|
||||
public double Opacity => IsMerged ? 1 : OpacityForNotMerged;
|
||||
public FontWeight FontWeight => IsCurrentHead ? FontWeight.Bold : FontWeight.Regular;
|
||||
public Thickness Margin { get; set; } = new(0);
|
||||
public IBrush Brush => CommitGraph.Pens[Color].Brush;
|
||||
public bool HasDecorators => Decorators.Count > 0;
|
||||
|
||||
public string GetFriendlyName()
|
||||
{
|
||||
|
||||
@@ -199,8 +199,8 @@ namespace SourceGit.Models
|
||||
|
||||
// Margins & merge state (used by Views.Histories).
|
||||
commit.IsMerged = isMerged;
|
||||
commit.Margin = new Thickness(Math.Max(offsetX, maxOffsetOld) + halfWidth + 2, 0, 0, 0);
|
||||
commit.Color = dotColor;
|
||||
commit.LeftMargin = Math.Max(offsetX, maxOffsetOld) + halfWidth + 2;
|
||||
}
|
||||
|
||||
// Deal with curves haven't ended yet.
|
||||
|
||||
@@ -183,7 +183,7 @@ namespace SourceGit.Views
|
||||
var typeface = new Typeface(FontFamily);
|
||||
var typefaceBold = new Typeface(FontFamily, FontStyle.Normal, FontWeight.Bold);
|
||||
var fg = Foreground;
|
||||
var normalBG = UseGraphColor ? commit.Brush : Brushes.Gray;
|
||||
var normalBG = UseGraphColor ? Models.CommitGraph.Pens[commit.Color].Brush : Brushes.Gray;
|
||||
var labelSize = FontSize;
|
||||
var requiredHeight = 16.0;
|
||||
var x = 0.0;
|
||||
|
||||
@@ -103,7 +103,7 @@
|
||||
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate DataType="m:Commit">
|
||||
<Border Padding="{Binding Margin}" ClipToBounds="True" Background="Transparent">
|
||||
<Border Padding="{Binding LeftMargin, Converter={x:Static c:DoubleConverters.ToLeftMargin}}" ClipToBounds="True" Background="Transparent">
|
||||
<Grid ColumnDefinitions="Auto,Auto,Auto,*" Margin="2,0,4,0" ClipToBounds="True">
|
||||
<v:CommitStatusIndicator Grid.Column="0"
|
||||
CurrentBranch="{Binding $parent[v:Histories].CurrentBranch}"
|
||||
@@ -140,8 +140,8 @@
|
||||
LinkForeground="{DynamicResource Brush.Link}"
|
||||
Subject="{Binding Subject}"
|
||||
IssueTrackers="{Binding $parent[v:Histories].IssueTrackers}"
|
||||
FontWeight="{Binding FontWeight}"
|
||||
Opacity="{Binding Opacity}"/>
|
||||
FontWeight="{Binding IsCurrentHead, Converter={x:Static c:BoolConverters.IsBoldToFontWeight}}"
|
||||
Opacity="{Binding IsMerged, Converter={x:Static c:BoolConverters.IsMergedToOpacity}}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
@@ -167,15 +167,15 @@
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
User="{Binding Author}"
|
||||
Opacity="{Binding Opacity}"
|
||||
Opacity="{Binding IsMerged, Converter={x:Static c:BoolConverters.IsMergedToOpacity}}"
|
||||
IsHitTestVisible="False"/>
|
||||
|
||||
<Border Grid.Column="1" Padding="8,0,4,0" ClipToBounds="True">
|
||||
<TextBlock Classes="primary"
|
||||
Text="{Binding Author.Name}"
|
||||
FontWeight="{Binding FontWeight}"
|
||||
HorizontalAlignment="Left"
|
||||
Opacity="{Binding Opacity}"/>
|
||||
FontWeight="{Binding IsCurrentHead, Converter={x:Static c:BoolConverters.IsBoldToFontWeight}}"
|
||||
Opacity="{Binding IsMerged, Converter={x:Static c:BoolConverters.IsMergedToOpacity}}"
|
||||
HorizontalAlignment="Left"/>
|
||||
</Border>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
@@ -192,8 +192,8 @@
|
||||
<Border Padding="8,0,0,0" Background="Transparent" ClipToBounds="True">
|
||||
<TextBlock Classes="primary"
|
||||
Text="{Binding SHA, Converter={x:Static c:StringConverters.ToShortSHA}}"
|
||||
FontWeight="{Binding FontWeight}"
|
||||
Opacity="{Binding Opacity}"/>
|
||||
FontWeight="{Binding IsCurrentHead, Converter={x:Static c:BoolConverters.IsBoldToFontWeight}}"
|
||||
Opacity="{Binding IsMerged, Converter={x:Static c:BoolConverters.IsMergedToOpacity}}"/>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
@@ -217,8 +217,8 @@
|
||||
<DataTemplate DataType="m:Commit">
|
||||
<Border Padding="8,0" Background="Transparent" ClipToBounds="True">
|
||||
<v:CommitTimeTextBlock Classes="primary"
|
||||
FontWeight="{Binding FontWeight}"
|
||||
Opacity="{Binding Opacity}"
|
||||
FontWeight="{Binding IsCurrentHead, Converter={x:Static c:BoolConverters.IsBoldToFontWeight}}"
|
||||
Opacity="{Binding IsMerged, Converter={x:Static c:BoolConverters.IsMergedToOpacity}}"
|
||||
UseAuthorTime="{Binding Source={x:Static vm:Preferences.Instance}, Path=ShowAuthorTimeInGraph, Mode=OneWay}"
|
||||
ShowAsDateTime="{Binding Source={x:Static vm:Preferences.Instance}, Path=!DisplayTimeAsPeriodInHistories}"
|
||||
DateTimeFormat="{Binding Source={x:Static vm:Preferences.Instance}, Path=DateTimeFormat}"/>
|
||||
|
||||
Reference in New Issue
Block a user