2024-02-05 23:08:37 -08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class Discard : Popup
|
|
|
|
|
{
|
|
|
|
|
public object Mode
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get;
|
|
|
|
|
private set;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public Discard(Repository repo)
|
|
|
|
|
{
|
2024-02-29 19:34:32 -08:00
|
|
|
|
_repo = repo;
|
|
|
|
|
|
2024-07-27 06:35:57 -07:00
|
|
|
|
Mode = new Models.Null();
|
2024-02-29 19:34:32 -08:00
|
|
|
|
View = new Views.Discard { DataContext = this };
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-30 21:04:29 -07:00
|
|
|
|
public Discard(Repository repo, List<Models.Change> changes)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo = repo;
|
|
|
|
|
_changes = changes;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (_changes == null)
|
2024-07-27 06:35:57 -07:00
|
|
|
|
Mode = new Models.Null();
|
2024-03-17 18:37:06 -07:00
|
|
|
|
else if (_changes.Count == 1)
|
2024-07-26 00:02:23 -07:00
|
|
|
|
Mode = _changes[0].Path;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
else
|
2024-07-26 00:02:23 -07:00
|
|
|
|
Mode = _changes.Count;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
|
|
|
|
View = new Views.Discard() { 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 = _changes == null ? "Discard all local changes ..." : $"Discard total {_changes.Count} changes ...";
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
return Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
if (_changes == null)
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Commands.Discard.All(_repo.FullPath);
|
2024-03-17 18:37:06 -07:00
|
|
|
|
else
|
2024-07-30 21:04:29 -07:00
|
|
|
|
Commands.Discard.Changes(_repo.FullPath, _changes);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-07-09 00:30:40 -07:00
|
|
|
|
CallUIThread(() =>
|
|
|
|
|
{
|
|
|
|
|
_repo.MarkWorkingCopyDirtyManually();
|
|
|
|
|
_repo.SetWatcherEnabled(true);
|
|
|
|
|
});
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private readonly Repository _repo = null;
|
|
|
|
|
private readonly List<Models.Change> _changes = null;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|