mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-25 11:24:02 +08:00
project: reorganize the structure of the project.
* remove dotnet-tool.json because the project does not rely on any dotnet tools. * remove Directory.Build.props because the solution has only one project. * move src/SourceGit to src. It's not needed to put all sources into a subfolder of src since there's only one project.
This commit is contained in:
76
src/ViewModels/AddSubmodule.cs
Normal file
76
src/ViewModels/AddSubmodule.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SourceGit.ViewModels
|
||||
{
|
||||
public class AddSubmodule : Popup
|
||||
{
|
||||
[Required(ErrorMessage = "Url is required!!!")]
|
||||
[CustomValidation(typeof(AddSubmodule), nameof(ValidateURL))]
|
||||
public string Url
|
||||
{
|
||||
get => _url;
|
||||
set => SetProperty(ref _url, value, true);
|
||||
}
|
||||
|
||||
[Required(ErrorMessage = "Reletive path is required!!!")]
|
||||
[CustomValidation(typeof(AddSubmodule), nameof(ValidateRelativePath))]
|
||||
public string RelativePath
|
||||
{
|
||||
get => _relativePath;
|
||||
set => SetProperty(ref _relativePath, value, true);
|
||||
}
|
||||
|
||||
public bool Recursive
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public AddSubmodule(Repository repo)
|
||||
{
|
||||
_repo = repo;
|
||||
View = new Views.AddSubmodule() { DataContext = this };
|
||||
}
|
||||
|
||||
public static ValidationResult ValidateURL(string url, ValidationContext ctx)
|
||||
{
|
||||
if (!Models.Remote.IsValidURL(url))
|
||||
return new ValidationResult("Invalid repository URL format");
|
||||
return ValidationResult.Success;
|
||||
}
|
||||
|
||||
public static ValidationResult ValidateRelativePath(string path, ValidationContext ctx)
|
||||
{
|
||||
if (Path.Exists(path))
|
||||
{
|
||||
return new ValidationResult("Give path is exists already!");
|
||||
}
|
||||
|
||||
if (Path.IsPathRooted(path))
|
||||
{
|
||||
return new ValidationResult("Path must be relative to this repository!");
|
||||
}
|
||||
|
||||
return ValidationResult.Success;
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
{
|
||||
_repo.SetWatcherEnabled(false);
|
||||
ProgressDescription = "Adding submodule...";
|
||||
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var succ = new Commands.Submodule(_repo.FullPath).Add(_url, _relativePath, Recursive, SetProgressDescription);
|
||||
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
||||
return succ;
|
||||
});
|
||||
}
|
||||
|
||||
private readonly Repository _repo = null;
|
||||
private string _url = string.Empty;
|
||||
private string _relativePath = string.Empty;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user