2024-03-17 18:37:06 -07:00
|
|
|
|
using System.Collections.Generic;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
using Avalonia.Threading;
|
|
|
|
|
|
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
|
|
|
|
|
namespace SourceGit.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class FileHistories : ObservableObject
|
|
|
|
|
{
|
|
|
|
|
public string File
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _file;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public bool IsLoading
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _isLoading;
|
|
|
|
|
private set => SetProperty(ref _isLoading, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public List<Models.Commit> Commits
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _commits;
|
|
|
|
|
set => SetProperty(ref _commits, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public Models.Commit SelectedCommit
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _selectedCommit;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (SetProperty(ref _selectedCommit, value))
|
|
|
|
|
{
|
|
|
|
|
if (value == null)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
DiffContext = null;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-03-20 03:27:48 -07:00
|
|
|
|
DiffContext = new DiffContext(_repo, new Models.DiffOption(value, _file), _diffContext);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public DiffContext DiffContext
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _diffContext;
|
|
|
|
|
set => SetProperty(ref _diffContext, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public FileHistories(string repo, string file)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo = repo;
|
|
|
|
|
_file = file;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var commits = new Commands.QueryCommits(_repo, $"-n 10000 -- \"{file}\"").Result();
|
2024-03-17 18:37:06 -07:00
|
|
|
|
Dispatcher.UIThread.Invoke(() =>
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
IsLoading = false;
|
|
|
|
|
Commits = commits;
|
|
|
|
|
if (commits.Count > 0) SelectedCommit = commits[0];
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void NavigateToCommit(string commitSHA)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var repo = Preference.FindRepository(_repo);
|
|
|
|
|
if (repo != null) repo.NavigateToCommit(commitSHA);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private readonly string _repo = string.Empty;
|
|
|
|
|
private readonly string _file = string.Empty;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
private bool _isLoading = true;
|
|
|
|
|
private List<Models.Commit> _commits = null;
|
|
|
|
|
private Models.Commit _selectedCommit = null;
|
|
|
|
|
private DiffContext _diffContext = null;
|
|
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|