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
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
public class DiscardModeAll { }
|
|
|
|
|
public class DiscardModeSingle { public string File { get; set; } }
|
|
|
|
|
public class DiscardModeMulti { public int Count { get; set; } }
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
Mode = new DiscardModeAll();
|
|
|
|
|
View = new Views.Discard { DataContext = this };
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public Discard(Repository repo, List<Models.Change> changes, bool isUnstaged)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo = repo;
|
|
|
|
|
_changes = changes;
|
2024-02-29 19:34:32 -08:00
|
|
|
|
_isUnstaged = isUnstaged;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (_changes == null)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Mode = new DiscardModeAll();
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else if (_changes.Count == 1)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Mode = new DiscardModeSingle() { File = _changes[0].Path };
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Mode = new DiscardModeMulti() { Count = _changes.Count };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 if (_isUnstaged)
|
2024-02-29 19:34:32 -08:00
|
|
|
|
Commands.Discard.ChangesInWorkTree(_repo.FullPath, _changes);
|
2024-03-17 18:37:06 -07:00
|
|
|
|
else
|
2024-02-29 19:34:32 -08:00
|
|
|
|
Commands.Discard.ChangesInStaged(_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;
|
|
|
|
|
private readonly bool _isUnstaged = true;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|