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 StashesPage : ObservableObject
|
|
|
|
|
{
|
|
|
|
|
public int Count
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _stashes == null ? 0 : _stashes.Count;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public List<Models.Stash> Stashes
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _stashes;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (SetProperty(ref _stashes, value))
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
SelectedStash = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public Models.Stash SelectedStash
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _selectedStash;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (SetProperty(ref _selectedStash, value))
|
|
|
|
|
{
|
|
|
|
|
if (value == null)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Changes = null;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var changes = new Commands.QueryStashChanges(_repo.FullPath, value.SHA).Result();
|
2024-03-17 18:37:06 -07:00
|
|
|
|
Dispatcher.UIThread.Invoke(() =>
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Changes = changes;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public List<Models.Change> Changes
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _changes;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private set
|
|
|
|
|
{
|
|
|
|
|
if (SetProperty(ref _changes, value))
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
SelectedChange = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public Models.Change SelectedChange
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _selectedChange;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (SetProperty(ref _selectedChange, value))
|
|
|
|
|
{
|
|
|
|
|
if (value == null)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
DiffContext = null;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-03-20 03:27:48 -07:00
|
|
|
|
DiffContext = new DiffContext(_repo.FullPath, new Models.DiffOption($"{_selectedStash.SHA}^", _selectedStash.SHA, value), _diffContext);
|
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;
|
|
|
|
|
private set => SetProperty(ref _diffContext, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public StashesPage(Repository repo)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo = repo;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void Cleanup()
|
|
|
|
|
{
|
2024-02-20 02:27:59 -08:00
|
|
|
|
_repo = null;
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (_stashes != null)
|
|
|
|
|
_stashes.Clear();
|
2024-02-20 02:27:59 -08:00
|
|
|
|
_selectedStash = null;
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (_changes != null)
|
|
|
|
|
_changes.Clear();
|
2024-02-20 02:27:59 -08:00
|
|
|
|
_selectedChange = null;
|
|
|
|
|
_diffContext = null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void Apply(object param)
|
|
|
|
|
{
|
|
|
|
|
if (param is Models.Stash stash)
|
|
|
|
|
{
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
new Commands.Stash(_repo.FullPath).Apply(stash.Name);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void Pop(object param)
|
|
|
|
|
{
|
|
|
|
|
if (param is Models.Stash stash)
|
|
|
|
|
{
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
new Commands.Stash(_repo.FullPath).Pop(stash.Name);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void Drop(object param)
|
|
|
|
|
{
|
|
|
|
|
if (param is Models.Stash stash && PopupHost.CanCreatePopup())
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
PopupHost.ShowPopup(new DropStash(_repo.FullPath, stash));
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void Clear()
|
|
|
|
|
{
|
|
|
|
|
if (PopupHost.CanCreatePopup())
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
PopupHost.ShowPopup(new ClearStashes(_repo));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Repository _repo = null;
|
|
|
|
|
private List<Models.Stash> _stashes = null;
|
|
|
|
|
private Models.Stash _selectedStash = null;
|
|
|
|
|
private List<Models.Change> _changes = null;
|
|
|
|
|
private Models.Change _selectedChange = null;
|
|
|
|
|
private DiffContext _diffContext = null;
|
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|