2024-03-17 18:37:06 -07:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
using Avalonia.Threading;
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class Blame : ObservableObject
|
|
|
|
|
{
|
|
|
|
|
public string Title
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get;
|
|
|
|
|
private set;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string SelectedSHA
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _selectedSHA;
|
|
|
|
|
private set => SetProperty(ref _selectedSHA, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public bool IsBinary
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _data != null && _data.IsBinary;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public Models.BlameData Data
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _data;
|
|
|
|
|
private set => SetProperty(ref _data, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public Blame(string repo, string file, string revision)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo = repo;
|
|
|
|
|
|
2024-03-14 19:41:36 -07:00
|
|
|
|
Title = $"{file} @ {revision.Substring(0, 10)}";
|
2024-03-17 18:37:06 -07:00
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var result = new Commands.Blame(repo, file, revision).Result();
|
2024-03-17 18:37:06 -07:00
|
|
|
|
Dispatcher.UIThread.Invoke(() =>
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Data = result;
|
|
|
|
|
OnPropertyChanged(nameof(IsBinary));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
private string _selectedSHA = string.Empty;
|
|
|
|
|
private Models.BlameData _data = null;
|
|
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|