Skip to content

Commit 93ffbdd

Browse files
committed
refactor: use DataGrid instead of ListBox displaying history commits
Sometimes, `Grid.IsSharedSizeScope` does not work when navigating to the first commit Signed-off-by: leo <[email protected]>
1 parent db77c61 commit 93ffbdd

File tree

8 files changed

+236
-223
lines changed

8 files changed

+236
-223
lines changed

src/App.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
<Application.Styles>
3030
<FluentTheme />
31+
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml"/>
3132
<StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />
3233
<StyleInclude Source="/Resources/Styles.axaml"/>
3334
</Application.Styles>

src/SourceGit.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
<ItemGroup>
4242
<PackageReference Include="Avalonia" Version="11.2.8" />
43+
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.2.8" />
4344
<PackageReference Include="Avalonia.Desktop" Version="11.2.8" />
4445
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.8" />
4546
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.8" />

src/ViewModels/Histories.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public void CheckoutBranchByCommit(Models.Commit commit)
300300
}
301301
}
302302

303-
public ContextMenu MakeContextMenu(ListBox list)
303+
public ContextMenu MakeContextMenu(DataGrid list)
304304
{
305305
var current = _repo.CurrentBranch;
306306
if (current == null || list.SelectedItems == null)

src/ViewModels/LayoutInfo.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ public GridLength RepositorySidebarWidth
4141
set => SetProperty(ref _repositorySidebarWidth, value);
4242
}
4343

44-
public GridLength HistoriesAuthorColumnWidth
45-
{
46-
get => _historiesAuthorColumnWidth;
47-
set => SetProperty(ref _historiesAuthorColumnWidth, value);
48-
}
49-
5044
public GridLength WorkingCopyLeftWidth
5145
{
5246
get => _workingCopyLeftWidth;
@@ -72,7 +66,6 @@ public GridLength CommitDetailFilesLeftWidth
7266
}
7367

7468
private GridLength _repositorySidebarWidth = new GridLength(250, GridUnitType.Pixel);
75-
private GridLength _historiesAuthorColumnWidth = new GridLength(120, GridUnitType.Pixel);
7669
private GridLength _workingCopyLeftWidth = new GridLength(300, GridUnitType.Pixel);
7770
private GridLength _stashesLeftWidth = new GridLength(300, GridUnitType.Pixel);
7871
private GridLength _commitDetailChangesLeftWidth = new GridLength(256, GridUnitType.Pixel);

src/ViewModels/Repository.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ public void StartSearchCommits()
871871

872872
Task.Run(() =>
873873
{
874-
List<Models.Commit> visible = [];
874+
var visible = new List<Models.Commit>();
875875
var method = (Models.CommitSearchMethod)_searchCommitFilterType;
876876

877877
if (method == Models.CommitSearchMethod.BySHA)
@@ -880,8 +880,8 @@ public void StartSearchCommits()
880880
if (isCommitSHA)
881881
{
882882
var commit = new Commands.QuerySingleCommit(_fullpath, _searchCommitFilter).Result();
883-
visible = [commit];
884-
}
883+
visible.Add(commit);
884+
}
885885
}
886886
else
887887
{

src/Views/CommitGraph.cs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Avalonia;
22
using Avalonia.Controls;
3+
using Avalonia.Controls.Primitives;
34
using Avalonia.Media;
45
using Avalonia.VisualTree;
56

@@ -51,26 +52,40 @@ public override void Render(DrawingContext context)
5152
if (histories == null)
5253
return;
5354

54-
var list = histories.CommitListContainer;
55-
if (list == null)
55+
var grid = histories.CommitListContainer;
56+
if (grid == null)
5657
return;
5758

58-
var container = list.ItemsPanelRoot as VirtualizingStackPanel;
59-
if (container == null)
59+
var rowsPresenter = grid.FindDescendantOfType<DataGridRowsPresenter>();
60+
if (rowsPresenter == null)
6061
return;
6162

62-
var item = list.ContainerFromIndex(container.FirstRealizedIndex);
63-
if (item == null)
64-
return;
63+
double rowHeight = grid.RowHeight;
64+
double startY = 0;
65+
foreach (var child in rowsPresenter.Children)
66+
{
67+
var row = child as DataGridRow;
68+
if (row.IsVisible)
69+
{
70+
if (rowHeight != row.Bounds.Height)
71+
rowHeight = row.Bounds.Height;
72+
73+
if (row.Bounds.Top <= 0 && row.Bounds.Top > -rowHeight)
74+
{
75+
var test = rowHeight * row.Index - row.Bounds.Top;
76+
if (startY < test)
77+
startY = test;
78+
}
79+
}
80+
}
6581

66-
var width = histories.CommitListHeader.ColumnDefinitions[0].ActualWidth;
67-
var height = Bounds.Height;
68-
var rowHeight = item.Bounds.Height;
69-
var startY = container.FirstRealizedIndex * rowHeight - item.TranslatePoint(new Point(0, 0), list).Value!.Y;
82+
var headersHeight = grid.ColumnHeaderHeight;
83+
var width = histories.CommitListContainer.Columns[0].ActualWidth;
84+
var height = Bounds.Height - headersHeight;
7085
var endY = startY + height + 28;
7186

72-
using (context.PushClip(new Rect(0, 0, width, height)))
73-
using (context.PushTransform(Matrix.CreateTranslation(0, -startY)))
87+
using (context.PushClip(new Rect(0, headersHeight, width, height)))
88+
using (context.PushTransform(Matrix.CreateTranslation(0, headersHeight - startY)))
7489
{
7590
DrawCurves(context, graph, startY, endY, rowHeight);
7691
DrawAnchors(context, graph, startY, endY, rowHeight);

0 commit comments

Comments
 (0)