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 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-26 00:56:38 -07:00
|
|
|
|
DetailContext.Commit = 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-03-26 00:56:38 -07:00
|
|
|
|
DetailContext.Commit = value;
|
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-26 00:56:38 -07:00
|
|
|
|
public CommitDetail DetailContext
|
|
|
|
|
{
|
|
|
|
|
get => _detailContext;
|
|
|
|
|
set => SetProperty(ref _detailContext, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-05 02:34:49 -07:00
|
|
|
|
public FileHistories(string repo, string file, IssueTrackerRuleSetting issueTrackerSetting)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo = repo;
|
|
|
|
|
_file = file;
|
2024-08-05 02:34:49 -07:00
|
|
|
|
_detailContext = new CommitDetail(repo, issueTrackerSetting);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
2024-06-06 21:31:10 -07:00
|
|
|
|
var commits = new Commands.QueryCommits(_repo, $"-n 10000 -- \"{file}\"", false).Result();
|
2024-03-17 18:37:06 -07:00
|
|
|
|
Dispatcher.UIThread.Invoke(() =>
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
IsLoading = false;
|
|
|
|
|
Commits = commits;
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (commits.Count > 0)
|
|
|
|
|
SelectedCommit = commits[0];
|
2024-02-05 23:08:37 -08:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-14 09:30:31 -07:00
|
|
|
|
private readonly string _repo = null;
|
|
|
|
|
private readonly string _file = null;
|
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-26 00:56:38 -07:00
|
|
|
|
private CommitDetail _detailContext = null;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|