Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/SourceGit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
<PackageReference Include="Avalonia.Diagnostics" Version="11.3.13" Condition="'$(Configuration)' == 'Debug'" />
<PackageReference Include="Azure.AI.OpenAI" Version="2.9.0-beta.1" />
<PackageReference Include="BitMiracle.LibTiff.NET" Version="2.4.660" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="LiveChartsCore.SkiaSharpView.Avalonia" Version="2.0.0-rc6.1" />
<PackageReference Include="OpenAI" Version="2.9.1" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.2" />
<PackageReference Include="LiveChartsCore.SkiaSharpView.Avalonia" Version="2.0.0" />
<PackageReference Include="OpenAI" Version="2.10.0" />
<PackageReference Include="Pfim" Version="0.11.4" />

<ProjectReference Include="../depends/AvaloniaEdit/src/AvaloniaEdit.TextMate/AvaloniaEdit.TextMate.csproj" />
Expand Down
57 changes: 47 additions & 10 deletions src/ViewModels/Histories.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

using Avalonia.Controls;
Expand Down Expand Up @@ -60,15 +61,7 @@ public bool IsDateTimeColumnVisible
public List<Models.Commit> Commits
{
get => _commits;
set
{
var lastSelected = SelectedCommit;
if (SetProperty(ref _commits, value))
{
if (value.Count > 0 && lastSelected != null)
SelectedCommit = value.Find(x => x.SHA == lastSelected.SHA);
}
}
set => SetProperty(ref _commits, value);
}

public Models.CommitGraph Graph
Expand All @@ -83,6 +76,18 @@ public Models.Commit SelectedCommit
set => SetProperty(ref _selectedCommit, value);
}

public Models.Commit LastSelectedCommit
{
get => _lastSelectedCommit;
set => SetProperty(ref _lastSelectedCommit, value);
}

public List<Models.Commit> LastSelectedCommits
{
get => _lastSelectedCommits;
private set => SetProperty(ref _lastSelectedCommits, value);
}

public long NavigationId
{
get => _navigationId;
Expand Down Expand Up @@ -137,6 +142,8 @@ public void Dispose()
_repo = null;
_graph = null;
_selectedCommit = null;
_lastSelectedCommits = null;
_lastSelectedCommit = null;
_detailContext?.Dispose();
_detailContext = null;
}
Expand Down Expand Up @@ -209,7 +216,14 @@ public void NavigateTo(string commitSHA)
});
}

public void Select(IList commits)
/// <summary>
///
/// notes: if multi selects, `AutoSelectedCommit` which `Binding Mode=OneWay` will not be updated,
/// so that we could not get the lastSelectedCommit automatically
///
/// </summary>
/// <param name="commits"></param>
public void Select(IList commits, object selectedCommit)
{
if (_ignoreSelectionChange)
return;
Expand All @@ -218,13 +232,15 @@ public void Select(IList commits)
{
_repo.SearchCommitContext.Selected = null;
DetailContext = null;
return;
}
else if (commits.Count == 1)
{
var commit = (commits[0] as Models.Commit)!;
if (_repo.SearchCommitContext.Selected == null || _repo.SearchCommitContext.Selected.SHA != commit.SHA)
_repo.SearchCommitContext.Selected = _repo.SearchCommitContext.Results?.Find(x => x.SHA == commit.SHA);

// MarkLastSelectedCommitsAsSelected();
SelectedCommit = commit;
NavigationId = _navigationId + 1;

Expand Down Expand Up @@ -252,6 +268,25 @@ public void Select(IList commits)
_repo.SearchCommitContext.Selected = null;
DetailContext = new Models.Count(commits.Count);
}

LastSelectedCommit = selectedCommit as Models.Commit;
LastSelectedCommits = commits.Cast<Models.Commit>().ToList();
}

public void MarkLastSelectedCommitsAsSelected(params IList<Models.Commit> commits)
{
var availableCommits = Commits.Where(x => commits.Any(y => y.SHA == x.SHA)).ToList();

// if LastSelectedCommits is not empty, find the AutoSelectedCommit or get last one
if (availableCommits.Count > 0 && LastSelectedCommit != null)
{
// find in oldAvailable or get last one
SelectedCommit = availableCommits.Find(x => x.SHA == LastSelectedCommit.SHA)
?? availableCommits.FirstOrDefault();
}
// set selectItem above(1item), now select others too
LastSelectedCommits = availableCommits;
NavigationId = _navigationId + 1;
}

public async Task<Models.Commit> GetCommitAsync(string sha)
Expand Down Expand Up @@ -466,6 +501,8 @@ public void CompareWithWorktree(Models.Commit commit)
private CommitDetailSharedData _commitDetailSharedData = null;
private bool _isLoading = true;
private List<Models.Commit> _commits = new List<Models.Commit>();
private List<Models.Commit> _lastSelectedCommits = [];
private Models.Commit _lastSelectedCommit = null;
private Models.CommitGraph _graph = null;
private Models.Commit _selectedCommit = null;
private Models.Bisect _bisect = null;
Expand Down
13 changes: 11 additions & 2 deletions src/ViewModels/Repository.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

using Avalonia.Collections;
using Avalonia.Threading;

using CommunityToolkit.Mvvm.ComponentModel;

namespace SourceGit.ViewModels
Expand Down Expand Up @@ -282,6 +281,12 @@ public SearchCommitContext SearchCommitContext
get => _searchCommitContext;
}

public List<Models.Commit> SelectedCommits
{
get => _selectCommits;
set => SetProperty(ref _selectCommits, value);
}

public bool IsLocalBranchGroupExpanded
{
get => _uiStates.IsLocalBranchesExpandedInSideBar;
Expand Down Expand Up @@ -1219,6 +1224,7 @@ public void RefreshCommits()
{
if (_cancellationRefreshCommits is { IsCancellationRequested: false })
_cancellationRefreshCommits.Cancel();
var oldSelectedCommits = _selectCommits.ToList();

_cancellationRefreshCommits = new CancellationTokenSource();
var token = _cancellationRefreshCommits.Token;
Expand Down Expand Up @@ -1248,6 +1254,8 @@ public void RefreshCommits()

BisectState = _histories.UpdateBisectInfo();

_histories.MarkLastSelectedCommitsAsSelected(_histories.LastSelectedCommits);

if (!string.IsNullOrEmpty(_navigateToCommitDelayed))
NavigateToCommit(_navigateToCommitDelayed);
}
Expand Down Expand Up @@ -1957,6 +1965,7 @@ private async Task AutoFetchOnUIThread()

private bool _isSearchingCommits = false;
private SearchCommitContext _searchCommitContext = null;
private List<Models.Commit> _selectCommits = new List<Models.Commit>();

private string _filter = string.Empty;
private List<Models.Remote> _remotes = [];
Expand Down
23 changes: 22 additions & 1 deletion src/Views/Histories.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ public long NavigationId
set => SetValue(NavigationIdProperty, value);
}

public static readonly StyledProperty<List<Models.Commit>> LastSelectedCommitsProperty =
AvaloniaProperty.Register<Histories, List<Models.Commit>>(nameof(LastSelectedCommits));

public List<Models.Commit> LastSelectedCommits
{
get => GetValue(LastSelectedCommitsProperty);
set => SetValue(LastSelectedCommitsProperty, value);
}

public static readonly StyledProperty<bool> IsScrollToTopVisibleProperty =
AvaloniaProperty.Register<Histories, bool>(nameof(IsScrollToTopVisible));

Expand All @@ -146,6 +155,18 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
if (CommitListContainer is { SelectedItems.Count: 1, IsLoaded: true } dataGrid)
dataGrid.ScrollIntoView(dataGrid.SelectedItem, null);
}
if (change.Property == LastSelectedCommitsProperty)
{
if (LastSelectedCommits?.Count > 1 &&
(CommitListContainer is DataGrid { IsLoaded: true } dataGrid))
{
foreach (var c in LastSelectedCommits)
{
dataGrid.SelectedItems.Add(c);
}
}
}

}

private void OnCommitListLoaded(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -301,7 +322,7 @@ private void OnScrollToTopPointerPressed(object sender, PointerPressedEventArgs
private void OnCommitListSelectionChanged(object _, SelectionChangedEventArgs e)
{
if (DataContext is ViewModels.Histories histories)
histories.Select(CommitListContainer.SelectedItems);
histories.Select(CommitListContainer.SelectedItems, CommitListContainer.SelectedItem);

e.Handled = true;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Views/Repository.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@
<Setter Property="CornerRadius" Value="4"/>
</Style>
</ListBox.Styles>
<ListBox.ItemTemplate>
<ListBox.ItemTemplate>
<DataTemplate DataType="vm:Worktree">
<Border Height="24"
Background="Transparent"
Expand All @@ -450,7 +450,7 @@
<TextBlock Grid.Row="0" Grid.Column="3"
Margin="6,0,0,0"
Text="{Binding Branch, Mode=OneWay}"/>

<TextBlock Grid.Row="1" Grid.Column="0"
Classes="info_label"
HorizontalAlignment="Left" VerticalAlignment="Center"
Expand Down Expand Up @@ -926,6 +926,7 @@
Bisect="{Binding Bisect}"
IssueTrackers="{Binding $parent[v:Repository].((vm:Repository)DataContext).IssueTrackers}"
OnlyHighlightCurrentBranch="{Binding $parent[v:Repository].((vm:Repository)DataContext).OnlyHighlightCurrentBranchInHistory}"
LastSelectedCommits="{Binding LastSelectedCommits}"
NavigationId="{Binding NavigationId}"/>
</DataTemplate>

Expand Down