private static GitRevision CalculateSelectedRevision(RevisionGridControl revisionGrid, List <IGitRef> selectedRemoteBranches, List <string> selectedRemotes, List <IGitRef> selectedLocalBranches, List <IGitRef> selectedBranches, List <IGitRef> selectedTags) { GitRevision selectedRevision = revisionGrid.LatestSelectedRevision; 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 LoadBlame(GitRevision revision, [CanBeNull] IReadOnlyList <ObjectId> children, string fileName, RevisionGridControl revGrid, Control controlToMask, Encoding encoding, int?initialLine = null, bool force = false) { var objectId = revision.ObjectId; // refresh only when something changed if (!force && objectId == _blameId && fileName == _fileName && revGrid == _revGrid && encoding == _encoding) { return; } controlToMask?.Mask(); var scrollPos = BlameFile.VScrollPosition; var line = _clickedBlameLine is not null && _clickedBlameLine.Commit.ObjectId == objectId ? _clickedBlameLine.OriginLineNumber : initialLine ?? 0; _revGrid = revGrid; _fileName = fileName; _encoding = encoding; _blameLoader.LoadAsync(() => _blame = Module.Blame(fileName, objectId.ToString(), encoding), () => ProcessBlame(fileName, revision, children, controlToMask, line, scrollPos)); }
public FormBisect(RevisionGridControl revisionGrid) : base(revisionGrid.UICommands) { _revisionGrid = revisionGrid; InitializeComponent(); InitializeComplete(); UpdateButtonsState(); }
public RevisionGridMenuCommands(RevisionGridControl revisionGrid) { _revisionGrid = revisionGrid; NavigateMenuCommands = CreateNavigateMenuCommands(); ViewMenuCommands = CreateViewMenuCommands(); TranslationCategoryName = "RevisionGrid"; Translate(); }
public BuildServerWatcher(RevisionGridControl revisionGrid, RevisionDataGridView revisionGridView, Func <GitModule> module) { _revisionGrid = revisionGrid; _revisionGridView = revisionGridView; _module = module; _repoNameExtractor = new RepoNameExtractor(_module); ColumnProvider = new BuildStatusColumnProvider(revisionGrid, revisionGridView, _module); }
private static string AskToSpecify(IEnumerable <string> options, RevisionGridControl revisionGrid) { using (var f = new FormQuickStringSelector()) { f.Location = revisionGrid?.GetQuickItemSelectorLocation() ?? new System.Drawing.Point(); f.Init(options.ToList()); f.ShowDialog(); return(f.SelectedString); } }
public MessageColumnProvider(RevisionGridControl grid) : base("Message") { _grid = grid; Column = new DataGridViewTextBoxColumn { AutoSizeMode = DataGridViewAutoSizeColumnMode.None, HeaderText = "Message", ReadOnly = true, SortMode = DataGridViewColumnSortMode.NotSortable, Width = DpiUtil.Scale(500) }; }
public AuthorNameColumnProvider(RevisionGridControl grid, AuthorRevisionHighlighting authorHighlighting) : base("Author Name") { _grid = grid; _authorHighlighting = authorHighlighting; Column = new DataGridViewTextBoxColumn { AutoSizeMode = DataGridViewAutoSizeColumnMode.None, HeaderText = "Author Name", ReadOnly = true, SortMode = DataGridViewColumnSortMode.NotSortable, Width = DpiUtil.Scale(130) }; }
public BuildStatusColumnProvider(RevisionGridControl grid, RevisionDataGridView gridView, Func <GitModule> module) : base("Build Status") { _grid = grid; _gridView = gridView; _module = module; Column = new DataGridViewTextBoxColumn { HeaderText = "Build Status", ReadOnly = true, SortMode = DataGridViewColumnSortMode.NotSortable, Width = DpiUtil.Scale(TextColumnWidth) }; }
private CommandStatus ExecuteRunScript(IWin32Window owner, IGitModule module, string scriptKey, IGitUICommands uiCommands, RevisionGridControl revisionGrid, Action <string> showError) { var result = (CommandStatus)s_miRunScript.Invoke(null, new object[] { owner, module, scriptKey, uiCommands, revisionGrid, showError }); return(result); }
public GraphColumnProvider(RevisionGridControl grid, GraphModel graphModel) : base("Graph") { _grid = grid; _graphModel = graphModel; // TODO is it worth creating a lighter-weight column type? Column = new DataGridViewTextBoxColumn { AutoSizeMode = DataGridViewAutoSizeColumnMode.None, ReadOnly = true, SortMode = DataGridViewColumnSortMode.NotSortable, Resizable = DataGridViewTriState.False }; }
public CommitIdColumnProvider(RevisionGridControl grid) : base("Commit ID") { _grid = grid; Column = new DataGridViewTextBoxColumn { AutoSizeMode = DataGridViewAutoSizeColumnMode.None, HeaderText = "Commit ID", ReadOnly = true, SortMode = DataGridViewColumnSortMode.NotSortable, Resizable = DataGridViewTriState.True, Width = DpiUtil.Scale(60), MinimumWidth = DpiUtil.Scale(32) }; }
public MessageColumnProvider(RevisionGridControl grid, IGitRevisionSummaryBuilder gitRevisionSummaryBuilder) : base("Message") { _grid = grid; _gitRevisionSummaryBuilder = gitRevisionSummaryBuilder; Column = new DataGridViewTextBoxColumn { AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill, HeaderText = "Message", ReadOnly = true, SortMode = DataGridViewColumnSortMode.NotSortable, Width = DpiUtil.Scale(500), MinimumWidth = DpiUtil.Scale(25) }; }
public RevisionGraphColumnProvider(RevisionGridControl grid, RevisionGraph revisionGraph) : base("Graph") { _grid = grid; _revisionGraph = revisionGraph; // TODO is it worth creating a lighter-weight column type? Column = new DataGridViewTextBoxColumn { AutoSizeMode = DataGridViewAutoSizeColumnMode.None, ReadOnly = true, SortMode = DataGridViewColumnSortMode.NotSortable, Resizable = DataGridViewTriState.False, MinimumWidth = LaneWidth }; }
private static GitRevision GetCurrentRevision( IGitModule module, [CanBeNull] RevisionGridControl revisionGrid, List <IGitRef> currentTags, List <IGitRef> currentLocalBranches, List <IGitRef> currentRemoteBranches, List <IGitRef> currentBranches, [CanBeNull] GitRevision currentRevision) { if (currentRevision == null) { IEnumerable <IGitRef> refs; if (revisionGrid == null) { var currentRevisionGuid = module.GetCurrentCheckout(); currentRevision = new GitRevision(currentRevisionGuid); refs = module.GetRefs(true, true).Where(gitRef => gitRef.ObjectId == currentRevisionGuid).ToList(); } else { currentRevision = revisionGrid.GetCurrentRevision(); refs = currentRevision.Refs; } 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 CommandStatus ExecuteRunScript(IWin32Window owner, IGitModule module, string scriptKey, IGitUICommands uiCommands, RevisionGridControl revisionGrid) { try { var result = (CommandStatus)_miRunScript.Invoke(null, new object[] { owner, module, scriptKey, uiCommands, revisionGrid }); return(result); } catch (TargetInvocationException ex) { throw ex.InnerException; } }
public static CommandStatus RunScript(IWin32Window owner, IGitModule module, string scriptKey, IGitUICommands uiCommands, RevisionGridControl revisionGrid, Action <string> showError) { if (string.IsNullOrEmpty(scriptKey)) { return(false); } var script = ScriptManager.GetScript(scriptKey); if (script == null) { showError("Cannot find script: " + scriptKey); return(false); } if (string.IsNullOrEmpty(script.Command)) { return(false); } string arguments = script.Arguments; if (!string.IsNullOrEmpty(arguments) && revisionGrid == null) { string optionDependingOnSelectedRevision = ScriptOptionsParser.Options.FirstOrDefault(option => ScriptOptionsParser.DependsOnSelectedRevision(option) && ScriptOptionsParser.Contains(arguments, option)); if (optionDependingOnSelectedRevision != null) { showError($"Option {optionDependingOnSelectedRevision} is only supported when started with revision grid available."); return(false); } } return(RunScript(owner, module, script, uiCommands, revisionGrid, showError)); }
private static bool RunScript(IWin32Window owner, GitModule module, ScriptInfo scriptInfo, RevisionGridControl revisionGrid) { if (scriptInfo.AskConfirmation && MessageBox.Show(owner, $"Do you want to execute '{scriptInfo.Name}'?", "Script", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return(false); } string originalCommand = scriptInfo.Command; string argument = scriptInfo.Arguments; string command = OverrideCommandWhenNecessary(originalCommand); IReadOnlyList <GitRevision> allSelectedRevisions = Array.Empty <GitRevision>(); GitRevision selectedRevision = null; GitRevision currentRevision = null; 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 (string.IsNullOrEmpty(argument) || !argument.Contains(option)) { continue; } if (option.StartsWith("{c") && currentRevision == null) { currentRevision = GetCurrentRevision(module, revisionGrid, currentTags, currentLocalBranches, currentRemoteBranches, currentBranches, currentRevision); 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, "Current Revision Branch"))); } } } else if (option.StartsWith("{s") && selectedRevision == null && revisionGrid != null) { allSelectedRevisions = revisionGrid.GetSelectedRevisions(); allSelectedRevisions.Reverse(); // Put first clicked revisions first selectedRevision = CalculateSelectedRevision(revisionGrid, selectedRemoteBranches, selectedRemotes, selectedLocalBranches, selectedBranches, selectedTags); } string remote; string url; switch (option) { case "{sHashes}": argument = argument.Replace(option, string.Join(" ", allSelectedRevisions.Select(revision => revision.Guid).ToArray())); break; case "{sTag}": if (selectedTags.Count == 1) { argument = argument.Replace(option, selectedTags[0].Name); } else if (selectedTags.Count != 0) { argument = argument.Replace(option, AskToSpecify(selectedTags, "Selected Revision Tag")); } else { argument = argument.Replace(option, ""); } break; case "{sBranch}": if (selectedBranches.Count == 1) { argument = argument.Replace(option, selectedBranches[0].Name); } else if (selectedBranches.Count != 0) { argument = argument.Replace(option, AskToSpecify(selectedBranches, "Selected Revision Branch")); } else { argument = argument.Replace(option, ""); } break; case "{sLocalBranch}": if (selectedLocalBranches.Count == 1) { argument = argument.Replace(option, selectedLocalBranches[0].Name); } else if (selectedLocalBranches.Count != 0) { argument = argument.Replace(option, AskToSpecify(selectedLocalBranches, "Selected Revision Local Branch")); } else { argument = argument.Replace(option, ""); } break; case "{sRemoteBranch}": if (selectedRemoteBranches.Count == 1) { argument = argument.Replace(option, selectedRemoteBranches[0].Name); } else if (selectedRemoteBranches.Count != 0) { argument = argument.Replace(option, AskToSpecify(selectedRemoteBranches, "Selected Revision Remote Branch")); } else { argument = argument.Replace(option, ""); } break; case "{sRemote}": if (selectedRemotes.Count == 0) { argument = argument.Replace(option, ""); break; } remote = selectedRemotes.Count == 1 ? selectedRemotes[0] : AskToSpecify(selectedRemotes, "Selected Revision Remote"); argument = argument.Replace(option, remote); break; case "{sRemoteUrl}": if (selectedRemotes.Count == 0) { argument = argument.Replace(option, ""); break; } remote = selectedRemotes.Count == 1 ? selectedRemotes[0] : AskToSpecify(selectedRemotes, "Selected Revision Remote"); url = module.GetSetting(string.Format(SettingKeyString.RemoteUrl, remote)); argument = argument.Replace(option, url); break; case "{sRemotePathFromUrl}": if (selectedRemotes.Count == 0) { argument = argument.Replace(option, ""); break; } remote = selectedRemotes.Count == 1 ? selectedRemotes[0] : AskToSpecify(selectedRemotes, "Selected Revision Remote"); url = module.GetSetting(string.Format(SettingKeyString.RemoteUrl, remote)); argument = argument.Replace(option, GetRemotePath(url)); break; case "{sHash}": argument = argument.Replace(option, selectedRevision.Guid); break; case "{sMessage}": argument = argument.Replace(option, selectedRevision.Subject); break; case "{sAuthor}": argument = argument.Replace(option, selectedRevision.Author); break; case "{sCommitter}": argument = argument.Replace(option, selectedRevision.Committer); break; case "{sAuthorDate}": argument = argument.Replace(option, selectedRevision.AuthorDate.ToString()); break; case "{sCommitDate}": argument = argument.Replace(option, selectedRevision.CommitDate.ToString()); break; case "{cTag}": if (currentTags.Count == 1) { argument = argument.Replace(option, currentTags[0].Name); } else if (currentTags.Count != 0) { argument = argument.Replace(option, AskToSpecify(currentTags, "Current Revision Tag")); } else { argument = argument.Replace(option, ""); } break; case "{cBranch}": if (currentBranches.Count == 1) { argument = argument.Replace(option, currentBranches[0].Name); } else if (currentBranches.Count != 0) { argument = argument.Replace(option, AskToSpecify(currentBranches, "Current Revision Branch")); } else { argument = argument.Replace(option, ""); } break; case "{cLocalBranch}": if (currentLocalBranches.Count == 1) { argument = argument.Replace(option, currentLocalBranches[0].Name); } else if (currentLocalBranches.Count != 0) { argument = argument.Replace(option, AskToSpecify(currentLocalBranches, "Current Revision Local Branch")); } else { argument = argument.Replace(option, ""); } break; case "{cRemoteBranch}": if (currentRemoteBranches.Count == 1) { argument = argument.Replace(option, currentRemoteBranches[0].Name); } else if (currentRemoteBranches.Count != 0) { argument = argument.Replace(option, AskToSpecify(currentRemoteBranches, "Current Revision Remote Branch")); } else { argument = argument.Replace(option, ""); } break; case "{cHash}": argument = argument.Replace(option, currentRevision.Guid); break; case "{cMessage}": argument = argument.Replace(option, currentRevision.Subject); break; case "{cAuthor}": argument = argument.Replace(option, currentRevision.Author); break; case "{cCommitter}": argument = argument.Replace(option, currentRevision.Committer); break; case "{cAuthorDate}": argument = argument.Replace(option, currentRevision.AuthorDate.ToString()); break; case "{cCommitDate}": argument = argument.Replace(option, currentRevision.CommitDate.ToString()); break; case "{cDefaultRemote}": if (string.IsNullOrEmpty(currentRemote)) { argument = argument.Replace(option, ""); break; } argument = argument.Replace(option, currentRemote); break; case "{cDefaultRemoteUrl}": if (string.IsNullOrEmpty(currentRemote)) { argument = argument.Replace(option, ""); break; } url = module.GetSetting(string.Format(SettingKeyString.RemoteUrl, currentRemote)); argument = argument.Replace(option, url); break; case "{cDefaultRemotePathFromUrl}": if (string.IsNullOrEmpty(currentRemote)) { argument = argument.Replace(option, ""); break; } url = module.GetSetting(string.Format(SettingKeyString.RemoteUrl, currentRemote)); argument = argument.Replace(option, GetRemotePath(url)); break; case "{UserInput}": using (var prompt = new SimplePrompt()) { prompt.ShowDialog(); argument = argument.Replace(option, prompt.UserInput); } break; case "{UserFiles}": using (FormFilePrompt prompt = new FormFilePrompt()) { if (prompt.ShowDialog(owner) != DialogResult.OK) { return(false); } argument = argument.Replace(option, prompt.FileInput); break; } case "{WorkingDir}": argument = argument.Replace(option, module.WorkingDir); break; } } command = ExpandCommandVariables(command, module); if (scriptInfo.IsPowerShell) { PowerShellHelper.RunPowerShell(command, argument, module.WorkingDir, scriptInfo.RunInBackground); return(false); } if (command.StartsWith(PluginPrefix)) { command = command.Replace(PluginPrefix, ""); foreach (var plugin in PluginRegistry.Plugins) { if (plugin.Description.ToLower().Equals(command, StringComparison.CurrentCultureIgnoreCase)) { var eventArgs = new GitUIEventArgs(owner, revisionGrid.UICommands); return(plugin.Execute(eventArgs)); } } return(false); } if (!scriptInfo.RunInBackground) { FormProcess.ShowStandardProcessDialog(owner, command, argument, module.WorkingDir, null, true); } else { if (originalCommand.Equals("{openurl}", StringComparison.CurrentCultureIgnoreCase)) { Process.Start(argument); } else { new Executable(command, module.WorkingDir).Start(argument); } } return(!scriptInfo.RunInBackground); }
private static void RefreshRevisions(RevisionGridControl revisionGridControl) { revisionGridControl.ForceRefreshRevisions(); ProcessUntil(() => revisionGridControl.GetTestAccessor().IsRefreshingRevisions.ToString(), false.ToString()); }
public void Bind(RevisionGridControl revisionGrid, RevisionFileTreeControl revisionFileTree) { _revisionGrid = revisionGrid; _revisionFileTree = revisionFileTree; }
private static CommandStatus RunScript(IWin32Window owner, GitModule module, ScriptInfo scriptInfo, IGitUICommands uiCommands, RevisionGridControl revisionGrid) { if (scriptInfo.AskConfirmation && MessageBox.Show(owner, $"Do you want to execute '{scriptInfo.Name}'?", "Script", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return(false); } string originalCommand = scriptInfo.Command; (string argument, bool abort) = ScriptOptionsParser.Parse(scriptInfo.Arguments, module, owner, revisionGrid); if (abort) { return(false); } string command = OverrideCommandWhenNecessary(originalCommand); command = ExpandCommandVariables(command, module); if (scriptInfo.IsPowerShell) { PowerShellHelper.RunPowerShell(command, argument, module.WorkingDir, scriptInfo.RunInBackground); return(new CommandStatus(true, false)); } if (command.StartsWith(PluginPrefix)) { command = command.Replace(PluginPrefix, ""); foreach (var plugin in PluginRegistry.Plugins) { if (plugin.Description.ToLower().Equals(command, StringComparison.CurrentCultureIgnoreCase)) { var eventArgs = new GitUIEventArgs(owner, uiCommands); return(new CommandStatus(true, plugin.Execute(eventArgs))); } } return(false); } if (command.StartsWith(NavigateToPrefix)) { if (revisionGrid == null) { return(false); } command = command.Replace(NavigateToPrefix, string.Empty); if (!command.IsNullOrEmpty()) { var revisionRef = new Executable(command, module.WorkingDir).GetOutputLines(argument).FirstOrDefault(); if (revisionRef != null) { revisionGrid.GoToRef(revisionRef, true); } } return(new CommandStatus(true, false)); } if (!scriptInfo.RunInBackground) { FormProcess.ShowStandardProcessDialog(owner, command, argument, module.WorkingDir, null, true); } else { if (originalCommand.Equals("{openurl}", StringComparison.CurrentCultureIgnoreCase)) { Process.Start(argument); } else { new Executable(command, module.WorkingDir).Start(argument); } } return(new CommandStatus(true, !scriptInfo.RunInBackground)); }
public static CommandStatus RunScript(IWin32Window owner, GitModule module, string scriptKey, IGitUICommands uiCommands, RevisionGridControl revisionGrid) { if (string.IsNullOrEmpty(scriptKey)) { return(false); } var script = ScriptManager.GetScript(scriptKey); if (script == null) { MessageBox.Show(owner, "Cannot find script: " + scriptKey, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (string.IsNullOrEmpty(script.Command)) { return(false); } string argument = script.Arguments; foreach (string option in ScriptOptionsParser.Options) { if (string.IsNullOrEmpty(argument) || !argument.Contains(option)) { continue; } if (!option.StartsWith("s")) { continue; } if (revisionGrid != null) { continue; } MessageBox.Show(owner, $"Option {option} is only supported when started from revision grid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } return(RunScript(owner, module, script, uiCommands, revisionGrid)); }
/// <summary>Tries to run scripts identified by a <paramref name="command"/></summary> public static CommandStatus ExecuteScriptCommand(IWin32Window owner, GitModule module, int command, IGitUICommands uiCommands, RevisionGridControl revisionGrid = null) { var anyScriptExecuted = false; var needsGridRefresh = false; foreach (var script in ScriptManager.GetScripts()) { if (script.HotkeyCommandIdentifier == command) { var result = RunScript(owner, module, script.Name, uiCommands, revisionGrid); anyScriptExecuted = true; needsGridRefresh |= result.NeedsGridRefresh; } } return(new CommandStatus(anyScriptExecuted, needsGridRefresh)); }
public static (string arguments, bool abort) Parse(string arguments, IGitModule module, IWin32Window owner, RevisionGridControl revisionGrid) { 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 (string.IsNullOrEmpty(arguments)) { continue; } if (!Contains(arguments, option)) { continue; } if (currentRevision == null && option.StartsWith("c")) { currentRevision = GetCurrentRevision(module, revisionGrid, 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, revisionGrid))); } } } else if (selectedRevision == null && revisionGrid != null && DependsOnSelectedRevision(option)) { allSelectedRevisions = revisionGrid.GetSelectedRevisions(); selectedRevision = CalculateSelectedRevision(revisionGrid, selectedRemoteBranches, selectedRemotes, selectedLocalBranches, selectedBranches, selectedTags); if (selectedRevision == null) { return(arguments : null, abort : true); } } arguments = ParseScriptArguments(arguments, option, owner, revisionGrid, 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(string arguments, string option, IWin32Window owner, RevisionGridControl revisionGrid, IGitModule module, IReadOnlyList <GitRevision> allSelectedRevisions, in IList <IGitRef> selectedTags, in IList <IGitRef> selectedBranches, in IList <IGitRef> selectedLocalBranches, in IList <IGitRef> selectedRemoteBranches, in IList <string> selectedRemotes, GitRevision selectedRevision, in IList <IGitRef> currentTags, in IList <IGitRef> currentBranches, in IList <IGitRef> currentLocalBranches, in IList <IGitRef> currentRemoteBranches, GitRevision currentRevision, string currentRemote)
public static CommandStatus RunScript(IWin32Window owner, IGitModule module, string scriptKey, IGitUICommands uiCommands, RevisionGridControl revisionGrid) { try { return(RunScriptInternal(owner, module, scriptKey, uiCommands, revisionGrid)); } catch (ExternalOperationException ex) when(!(ex is UserExternalOperationException)) { ThreadHelper.AssertOnUIThread(); throw new UserExternalOperationException($"{Strings.ScriptErrorFailedToExecute}: '{scriptKey}'", ex); } }
private static CommandStatus RunScriptInternal(IWin32Window owner, IGitModule module, string scriptKey, IGitUICommands uiCommands, RevisionGridControl revisionGrid) { if (string.IsNullOrEmpty(scriptKey)) { return(false); } ScriptInfo scriptInfo = ScriptManager.GetScript(scriptKey); if (scriptInfo is null) { ThreadHelper.AssertOnUIThread(); throw new UserExternalOperationException($"{Strings.ScriptErrorCantFind}: '{scriptKey}'", new ExternalOperationException(command: null, arguments: null, module.WorkingDir, innerException: null)); } if (string.IsNullOrEmpty(scriptInfo.Command)) { return(false); } string arguments = scriptInfo.Arguments; if (!string.IsNullOrEmpty(arguments) && revisionGrid is null) { string optionDependingOnSelectedRevision = ScriptOptionsParser.Options.FirstOrDefault(option => ScriptOptionsParser.DependsOnSelectedRevision(option) && ScriptOptionsParser.Contains(arguments, option)); if (optionDependingOnSelectedRevision is object) { ThreadHelper.AssertOnUIThread(); throw new UserExternalOperationException($"{Strings.ScriptText}: '{scriptKey}'{Environment.NewLine}'{optionDependingOnSelectedRevision}' {Strings.ScriptErrorOptionWithoutRevisionGridText}", new ExternalOperationException(scriptInfo.Command, arguments, module.WorkingDir, innerException: null)); } } if (scriptInfo.AskConfirmation && MessageBox.Show(owner, $"{Strings.ScriptConfirmExecute}: '{scriptInfo.Name}'?", Strings.ScriptText, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return(false); } string originalCommand = scriptInfo.Command; (string argument, bool abort) = ScriptOptionsParser.Parse(scriptInfo.Arguments, module, owner, revisionGrid); if (abort) { ThreadHelper.AssertOnUIThread(); throw new UserExternalOperationException($"{Strings.ScriptText}: '{scriptKey}'{Environment.NewLine}{Strings.ScriptErrorOptionWithoutRevisionText}", new ExternalOperationException(scriptInfo.Command, arguments, module.WorkingDir, innerException: null)); } string command = OverrideCommandWhenNecessary(originalCommand); command = ExpandCommandVariables(command, module); if (scriptInfo.IsPowerShell) { PowerShellHelper.RunPowerShell(command, argument, module.WorkingDir, scriptInfo.RunInBackground); // 'RunPowerShell' always runs the script detached (yet). // Hence currently, it does not make sense to set 'needsGridRefresh' to '!scriptInfo.RunInBackground'. return(new CommandStatus(executed: true, needsGridRefresh: false)); } if (command.StartsWith(PluginPrefix)) { command = command.Replace(PluginPrefix, string.Empty); lock (PluginRegistry.Plugins) { foreach (var plugin in PluginRegistry.Plugins) { if (plugin.Description.ToLower().Equals(command, StringComparison.CurrentCultureIgnoreCase)) { var eventArgs = new GitUIEventArgs(owner, uiCommands); return(new CommandStatus(executed: true, needsGridRefresh: plugin.Execute(eventArgs))); } } } return(false); } if (command.StartsWith(NavigateToPrefix)) { if (revisionGrid is null) { return(false); } command = command.Replace(NavigateToPrefix, string.Empty); if (!string.IsNullOrEmpty(command)) { var revisionRef = new Executable(command, module.WorkingDir).GetOutputLines(argument).FirstOrDefault(); if (revisionRef != null) { revisionGrid.GoToRef(revisionRef, true); } } return(new CommandStatus(executed: true, needsGridRefresh: false)); } if (!scriptInfo.RunInBackground) { FormProcess.ShowDialog(owner, command, argument, module.WorkingDir, null, true); } else { if (originalCommand.Equals("{openurl}", StringComparison.CurrentCultureIgnoreCase)) { Process.Start(argument); } else { // It is totally valid to have a command without an argument, e.g.: // Command : myscript.cmd // Arguments: <blank> new Executable(command, module.WorkingDir).Start(argument ?? string.Empty); } } return(new CommandStatus(executed: true, needsGridRefresh: !scriptInfo.RunInBackground)); }
public static CommandStatus RunScript(IWin32Window owner, IGitModule module, string scriptKey, IGitUICommands uiCommands, RevisionGridControl revisionGrid) { return(RunScript(owner, module, scriptKey, uiCommands, revisionGrid, msg => MessageBox.Show(owner, msg, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error))); }
private static CommandStatus RunScript(IWin32Window owner, IGitModule module, ScriptInfo scriptInfo, IGitUICommands uiCommands, RevisionGridControl revisionGrid, Action <string> showError) { if (scriptInfo.AskConfirmation && MessageBox.Show(owner, $"Do you want to execute '{scriptInfo.Name}'?", "Script", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return(false); } string originalCommand = scriptInfo.Command; (string argument, bool abort) = ScriptOptionsParser.Parse(scriptInfo.Arguments, module, owner, revisionGrid); if (abort) { showError($"There must be a revision in order to substitute the argument option(s) for the script to run."); return(false); } string command = OverrideCommandWhenNecessary(originalCommand); command = ExpandCommandVariables(command, module); if (scriptInfo.IsPowerShell) { PowerShellHelper.RunPowerShell(command, argument, module.WorkingDir, scriptInfo.RunInBackground); // 'RunPowerShell' always runs the script detached (yet). // Hence currently, it does not make sense to set 'needsGridRefresh' to '!scriptInfo.RunInBackground'. return(new CommandStatus(executed: true, needsGridRefresh: false)); } if (command.StartsWith(PluginPrefix)) { command = command.Replace(PluginPrefix, ""); lock (PluginRegistry.Plugins) { foreach (var plugin in PluginRegistry.Plugins) { if (plugin.Description.ToLower().Equals(command, StringComparison.CurrentCultureIgnoreCase)) { var eventArgs = new GitUIEventArgs(owner, uiCommands); return(new CommandStatus(executed: true, needsGridRefresh: plugin.Execute(eventArgs))); } } } return(false); } if (command.StartsWith(NavigateToPrefix)) { if (revisionGrid == null) { return(false); } command = command.Replace(NavigateToPrefix, string.Empty); if (!command.IsNullOrEmpty()) { var revisionRef = new Executable(command, module.WorkingDir).GetOutputLines(argument).FirstOrDefault(); if (revisionRef != null) { revisionGrid.GoToRef(revisionRef, true); } } return(new CommandStatus(executed: true, needsGridRefresh: false)); } if (!scriptInfo.RunInBackground) { FormProcess.ShowStandardProcessDialog(owner, command, argument, module.WorkingDir, null, true); } else { if (originalCommand.Equals("{openurl}", StringComparison.CurrentCultureIgnoreCase)) { Process.Start(argument); } else { new Executable(command, module.WorkingDir).Start(argument); } } return(new CommandStatus(executed: true, needsGridRefresh: !scriptInfo.RunInBackground)); }
/// <summary>Tries to run scripts identified by a <paramref name="command"/> /// and returns true if any executed.</summary> public static bool ExecuteScriptCommand(IWin32Window owner, GitModule module, int command, RevisionGridControl revisionGrid = null) { var anyScriptExecuted = false; foreach (var script in ScriptManager.GetScripts()) { if (script.HotkeyCommandIdentifier == command) { RunScript(owner, module, script.Name, revisionGrid); anyScriptExecuted = true; } } return(anyScriptExecuted); }