Skip to content

Commit 8ee6c59

Browse files
committed
ux: refactor commit graph highlighting UI to use unified menu
1. Introduced CommitGraphHighlighting enum to consolidate highlighting modes. 2. Replaced individual toggle buttons in Repository view with a unified menu in Histories column header. 3. Updated CommitGraph rendering to respect the new HighlightMode enum. 4. Added multi-language localizations for the new highlighting modes. 5. Maintained dynamic lineage calculation for hover support while adopting the cleaner UI structure from upstream. FAILED TEST CASES: NONE
1 parent 639f8ce commit 8ee6c59

12 files changed

Lines changed: 152 additions & 97 deletions

File tree

‎src/Converters/FilterModeConverters.cs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,11 @@ public static class FilterModeConverters
1515
_ => Brushes.Transparent,
1616
};
1717
});
18+
19+
public static readonly FuncValueConverter<Models.CommitGraphHighlighting, bool> HighlightModeToIsAllBright =
20+
new FuncValueConverter<Models.CommitGraphHighlighting, bool>(v =>
21+
{
22+
return v == Models.CommitGraphHighlighting.All;
23+
});
1824
}
1925
}

‎src/Models/CommitGraph.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66

77
namespace SourceGit.Models
88
{
9+
public enum CommitGraphHighlighting
10+
{
11+
All,
12+
CurrentBranchOnly,
13+
SelectedLineageOnly,
14+
CurrentBranchAndSelectedLineage,
15+
}
16+
917
public record CommitGraphLayout(double StartY, double ClipWidth, double RowHeight);
1018

1119
public class CommitGraph

‎src/Models/RepositoryUIStates.cs‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,11 @@ public bool EnableTopoOrderInHistory
3939
set;
4040
} = false;
4141

42-
public bool OnlyHighlightCurrentBranchInHistory
42+
public CommitGraphHighlighting CommitGraphHighlighting
4343
{
4444
get;
4545
set;
46-
} = false;
47-
48-
public bool HighlightSelectedLineageInHistory
49-
{
50-
get;
51-
set;
52-
} = false;
46+
} = CommitGraphHighlighting.All;
5347

5448
public BranchSortMode LocalBranchSortMode
5549
{

‎src/Resources/Locales/en_US.axaml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,11 @@
491491
<x:String x:Key="Text.Histories.Header.CommitTime" xml:space="preserve">COMMIT TIME</x:String>
492492
<x:String x:Key="Text.Histories.Header.DateTime" xml:space="preserve">DATE TIME</x:String>
493493
<x:String x:Key="Text.Histories.Header.GraphAndSubject" xml:space="preserve">GRAPH &amp; SUBJECT</x:String>
494+
<x:String x:Key="Text.Histories.Header.Highlights" xml:space="preserve">Highlighting Mode</x:String>
495+
<x:String x:Key="Text.Histories.Header.Highlights.All" xml:space="preserve">Show All</x:String>
496+
<x:String x:Key="Text.Histories.Header.Highlights.CurrentBranchOnly" xml:space="preserve">Current Branch Only</x:String>
497+
<x:String x:Key="Text.Histories.Header.Highlights.SelectedLineageOnly" xml:space="preserve">Selected Lineage Only</x:String>
498+
<x:String x:Key="Text.Histories.Header.Highlights.CurrentBranchAndSelectedLineage" xml:space="preserve">Current Branch &amp; Selected Lineage</x:String>
494499
<x:String x:Key="Text.Histories.Header.SHA" xml:space="preserve">SHA</x:String>
495500
<x:String x:Key="Text.Histories.Selected" xml:space="preserve">SELECTED {0} COMMITS</x:String>
496501
<x:String x:Key="Text.Histories.ShowColumns" xml:space="preserve">SHOW COLUMNS</x:String>

‎src/Resources/Locales/zh_CN.axaml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,11 @@
495495
<x:String x:Key="Text.Histories.Header.CommitTime" xml:space="preserve">提交时间</x:String>
496496
<x:String x:Key="Text.Histories.Header.DateTime" xml:space="preserve">日期时间</x:String>
497497
<x:String x:Key="Text.Histories.Header.GraphAndSubject" xml:space="preserve">路线图与主题</x:String>
498+
<x:String x:Key="Text.Histories.Header.Highlights" xml:space="preserve">高亮模式</x:String>
499+
<x:String x:Key="Text.Histories.Header.Highlights.All" xml:space="preserve">全部显示</x:String>
500+
<x:String x:Key="Text.Histories.Header.Highlights.CurrentBranchOnly" xml:space="preserve">仅当前分支</x:String>
501+
<x:String x:Key="Text.Histories.Header.Highlights.SelectedLineageOnly" xml:space="preserve">仅选中谱系</x:String>
502+
<x:String x:Key="Text.Histories.Header.Highlights.CurrentBranchAndSelectedLineage" xml:space="preserve">当前分支与选中谱系</x:String>
498503
<x:String x:Key="Text.Histories.Header.SHA" xml:space="preserve">提交指纹</x:String>
499504
<x:String x:Key="Text.Histories.Selected" xml:space="preserve">已选中 {0} 项提交</x:String>
500505
<x:String x:Key="Text.Histories.ShowColumns" xml:space="preserve">显示列</x:String>

‎src/Resources/Locales/zh_TW.axaml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,11 @@
495495
<x:String x:Key="Text.Histories.Header.CommitTime" xml:space="preserve">提交時間</x:String>
496496
<x:String x:Key="Text.Histories.Header.DateTime" xml:space="preserve">日期時間</x:String>
497497
<x:String x:Key="Text.Histories.Header.GraphAndSubject" xml:space="preserve">路線圖與訊息標題</x:String>
498+
<x:String x:Key="Text.Histories.Header.Highlights" xml:space="preserve">高亮模式</x:String>
499+
<x:String x:Key="Text.Histories.Header.Highlights.All" xml:space="preserve">全部顯示</x:String>
500+
<x:String x:Key="Text.Histories.Header.Highlights.CurrentBranchOnly" xml:space="preserve">僅目前分支</x:String>
501+
<x:String x:Key="Text.Histories.Header.Highlights.SelectedLineageOnly" xml:space="preserve">僅選取譜系</x:String>
502+
<x:String x:Key="Text.Histories.Header.Highlights.CurrentBranchAndSelectedLineage" xml:space="preserve">目前分支與選取譜系</x:String>
498503
<x:String x:Key="Text.Histories.Header.SHA" xml:space="preserve">提交編號</x:String>
499504
<x:String x:Key="Text.Histories.Selected" xml:space="preserve">已選取 {0} 項提交</x:String>
500505
<x:String x:Key="Text.Histories.ShowColumns" xml:space="preserve">顯示欄位</x:String>

‎src/ViewModels/Histories.cs‎

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -159,28 +159,25 @@ public Models.Branch CurrentBranch
159159
get => _repo.CurrentBranch;
160160
}
161161

162-
public bool HighlightCurrentBranchOnly
162+
public Models.CommitGraphHighlighting CommitGraphHighlighting
163163
{
164-
get => _repo.UIStates.OnlyHighlightCurrentBranchInHistory;
164+
get => _repo.UIStates.CommitGraphHighlighting;
165165
set
166166
{
167-
if (_repo.UIStates.OnlyHighlightCurrentBranchInHistory != value)
167+
if (_repo.UIStates.CommitGraphHighlighting != value)
168168
{
169-
_repo.UIStates.OnlyHighlightCurrentBranchInHistory = value;
169+
_repo.UIStates.CommitGraphHighlighting = value;
170170
OnPropertyChanged();
171-
}
172-
}
173-
}
174171

175-
public bool HighlightSelectedLineage
176-
{
177-
get => _repo.UIStates.HighlightSelectedLineageInHistory;
178-
set
179-
{
180-
if (_repo.UIStates.HighlightSelectedLineageInHistory != value)
181-
{
182-
_repo.UIStates.HighlightSelectedLineageInHistory = value;
183-
OnPropertyChanged();
172+
var highlightSelected = value == Models.CommitGraphHighlighting.SelectedLineageOnly ||
173+
value == Models.CommitGraphHighlighting.CurrentBranchAndSelectedLineage;
174+
if (highlightSelected && _selectedCommits.Count == 1)
175+
CalculateTargetLineage(_selectedCommits[0]);
176+
else if (!highlightSelected)
177+
{
178+
SelectedLineageCommits = null;
179+
SelectedLineagePaths = null;
180+
}
184181
}
185182
}
186183
}
@@ -555,7 +552,7 @@ private void CalculateTargetLineage(Models.Commit commit)
555552
}
556553

557554
var paths = new HashSet<int>();
558-
var lineage = GetCommitLineage(commit, Models.CommitLineageSearchMethod.FullLineage);
555+
var lineage = GetCommitLineage(commit, Models.CommitLineageSearchMethod.FullLineage, 20000);
559556
for (int i = 0; i < lineage.Length; i++)
560557
{
561558
if (lineage[i])
@@ -582,7 +579,7 @@ private void PostSelectedCommitsChanged()
582579
if (_selectedCommits.Count == 0)
583580
{
584581
_repo.SearchCommitContext.Selected = null;
585-
DetailContext = null;
582+
DetailContext = new Models.Null();
586583
SelectedLineageCommits = null;
587584
SelectedLineagePaths = null;
588585
}
@@ -597,7 +594,9 @@ private void PostSelectedCommitsChanged()
597594
else
598595
DetailContext = new CommitDetail(_repo, _commitDetailSharedData) { Commit = c };
599596

600-
if (_repo.UIStates.HighlightSelectedLineageInHistory)
597+
var highlightSelected = _repo.UIStates.CommitGraphHighlighting == Models.CommitGraphHighlighting.SelectedLineageOnly ||
598+
_repo.UIStates.CommitGraphHighlighting == Models.CommitGraphHighlighting.CurrentBranchAndSelectedLineage;
599+
if (highlightSelected)
601600
CalculateTargetLineage(c);
602601
}
603602
else if (_selectedCommits.Count == 2)

‎src/ViewModels/Repository.cs‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,10 @@ private set
126126
}
127127
}
128128

129-
public bool HighlightCurrentBranchOnlyInHistory
129+
public Models.CommitGraphHighlighting CommitGraphHighlighting
130130
{
131-
get => _histories.HighlightCurrentBranchOnly;
132-
set => _histories.HighlightCurrentBranchOnly = value;
133-
}
134-
135-
public bool HighlightSelectedLineageInHistory
136-
{
137-
get => _histories.HighlightSelectedLineage;
138-
set => _histories.HighlightSelectedLineage = value;
131+
get => _histories.CommitGraphHighlighting;
132+
set => _histories.CommitGraphHighlighting = value;
139133
}
140134

141135
public string Filter

‎src/Views/CommitGraph.cs‎

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,13 @@ public IBrush DotBrush
2424
set => SetValue(DotBrushProperty, value);
2525
}
2626

27-
public static readonly StyledProperty<bool> OnlyHighlightCurrentBranchProperty =
28-
AvaloniaProperty.Register<CommitGraph, bool>(nameof(OnlyHighlightCurrentBranch), true);
27+
public static readonly StyledProperty<Models.CommitGraphHighlighting> HighlightModeProperty =
28+
AvaloniaProperty.Register<CommitGraph, Models.CommitGraphHighlighting>(nameof(HighlightMode), Models.CommitGraphHighlighting.All);
2929

30-
public bool OnlyHighlightCurrentBranch
30+
public Models.CommitGraphHighlighting HighlightMode
3131
{
32-
get => GetValue(OnlyHighlightCurrentBranchProperty);
33-
set => SetValue(OnlyHighlightCurrentBranchProperty, value);
34-
}
35-
36-
public static readonly StyledProperty<bool> HighlightSelectedLineageProperty =
37-
AvaloniaProperty.Register<CommitGraph, bool>(nameof(HighlightSelectedLineage), false);
38-
39-
public bool HighlightSelectedLineage
40-
{
41-
get => GetValue(HighlightSelectedLineageProperty);
42-
set => SetValue(HighlightSelectedLineageProperty, value);
32+
get => GetValue(HighlightModeProperty);
33+
set => SetValue(HighlightModeProperty, value);
4334
}
4435

4536
public static readonly StyledProperty<bool[]> HoveredLineageCommitsProperty =
@@ -92,8 +83,7 @@ static CommitGraph()
9283
AffectsRender<CommitGraph>(
9384
GraphProperty,
9485
DotBrushProperty,
95-
OnlyHighlightCurrentBranchProperty,
96-
HighlightSelectedLineageProperty,
86+
HighlightModeProperty,
9787
HoveredLineageCommitsProperty,
9888
HoveredCommitIndexProperty,
9989
SelectedLineageCommitsProperty,
@@ -110,7 +100,7 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
110100
change.Property == HoveredLineageCommitsProperty ||
111101
change.Property == SelectedLineageCommitsProperty ||
112102
change.Property == SelectedLineagePathsProperty ||
113-
change.Property == HighlightSelectedLineageProperty)
103+
change.Property == HighlightModeProperty)
114104
{
115105
UpdateHoveredRelated();
116106
}
@@ -165,8 +155,11 @@ private void DrawCurves(DrawingContext context, Models.CommitGraph graph, double
165155
{
166156
var hoverBold = 2.0;
167157
var grayedPen = new Pen(new SolidColorBrush(Colors.Gray, 0.4), Models.CommitGraph.Pens[0].Thickness);
168-
var onlyHighlightCurrentBranch = OnlyHighlightCurrentBranch;
169-
var highlightSelectedLineage = HighlightSelectedLineage;
158+
var highlightMode = HighlightMode;
159+
var onlyHighlightCurrentBranch = highlightMode == Models.CommitGraphHighlighting.CurrentBranchOnly ||
160+
highlightMode == Models.CommitGraphHighlighting.CurrentBranchAndSelectedLineage;
161+
var highlightSelectedLineage = highlightMode == Models.CommitGraphHighlighting.SelectedLineageOnly ||
162+
highlightMode == Models.CommitGraphHighlighting.CurrentBranchAndSelectedLineage;
170163
var selectedLineageCommits = SelectedLineageCommits;
171164
var hoveredLineage = HoveredLineageCommits;
172165

@@ -195,7 +188,15 @@ private void DrawCurves(DrawingContext context, Models.CommitGraph graph, double
195188
hoveredLineage[link.EndCommitIndex];
196189

197190
var pen = link.Color < 0 ? grayedPen : Models.CommitGraph.Pens[link.Color];
198-
if (onlyHighlightCurrentBranch && !link.IsMerged && !isLinkInSelectedLineage)
191+
bool shouldDim = false;
192+
if (highlightMode == Models.CommitGraphHighlighting.CurrentBranchOnly)
193+
shouldDim = !link.IsMerged;
194+
else if (highlightMode == Models.CommitGraphHighlighting.SelectedLineageOnly)
195+
shouldDim = !isLinkInSelectedLineage;
196+
else if (highlightMode == Models.CommitGraphHighlighting.CurrentBranchAndSelectedLineage)
197+
shouldDim = !link.IsMerged && !isLinkInSelectedLineage;
198+
199+
if (shouldDim)
199200
pen = grayedPen;
200201

201202
if (isLinkInHoveredLineage)
@@ -230,7 +231,15 @@ private void DrawCurves(DrawingContext context, Models.CommitGraph graph, double
230231

231232
var geo = new StreamGeometry();
232233
var pen = line.Color < 0 ? grayedPen : Models.CommitGraph.Pens[line.Color];
233-
if (onlyHighlightCurrentBranch && !line.IsMerged && !isLineInSelectedLineage)
234+
bool shouldDim = false;
235+
if (highlightMode == Models.CommitGraphHighlighting.CurrentBranchOnly)
236+
shouldDim = !line.IsMerged;
237+
else if (highlightMode == Models.CommitGraphHighlighting.SelectedLineageOnly)
238+
shouldDim = !isLineInSelectedLineage;
239+
else if (highlightMode == Models.CommitGraphHighlighting.CurrentBranchAndSelectedLineage)
240+
shouldDim = !line.IsMerged && !isLineInSelectedLineage;
241+
242+
if (shouldDim)
234243
pen = grayedPen;
235244

236245
if (line.IsHoveredRelated)
@@ -297,8 +306,11 @@ private void DrawAnchors(DrawingContext context, Models.CommitGraph graph, doubl
297306
var dotFill = DotBrush;
298307
var dotFillPen = new Pen(dotFill, 2);
299308
var grayedPen = new Pen(Brushes.Gray, Models.CommitGraph.Pens[0].Thickness);
300-
var onlyHighlightCurrentBranch = OnlyHighlightCurrentBranch;
301-
var highlightSelectedLineage = HighlightSelectedLineage;
309+
var highlightMode = HighlightMode;
310+
var onlyHighlightCurrentBranch = highlightMode == Models.CommitGraphHighlighting.CurrentBranchOnly ||
311+
highlightMode == Models.CommitGraphHighlighting.CurrentBranchAndSelectedLineage;
312+
var highlightSelectedLineage = highlightMode == Models.CommitGraphHighlighting.SelectedLineageOnly ||
313+
highlightMode == Models.CommitGraphHighlighting.CurrentBranchAndSelectedLineage;
302314
var selectedLineageCommits = SelectedLineageCommits;
303315

304316
if (DataContext is not ViewModels.Histories vm)
@@ -317,7 +329,15 @@ private void DrawAnchors(DrawingContext context, Models.CommitGraph graph, doubl
317329
bool isDotInSelectedLineage = highlightSelectedLineage && selectedLineageCommits != null && i >= 0 && i < selectedLineageCommits.Length && selectedLineageCommits[i];
318330

319331
var pen = Models.CommitGraph.Pens[dot.Color];
320-
if (onlyHighlightCurrentBranch && !dot.IsMerged && !isDotInSelectedLineage)
332+
bool shouldDim = false;
333+
if (highlightMode == Models.CommitGraphHighlighting.CurrentBranchOnly)
334+
shouldDim = !dot.IsMerged;
335+
else if (highlightMode == Models.CommitGraphHighlighting.SelectedLineageOnly)
336+
shouldDim = !isDotInSelectedLineage;
337+
else if (highlightMode == Models.CommitGraphHighlighting.CurrentBranchAndSelectedLineage)
338+
shouldDim = !dot.IsMerged && !isDotInSelectedLineage;
339+
340+
if (shouldDim)
321341
pen = grayedPen;
322342

323343
switch (dot.Type)
@@ -339,3 +359,4 @@ private void DrawAnchors(DrawingContext context, Models.CommitGraph graph, doubl
339359
}
340360
}
341361
}
362+

‎src/Views/Histories.axaml‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,14 @@
100100
<DataGrid.Columns>
101101
<DataGridTemplateColumn Width="*" IsReadOnly="True">
102102
<DataGridTemplateColumn.Header>
103-
<TextBlock Classes="table_header" Text="{DynamicResource Text.Histories.Header.GraphAndSubject}" HorizontalAlignment="Center"/>
103+
<Grid>
104+
<Button Classes="icon_button"
105+
Click="OnHighlightsClicked"
106+
ToolTip.Tip="{DynamicResource Text.Histories.Header.Highlights}">
107+
<Path Width="12" Height="12" Data="{StaticResource Icons.LightOn}"/>
108+
</Button>
109+
<TextBlock Classes="table_header" Text="{DynamicResource Text.Histories.Header.GraphAndSubject}" HorizontalAlignment="Center"/>
110+
</Grid>
104111
</DataGridTemplateColumn.Header>
105112

106113
<DataGridTemplateColumn.CellTemplate>
@@ -128,7 +135,7 @@
128135
<v:CommitRefsPresenter.UseGraphColor>
129136
<MultiBinding Converter="{x:Static BoolConverters.Or}">
130137
<Binding Path="IsMerged"/>
131-
<Binding Path="$parent[v:Histories].OnlyHighlightCurrentBranch" Converter="{x:Static BoolConverters.Not}"/>
138+
<Binding Path="$parent[v:Histories].CommitGraphHighlighting" Converter="{x:Static c:FilterModeConverters.HighlightModeToIsAllBright}"/>
132139
</MultiBinding>
133140
</v:CommitRefsPresenter.UseGraphColor>
134141
</v:CommitRefsPresenter>
@@ -233,12 +240,11 @@
233240
Margin="0,24,0,0"
234241
Graph="{Binding Graph}"
235242
DotBrush="{DynamicResource Brush.Contents}"
236-
OnlyHighlightCurrentBranch="{Binding $parent[v:Histories].OnlyHighlightCurrentBranch}"
243+
HighlightMode="{Binding $parent[v:Histories].CommitGraphHighlighting}"
237244
HoveredCommitIndex="{Binding HoveredCommitIndex}"
238245
HoveredLineageCommits="{Binding HoveredLineageCommits}"
239246
SelectedLineageCommits="{Binding SelectedLineageCommits}"
240247
SelectedLineagePaths="{Binding SelectedLineagePaths}"
241-
HighlightSelectedLineage="{Binding $parent[v:Histories].HighlightSelectedLineage}"
242248
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
243249
IsHitTestVisible="False"
244250
ClipToBounds="True"/>

0 commit comments

Comments
 (0)