sourcegit/src/ViewModels/UpdateSubmodules.cs

88 lines
2 KiB
C#
Raw Normal View History

2024-07-26 03:49:07 -07:00
using System.Collections.Generic;
using System.Threading.Tasks;
namespace SourceGit.ViewModels
{
public class UpdateSubmodules : Popup
{
2024-07-26 03:49:07 -07:00
public List<string> Submodules
{
get;
private set;
} = new List<string>();
2024-07-26 03:49:07 -07:00
public string SelectedSubmodule
{
get;
set;
}
public bool UpdateAll
{
get => _updateAll;
set => SetProperty(ref _updateAll, value);
}
public bool EnableInit
{
get;
set;
} = true;
public bool EnableRecursive
{
get;
set;
} = true;
public bool EnableRemote
{
get;
set;
} = false;
public UpdateSubmodules(Repository repo)
{
_repo = repo;
foreach (var submodule in _repo.Submodules)
Submodules.Add(submodule.Path);
SelectedSubmodule = Submodules.Count > 0 ? Submodules[0] : string.Empty;
View = new Views.UpdateSubmodules() { DataContext = this };
}
public override Task<bool> Sure()
{
_repo.SetWatcherEnabled(false);
2024-07-26 03:49:07 -07:00
string target = string.Empty;
if (_updateAll)
{
ProgressDescription = "Updating submodules ...";
}
else
{
target = SelectedSubmodule;
ProgressDescription = $"Updating submodule {target} ...";
}
return Task.Run(() =>
{
2024-07-26 03:49:07 -07:00
new Commands.Submodule(_repo.FullPath).Update(
target,
EnableInit,
EnableRecursive,
EnableRemote,
SetProgressDescription);
CallUIThread(() => _repo.SetWatcherEnabled(true));
return true;
});
}
private readonly Repository _repo = null;
2024-07-26 03:49:07 -07:00
private bool _updateAll = true;
}
}