feature: support creating custom action for selected remote (#1726)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2025-08-14 17:53:11 +08:00
parent c4ae21ea71
commit d66a083113
10 changed files with 55 additions and 39 deletions

View File

@@ -119,35 +119,11 @@ namespace SourceGit.ViewModels
get;
} = [];
public ExecuteCustomAction(Repository repo, Models.CustomAction action)
public ExecuteCustomAction(Repository repo, Models.CustomAction action, object scopeTarget)
{
_repo = repo;
CustomAction = action;
Target = new Models.Null();
PrepareControlParameters();
}
public ExecuteCustomAction(Repository repo, Models.CustomAction action, Models.Branch branch)
{
_repo = repo;
CustomAction = action;
Target = branch;
PrepareControlParameters();
}
public ExecuteCustomAction(Repository repo, Models.CustomAction action, Models.Commit commit)
{
_repo = repo;
CustomAction = action;
Target = commit;
PrepareControlParameters();
}
public ExecuteCustomAction(Repository repo, Models.CustomAction action, Models.Tag tag)
{
_repo = repo;
CustomAction = action;
Target = tag;
Target = scopeTarget ?? new Models.Null();
PrepareControlParameters();
}
@@ -206,9 +182,10 @@ namespace SourceGit.ViewModels
return Target switch
{
Models.Branch b => org.Replace("${BRANCH}", b.FriendlyName),
Models.Branch b => org.Replace("${BRANCH}", b.FriendlyName).Replace("${REMOTE}", b.Remote),
Models.Commit c => org.Replace("${SHA}", c.SHA),
Models.Tag t => org.Replace("${TAG}", t.Name),
Models.Remote r => org.Replace("${REMOTE}", r.Name),
_ => org
};
}

View File

@@ -876,19 +876,12 @@ namespace SourceGit.ViewModels
ShowPopup(new Apply(this));
}
public async Task ExecCustomActionAsync(Models.CustomAction action, object scope)
public async Task ExecCustomActionAsync(Models.CustomAction action, object scopeTarget)
{
if (!CanCreatePopup())
return;
var popup = scope switch
{
Models.Branch b => new ExecuteCustomAction(this, action, b),
Models.Commit c => new ExecuteCustomAction(this, action, c),
Models.Tag t => new ExecuteCustomAction(this, action, t),
_ => new ExecuteCustomAction(this, action)
};
var popup = new ExecuteCustomAction(this, action, scopeTarget);
if (action.Controls.Count == 0)
await ShowAndStartPopupAsync(popup);
else