code_style: add ViewModels.Repository.GetCustomAction(scope)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-03-10 21:30:04 +08:00
parent 5c279b4b56
commit cf8cff6b64
No known key found for this signature in database
2 changed files with 22 additions and 37 deletions

View file

@ -694,17 +694,7 @@ namespace SourceGit.ViewModels
menu.Items.Add(archive); menu.Items.Add(archive);
menu.Items.Add(new MenuItem() { Header = "-" }); menu.Items.Add(new MenuItem() { Header = "-" });
var actions = new List<Models.CustomAction>(); var actions = _repo.GetCustomActions(Models.CustomActionScope.Commit);
foreach (var action in Preferences.Instance.CustomActions)
{
if (action.Scope == Models.CustomActionScope.Commit)
actions.Add(action);
}
foreach (var action in _repo.Settings.CustomActions)
{
if (action.Scope == Models.CustomActionScope.Commit)
actions.Add(action);
}
if (actions.Count > 0) if (actions.Count > 0)
{ {
var custom = new MenuItem(); var custom = new MenuItem();

View file

@ -943,6 +943,25 @@ namespace SourceGit.ViewModels
_workingCopy?.AbortMerge(); _workingCopy?.AbortMerge();
} }
public List<Models.CustomAction> GetCustomActions(Models.CustomActionScope scope)
{
var actions = new List<Models.CustomAction>();
foreach (var act in Preferences.Instance.CustomActions)
{
if (act.Scope == scope)
actions.Add(act);
}
foreach (var act in _settings.CustomActions)
{
if (act.Scope == scope)
actions.Add(act);
}
return actions;
}
public void RefreshBranches() public void RefreshBranches()
{ {
var branches = new Commands.QueryBranches(_fullpath).Result(); var branches = new Commands.QueryBranches(_fullpath).Result();
@ -1443,22 +1462,10 @@ namespace SourceGit.ViewModels
public ContextMenu CreateContextMenuForCustomAction() public ContextMenu CreateContextMenuForCustomAction()
{ {
var actions = new List<Models.CustomAction>();
foreach (var action in Preferences.Instance.CustomActions)
{
if (action.Scope == Models.CustomActionScope.Repository)
actions.Add(action);
}
foreach (var action in _settings.CustomActions)
{
if (action.Scope == Models.CustomActionScope.Repository)
actions.Add(action);
}
var menu = new ContextMenu(); var menu = new ContextMenu();
menu.Placement = PlacementMode.BottomEdgeAlignedLeft; menu.Placement = PlacementMode.BottomEdgeAlignedLeft;
var actions = GetCustomActions(Models.CustomActionScope.Repository);
if (actions.Count > 0) if (actions.Count > 0)
{ {
foreach (var action in actions) foreach (var action in actions)
@ -2355,19 +2362,7 @@ namespace SourceGit.ViewModels
private void TryToAddCustomActionsToBranchContextMenu(ContextMenu menu, Models.Branch branch) private void TryToAddCustomActionsToBranchContextMenu(ContextMenu menu, Models.Branch branch)
{ {
var actions = new List<Models.CustomAction>(); var actions = GetCustomActions(Models.CustomActionScope.Branch);
foreach (var action in Preferences.Instance.CustomActions)
{
if (action.Scope == Models.CustomActionScope.Branch)
actions.Add(action);
}
foreach (var action in Settings.CustomActions)
{
if (action.Scope == Models.CustomActionScope.Branch)
actions.Add(action);
}
if (actions.Count == 0) if (actions.Count == 0)
return; return;