Skip to content

Commit 14469b1

Browse files
committed
theme: add ThemeOverrides.OpacityForNotMergedCommits to customize the opacity of commits that not belongs (haven't been merged) to current branch in histories (#268)
1 parent b2ed1b2 commit 14469b1

File tree

5 files changed

+22
-16
lines changed

5 files changed

+22
-16
lines changed

src/App.axaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ public static void SetTheme(string theme, string themeOverridesFile)
188188
else
189189
Models.CommitGraph.SetDefaultPens(overrides.GraphPenThickness);
190190

191+
Models.Commit.OpacityForNotMerged = overrides.OpacityForNotMergedCommits;
192+
191193
app.Resources.MergedDictionaries.Add(resDic);
192194
app._themeOverrides = resDic;
193195
}

src/Converters/BoolConverters.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
using Avalonia.Data.Converters;
2-
using Avalonia.Media;
32

43
namespace SourceGit.Converters
54
{
65
public static class BoolConverters
76
{
87
public static readonly FuncValueConverter<bool, double> ToPageTabWidth =
98
new FuncValueConverter<bool, double>(x => x ? 200 : double.NaN);
10-
11-
public static readonly FuncValueConverter<bool, double> HalfIfFalse =
12-
new FuncValueConverter<bool, double>(x => x ? 1 : 0.5);
13-
14-
public static readonly FuncValueConverter<bool, FontWeight> BoldIfTrue =
15-
new FuncValueConverter<bool, FontWeight>(x => x ? FontWeight.Bold : FontWeight.Regular);
169
}
1710
}

src/Models/Commit.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@
22
using System.Collections.Generic;
33

44
using Avalonia;
5+
using Avalonia.Media;
56

67
namespace SourceGit.Models
78
{
89
public class Commit
910
{
11+
public static double OpacityForNotMerged
12+
{
13+
get;
14+
set;
15+
} = 0.5;
16+
1017
public string SHA { get; set; } = string.Empty;
1118
public User Author { get; set; } = User.Invalid;
1219
public ulong AuthorTime { get; set; } = 0;
@@ -25,5 +32,8 @@ public class Commit
2532

2633
public bool IsCommitterVisible => !Author.Equals(Committer) || AuthorTime != CommitterTime;
2734
public bool IsCurrentHead => Decorators.Find(x => x.Type is DecoratorType.CurrentBranchHead or DecoratorType.CurrentCommitHead) != null;
35+
36+
public double Opacity => IsMerged ? 1 : OpacityForNotMerged;
37+
public FontWeight FontWeight => IsCurrentHead ? FontWeight.Bold : FontWeight.Regular;
2838
}
2939
}

src/Models/ThemeOverrides.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class ThemeOverrides
88
{
99
public Dictionary<string, Color> BasicColors { get; set; } = new Dictionary<string, Color>();
1010
public double GraphPenThickness { get; set; } = 2;
11+
public double OpacityForNotMergedCommits { get; set; } = 0.5;
1112
public List<Color> GraphColors { get; set; } = new List<Color>();
1213
}
1314
}

src/Views/Histories.axaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@
103103

104104
<TextBlock Classes="monospace"
105105
Text="{Binding Subject}"
106-
Opacity="{Binding IsMerged, Converter={x:Static c:BoolConverters.HalfIfFalse}}"
107-
FontWeight="{Binding IsCurrentHead, Converter={x:Static c:BoolConverters.BoldIfTrue}}"/>
106+
Opacity="{Binding Opacity}"
107+
FontWeight="{Binding FontWeight}"/>
108108
</StackPanel>
109109
</Border>
110110
</DataTemplate>
@@ -124,13 +124,13 @@
124124
VerticalAlignment="Center"
125125
IsHitTestVisible="False"
126126
User="{Binding Author}"
127-
Opacity="{Binding IsMerged, Converter={x:Static c:BoolConverters.HalfIfFalse}}"/>
127+
Opacity="{Binding Opacity}"/>
128128
<TextBlock Grid.Column="1"
129129
Classes="monospace"
130130
Text="{Binding Author.Name}"
131131
Margin="8,0,0,0"
132-
Opacity="{Binding IsMerged, Converter={x:Static c:BoolConverters.HalfIfFalse}}"
133-
FontWeight="{Binding IsCurrentHead, Converter={x:Static c:BoolConverters.BoldIfTrue}}"/>
132+
Opacity="{Binding Opacity}"
133+
FontWeight="{Binding FontWeight}"/>
134134
</Grid>
135135
</DataTemplate>
136136
</DataGridTemplateColumn.CellTemplate>
@@ -147,8 +147,8 @@
147147
Text="{Binding SHA, Converter={x:Static c:StringConverters.ToShortSHA}}"
148148
Margin="8,0"
149149
HorizontalAlignment="Center"
150-
Opacity="{Binding IsMerged, Converter={x:Static c:BoolConverters.HalfIfFalse}}"
151-
FontWeight="{Binding IsCurrentHead, Converter={x:Static c:BoolConverters.BoldIfTrue}}"/>
150+
Opacity="{Binding Opacity}"
151+
FontWeight="{Binding FontWeight}"/>
152152
</DataTemplate>
153153
</DataGridTemplateColumn.CellTemplate>
154154
</DataGridTemplateColumn>
@@ -169,8 +169,8 @@
169169
<v:CommitTimeTextBlock Classes="monospace"
170170
Margin="8,0"
171171
HorizontalAlignment="Center"
172-
Opacity="{Binding IsMerged, Converter={x:Static c:BoolConverters.HalfIfFalse}}"
173-
FontWeight="{Binding IsCurrentHead, Converter={x:Static c:BoolConverters.BoldIfTrue}}"
172+
Opacity="{Binding Opacity}"
173+
FontWeight="{Binding FontWeight}"
174174
Timestamp="{Binding CommitterTime}"
175175
ShowAsDateTime="{Binding Source={x:Static vm:Preference.Instance}, Path=!DisplayTimeAsPeriodInHistories}"/>
176176
</DataTemplate>

0 commit comments

Comments
 (0)