2024-06-30 20:57:13 -07:00
|
|
|
|
using System.Threading.Tasks;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class Init : Popup
|
|
|
|
|
{
|
|
|
|
|
public string TargetPath
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _targetPath;
|
|
|
|
|
set => SetProperty(ref _targetPath, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-20 02:36:43 -07:00
|
|
|
|
public Init(string path, RepositoryNode parent)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-05-20 02:36:43 -07:00
|
|
|
|
_targetPath = path;
|
|
|
|
|
_parentNode = parent;
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
View = new Views.Init() { DataContext = this };
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public override Task<bool> Sure()
|
|
|
|
|
{
|
2024-02-25 19:29:57 -08:00
|
|
|
|
ProgressDescription = $"Initialize git repository at: '{_targetPath}'";
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
return Task.Run(() =>
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var succ = new Commands.Init(HostPageId, _targetPath).Exec();
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (!succ)
|
|
|
|
|
return false;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
CallUIThread(() =>
|
|
|
|
|
{
|
2024-06-30 20:57:13 -07:00
|
|
|
|
var normalizedPath = _targetPath.Replace("\\", "/");
|
2024-07-22 00:34:31 -07:00
|
|
|
|
Preference.Instance.FindOrAddNodeByRepositoryPath(normalizedPath, _parentNode, true);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-14 09:30:31 -07:00
|
|
|
|
private string _targetPath = null;
|
2024-05-20 02:36:43 -07:00
|
|
|
|
private RepositoryNode _parentNode = null;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|