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.Media;
|
|
|
|
|
|
|
|
|
|
namespace SourceGit.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class ResetMode
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
public string Desc { get; set; }
|
|
|
|
|
public string Arg { get; set; }
|
|
|
|
|
public IBrush Color { get; set; }
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public ResetMode(string n, string d, string a, IBrush b)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Name = n;
|
|
|
|
|
Desc = d;
|
|
|
|
|
Arg = a;
|
|
|
|
|
Color = b;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public class Reset : Popup
|
|
|
|
|
{
|
|
|
|
|
public Models.Branch Current
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get;
|
|
|
|
|
private set;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public Models.Commit To
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get;
|
|
|
|
|
private set;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public List<ResetMode> Modes
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get;
|
|
|
|
|
private set;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public ResetMode SelectedMode
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public Reset(Repository repo, Models.Branch current, Models.Commit to)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo = repo;
|
|
|
|
|
Current = current;
|
|
|
|
|
To = to;
|
|
|
|
|
Modes = new List<ResetMode>() {
|
|
|
|
|
new ResetMode("Soft", "Keep all changes. Stage differences", "--soft", Brushes.Green),
|
|
|
|
|
new ResetMode("Mixed", "Keep all changes. Unstage differences", "--mixed", Brushes.Orange),
|
|
|
|
|
new ResetMode("Hard", "Discard all changes", "--hard", Brushes.Red),
|
|
|
|
|
};
|
|
|
|
|
SelectedMode = Modes[0];
|
|
|
|
|
View = new Views.Reset() { DataContext = this };
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public override Task<bool> Sure()
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo.SetWatcherEnabled(false);
|
2024-02-25 19:29:57 -08:00
|
|
|
|
ProgressDescription = $"Reset current branch to {To.SHA} ...";
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
return Task.Run(() =>
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var succ = new Commands.Reset(_repo.FullPath, To.SHA, SelectedMode.Arg).Exec();
|
|
|
|
|
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
|
|
|
|
return succ;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private readonly Repository _repo = null;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|