diff --git a/src/ViewModels/Histories.cs b/src/ViewModels/Histories.cs index 301cbb3c..707e8c43 100644 --- a/src/ViewModels/Histories.cs +++ b/src/ViewModels/Histories.cs @@ -694,17 +694,7 @@ namespace SourceGit.ViewModels menu.Items.Add(archive); menu.Items.Add(new MenuItem() { Header = "-" }); - var actions = new List(); - 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); - } + var actions = _repo.GetCustomActions(Models.CustomActionScope.Commit); if (actions.Count > 0) { var custom = new MenuItem(); diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 5d2778c9..96d0b36c 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -943,6 +943,25 @@ namespace SourceGit.ViewModels _workingCopy?.AbortMerge(); } + public List GetCustomActions(Models.CustomActionScope scope) + { + var actions = new List(); + + 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() { var branches = new Commands.QueryBranches(_fullpath).Result(); @@ -1443,22 +1462,10 @@ namespace SourceGit.ViewModels public ContextMenu CreateContextMenuForCustomAction() { - var actions = new List(); - 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(); menu.Placement = PlacementMode.BottomEdgeAlignedLeft; + var actions = GetCustomActions(Models.CustomActionScope.Repository); if (actions.Count > 0) { foreach (var action in actions) @@ -2355,19 +2362,7 @@ namespace SourceGit.ViewModels private void TryToAddCustomActionsToBranchContextMenu(ContextMenu menu, Models.Branch branch) { - var actions = new List(); - 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); - } - + var actions = GetCustomActions(Models.CustomActionScope.Branch); if (actions.Count == 0) return;