private static string AskToSpecify(IEnumerable <string> options, IScriptHostControl scriptHostControl) { using (var f = new FormQuickStringSelector()) { f.Location = scriptHostControl?.GetQuickItemSelectorLocation() ?? new System.Drawing.Point(); f.Init(options.ToList()); f.ShowDialog(); return(f.SelectedString); } }
public void Initialize([CanBeNull] IAheadBehindDataProvider aheadBehindDataProvider, FilterBranchHelper filterBranchHelper, ICheckRefs refsSource, IScriptHostControl scriptHost) { _aheadBehindDataProvider = aheadBehindDataProvider; _filterBranchHelper = filterBranchHelper; _refsSource = refsSource; _scriptHost = scriptHost; // This lazily sets the command source, invoking OnUICommandsSourceSet, which is required for setting up // notifications for each Tree. _ = UICommandsSource; }
private static string AskToSpecify(IEnumerable <IGitRef> options, IScriptHostControl scriptHostControl) { var items = options.ToList(); if (items.Count == 0) { return(string.Empty); } using (var f = new FormQuickGitRefSelector()) { f.Location = scriptHostControl?.GetQuickItemSelectorLocation() ?? new System.Drawing.Point(); f.Init(FormQuickGitRefSelector.Action.Select, items); f.ShowDialog(); return(f.SelectedRef.Name); } }
private static GitRevision GetCurrentRevision( [NotNull] IGitModule module, [CanBeNull] IScriptHostControl scriptHostControl, List <IGitRef> currentTags, List <IGitRef> currentLocalBranches, List <IGitRef> currentRemoteBranches, List <IGitRef> currentBranches) { GitRevision currentRevision; IEnumerable <IGitRef> refs; if (scriptHostControl == null) { var currentRevisionGuid = module.GetCurrentCheckout(); currentRevision = currentRevisionGuid == null ? null : new GitRevision(currentRevisionGuid); refs = module.GetRefs(true, true).Where(gitRef => gitRef.ObjectId == currentRevisionGuid); } else { currentRevision = scriptHostControl.GetCurrentRevision(); refs = currentRevision?.Refs ?? Array.Empty <IGitRef>(); } foreach (var gitRef in refs) { if (gitRef.IsTag) { currentTags.Add(gitRef); } else if (gitRef.IsHead || gitRef.IsRemote) { currentBranches.Add(gitRef); if (gitRef.IsRemote) { currentRemoteBranches.Add(gitRef); } else { currentLocalBranches.Add(gitRef); } } } return(currentRevision); }
private static GitRevision CalculateSelectedRevision(IScriptHostControl scriptHostControl, List <IGitRef> selectedRemoteBranches, List <string> selectedRemotes, List <IGitRef> selectedLocalBranches, List <IGitRef> selectedBranches, List <IGitRef> selectedTags) { GitRevision selectedRevision = scriptHostControl?.GetLatestSelectedRevision(); if (selectedRevision == null) { return(null); } foreach (var head in selectedRevision.Refs) { if (head.IsTag) { selectedTags.Add(head); } else if (head.IsHead || head.IsRemote) { selectedBranches.Add(head); if (head.IsRemote) { selectedRemoteBranches.Add(head); if (!selectedRemotes.Contains(head.Remote)) { selectedRemotes.Add(head.Remote); } } else { selectedLocalBranches.Add(head); } } } return(selectedRevision); }
public void Setup() { _module = Substitute.For <IGitModule>(); _scriptHostControl = Substitute.For <IScriptHostControl>(); }
public static (string arguments, bool abort) Parse([CanBeNull] string arguments, [NotNull] IGitModule module, IWin32Window owner, IScriptHostControl scriptHostControl) { if (string.IsNullOrWhiteSpace(arguments)) { return(arguments, abort : false); } module = module ?? throw new ArgumentNullException(nameof(module)); GitRevision selectedRevision = null; GitRevision currentRevision = null; IReadOnlyList <GitRevision> allSelectedRevisions = Array.Empty <GitRevision>(); var selectedLocalBranches = new List <IGitRef>(); var selectedRemoteBranches = new List <IGitRef>(); var selectedRemotes = new List <string>(); var selectedBranches = new List <IGitRef>(); var selectedTags = new List <IGitRef>(); var currentLocalBranches = new List <IGitRef>(); var currentRemoteBranches = new List <IGitRef>(); var currentRemote = ""; var currentBranches = new List <IGitRef>(); var currentTags = new List <IGitRef>(); foreach (string option in Options) { if (!Contains(arguments, option)) { continue; } if (currentRevision == null && option.StartsWith("c")) { currentRevision = GetCurrentRevision(module, scriptHostControl, currentTags, currentLocalBranches, currentRemoteBranches, currentBranches); if (currentRevision == null) { return(arguments : null, abort : true); } if (currentLocalBranches.Count == 1) { currentRemote = module.GetSetting(string.Format(SettingKeyString.BranchRemote, currentLocalBranches[0].Name)); } else { currentRemote = module.GetCurrentRemote(); if (string.IsNullOrEmpty(currentRemote)) { currentRemote = module.GetSetting(string.Format(SettingKeyString.BranchRemote, AskToSpecify(currentLocalBranches, scriptHostControl))); } } } else if (selectedRevision == null && scriptHostControl != null && DependsOnSelectedRevision(option)) { allSelectedRevisions = scriptHostControl.GetSelectedRevisions() ?? Array.Empty <GitRevision>(); selectedRevision = CalculateSelectedRevision(scriptHostControl, selectedRemoteBranches, selectedRemotes, selectedLocalBranches, selectedBranches, selectedTags); if (selectedRevision == null) { return(arguments : null, abort : true); } } arguments = ParseScriptArguments(arguments, option, owner, scriptHostControl, module, allSelectedRevisions, selectedTags, selectedBranches, selectedLocalBranches, selectedRemoteBranches, selectedRemotes, selectedRevision, currentTags, currentBranches, currentLocalBranches, currentRemoteBranches, currentRevision, currentRemote); if (arguments == null) { return(arguments : null, abort : true); } } return(arguments, abort : false); }
private static string ParseScriptArguments([NotNull] string arguments, [NotNull] string option, IWin32Window owner, IScriptHostControl scriptHostControl, IGitModule module, IReadOnlyList <GitRevision> allSelectedRevisions, in IList <IGitRef> selectedTags, in IList <IGitRef> selectedBranches, in IList <IGitRef> selectedLocalBranches,