sourcegit/src/ViewModels/Blame.cs
leo 96d4150d26 project: reorganize the structure of the project.
* remove dotnet-tool.json because the project does not rely on any dotnet tools.
* remove Directory.Build.props because the solution has only one project.
* move src/SourceGit to src. It's not needed to put all sources into a subfolder of src since there's only one project.
2024-04-02 20:00:33 +08:00

61 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 = Preference.FindRepository(_repo);
if (repo != null)
repo.NavigateToCommit(commitSHA);
}
private readonly string _repo = string.Empty;
private string _selectedSHA = string.Empty;
private Models.BlameData _data = null;
}
}