sourcegit/src/ViewModels/Blame.cs
leo 7f389b2e6f
refactor: move settings of repository, such as filters, commit message, from Preference to each repository's gitdir.
* avoid invalid repository setting remains in preference.json
* supports to restore tabs that not added to the Welcome page
2024-07-01 11:57:13 +08:00

60 lines
1.5 KiB
C#

using System.Threading.Tasks;
using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
namespace SourceGit.ViewModels
{
public class Blame : ObservableObject
{
public string Title
{
get;
private set;
}
public string SelectedSHA
{
get => _selectedSHA;
private set => SetProperty(ref _selectedSHA, value);
}
public bool IsBinary
{
get => _data != null && _data.IsBinary;
}
public Models.BlameData Data
{
get => _data;
private set => SetProperty(ref _data, value);
}
public Blame(string repo, string file, string revision)
{
_repo = repo;
Title = $"{file} @ {revision.Substring(0, 10)}";
Task.Run(() =>
{
var result = new Commands.Blame(repo, file, revision).Result();
Dispatcher.UIThread.Invoke(() =>
{
Data = result;
OnPropertyChanged(nameof(IsBinary));
});
});
}
public void NavigateToCommit(string commitSHA)
{
var repo = App.FindOpenedRepository(_repo);
repo?.NavigateToCommit(commitSHA);
}
private readonly string _repo = string.Empty;
private string _selectedSHA = string.Empty;
private Models.BlameData _data = null;
}
}