Skip to content

Commit cf8cff6

Browse files
committed
code_style: add ViewModels.Repository.GetCustomAction(scope)
Signed-off-by: leo <[email protected]>
1 parent 5c279b4 commit cf8cff6

File tree

2 files changed

+22
-37
lines changed

2 files changed

+22
-37
lines changed

src/ViewModels/Histories.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -694,17 +694,7 @@ public ContextMenu MakeContextMenu(ListBox list)
694694
menu.Items.Add(archive);
695695
menu.Items.Add(new MenuItem() { Header = "-" });
696696

697-
var actions = new List<Models.CustomAction>();
698-
foreach (var action in Preferences.Instance.CustomActions)
699-
{
700-
if (action.Scope == Models.CustomActionScope.Commit)
701-
actions.Add(action);
702-
}
703-
foreach (var action in _repo.Settings.CustomActions)
704-
{
705-
if (action.Scope == Models.CustomActionScope.Commit)
706-
actions.Add(action);
707-
}
697+
var actions = _repo.GetCustomActions(Models.CustomActionScope.Commit);
708698
if (actions.Count > 0)
709699
{
710700
var custom = new MenuItem();

src/ViewModels/Repository.cs

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,25 @@ public void AbortMerge()
943943
_workingCopy?.AbortMerge();
944944
}
945945

946+
public List<Models.CustomAction> GetCustomActions(Models.CustomActionScope scope)
947+
{
948+
var actions = new List<Models.CustomAction>();
949+
950+
foreach (var act in Preferences.Instance.CustomActions)
951+
{
952+
if (act.Scope == scope)
953+
actions.Add(act);
954+
}
955+
956+
foreach (var act in _settings.CustomActions)
957+
{
958+
if (act.Scope == scope)
959+
actions.Add(act);
960+
}
961+
962+
return actions;
963+
}
964+
946965
public void RefreshBranches()
947966
{
948967
var branches = new Commands.QueryBranches(_fullpath).Result();
@@ -1443,22 +1462,10 @@ public ContextMenu CreateContextMenuForGitLFS()
14431462

14441463
public ContextMenu CreateContextMenuForCustomAction()
14451464
{
1446-
var actions = new List<Models.CustomAction>();
1447-
foreach (var action in Preferences.Instance.CustomActions)
1448-
{
1449-
if (action.Scope == Models.CustomActionScope.Repository)
1450-
actions.Add(action);
1451-
}
1452-
1453-
foreach (var action in _settings.CustomActions)
1454-
{
1455-
if (action.Scope == Models.CustomActionScope.Repository)
1456-
actions.Add(action);
1457-
}
1458-
14591465
var menu = new ContextMenu();
14601466
menu.Placement = PlacementMode.BottomEdgeAlignedLeft;
14611467

1468+
var actions = GetCustomActions(Models.CustomActionScope.Repository);
14621469
if (actions.Count > 0)
14631470
{
14641471
foreach (var action in actions)
@@ -2355,19 +2362,7 @@ private BranchTreeNode FindBranchNode(List<BranchTreeNode> nodes, string path)
23552362

23562363
private void TryToAddCustomActionsToBranchContextMenu(ContextMenu menu, Models.Branch branch)
23572364
{
2358-
var actions = new List<Models.CustomAction>();
2359-
foreach (var action in Preferences.Instance.CustomActions)
2360-
{
2361-
if (action.Scope == Models.CustomActionScope.Branch)
2362-
actions.Add(action);
2363-
}
2364-
2365-
foreach (var action in Settings.CustomActions)
2366-
{
2367-
if (action.Scope == Models.CustomActionScope.Branch)
2368-
actions.Add(action);
2369-
}
2370-
2365+
var actions = GetCustomActions(Models.CustomActionScope.Branch);
23712366
if (actions.Count == 0)
23722367
return;
23732368

0 commit comments

Comments
 (0)