enhance: simpfy the way to lock a worktree

This commit is contained in:
leo
2024-06-27 19:19:21 +08:00
parent 8a8aabede3
commit fa2c7c0e18
10 changed files with 25 additions and 125 deletions

View File

@@ -13,10 +13,10 @@ namespace SourceGit.ViewModels
[Required(ErrorMessage = "Worktree path is required!")]
[CustomValidation(typeof(AddWorktree), nameof(ValidateWorktreePath))]
public string FullPath
public string Path
{
get => _fullPath;
set => SetProperty(ref _fullPath, value, true);
get => _path;
set => SetProperty(ref _path, value, true);
}
[CustomValidation(typeof(AddWorktree), nameof(ValidateBranchName))]
@@ -63,9 +63,14 @@ namespace SourceGit.ViewModels
View = new Views.AddWorktree() { DataContext = this };
}
public static ValidationResult ValidateWorktreePath(string folder, ValidationContext _)
public static ValidationResult ValidateWorktreePath(string path, ValidationContext ctx)
{
var info = new DirectoryInfo(folder);
var creator = ctx.ObjectInstance as AddWorktree;
if (creator == null)
return new ValidationResult("Missing runtime context to create branch!");
var fullPath = System.IO.Path.IsPathRooted(path) ? path : System.IO.Path.Combine(creator._repo.FullPath, path);
var info = new DirectoryInfo(fullPath);
if (info.Exists)
{
var files = info.GetFiles();
@@ -108,14 +113,14 @@ namespace SourceGit.ViewModels
return Task.Run(() =>
{
var succ = new Commands.Worktree(_repo.FullPath).Add(_fullPath, _customName, tracking, SetProgressDescription);
var succ = new Commands.Worktree(_repo.FullPath).Add(_path, _customName, tracking, SetProgressDescription);
CallUIThread(() => _repo.SetWatcherEnabled(true));
return succ;
});
}
private Repository _repo = null;
private string _fullPath = string.Empty;
private string _path = string.Empty;
private string _customName = string.Empty;
private bool _setTrackingBranch = false;
}

View File

@@ -1,44 +0,0 @@
using System.Threading.Tasks;
namespace SourceGit.ViewModels
{
public class LockWorktree : Popup
{
public Models.Worktree Target
{
get;
private set;
} = null;
public string Reason
{
get;
set;
} = string.Empty;
public LockWorktree(Repository repo, Models.Worktree target)
{
_repo = repo;
Target = target;
View = new Views.LockWorktree() { DataContext = this };
}
public override Task<bool> Sure()
{
_repo.SetWatcherEnabled(false);
ProgressDescription = "Locking worktrees ...";
return Task.Run(() =>
{
var succ = new Commands.Worktree(_repo.FullPath).Lock(Target.FullPath, Reason);
if (succ)
Target.IsLocked = true;
CallUIThread(() => _repo.SetWatcherEnabled(true));
return true;
});
}
private Repository _repo = null;
}
}

View File

@@ -1731,8 +1731,11 @@ namespace SourceGit.ViewModels
loc.Icon = App.CreateMenuIcon("Icons.Lock");
loc.Click += (o, ev) =>
{
if (PopupHost.CanCreatePopup())
PopupHost.ShowPopup(new LockWorktree(this, worktree));
SetWatcherEnabled(false);
var succ = new Commands.Worktree(_fullpath).Lock(worktree.FullPath);
if (succ)
worktree.IsLocked = true;
SetWatcherEnabled(true);
ev.Handled = true;
};
menu.Items.Add(loc);