public IEnumerable <RepositoryAction> GetContextMenuActions(IEnumerable <Repository> repositories) { var singleRepository = repositories.Count() == 1 ? repositories.Single() : null; if (singleRepository != null) { yield return(GetPrimaryAction(singleRepository)); yield return(GetSecondaryAction(singleRepository)); // if Windows Terminal is installed, provider PowerShell as additional option here (otherwise PowerShell is the secondary action) if (HasWindowsTerminal()) { yield return(CreateProcessRunnerAction(_translationService.Translate("Open in Windows PowerShell"), "powershell.exe ", $"-executionpolicy bypass -noexit -command \"Set-Location '{singleRepository.SafePath}'\"")); } yield return(CreateProcessRunnerAction(_translationService.Translate("Open in Windows Command Prompt"), "cmd.exe", $"/K \"cd /d {singleRepository.SafePath}\"")); var bashExecutable = TryFindBash(); var hasBash = !string.IsNullOrEmpty(bashExecutable); if (hasBash) { string path = singleRepository.SafePath; if (path.EndsWith("\\", StringComparison.OrdinalIgnoreCase)) { path = path.Substring(0, path.Length - 1); } yield return(CreateProcessRunnerAction(_translationService.Translate("Open in Git Bash"), bashExecutable, $"\"--cd={path}\"")); } var codeExecutable = TryFindCode(); var hasCode = !string.IsNullOrEmpty(codeExecutable); if (hasCode) { yield return(CreateProcessRunnerAction(_translationService.Translate("Open in Visual Studio Code"), codeExecutable, singleRepository.SafePath)); } } yield return(CreateActionForMultipleRepositories(_translationService.Translate("Fetch"), repositories, _repositoryWriter.Fetch, beginGroup: true, executionCausesSynchronizing: true)); yield return(CreateActionForMultipleRepositories(_translationService.Translate("Pull"), repositories, _repositoryWriter.Pull, executionCausesSynchronizing: true)); yield return(CreateActionForMultipleRepositories(_translationService.Translate("Push"), repositories, _repositoryWriter.Push, executionCausesSynchronizing: true)); if (singleRepository != null) { yield return(new RepositoryAction() { Name = _translationService.Translate("Checkout"), SubActions = singleRepository.LocalBranches.Select(branch => new RepositoryAction() { Name = branch, Action = (s, e) => _repositoryWriter.Checkout(singleRepository, branch), CanExecute = !singleRepository.CurrentBranch.Equals(branch, StringComparison.OrdinalIgnoreCase) }).ToArray() }); } yield return(CreateActionForMultipleRepositories(_translationService.Translate("Ignore"), repositories, r => _repositoryMonitor.IgnoreByPath(r.Path), beginGroup: true)); }
private IEnumerable <RepositoryAction> GetContextMenuActionsInternal(IEnumerable <Repository> repositories) { var singleRepository = repositories.Count() == 1 ? repositories.Single() : null; if (singleRepository != null) { yield return(GetPrimaryAction(singleRepository)); yield return(GetSecondaryAction(singleRepository)); var codeExecutable = TryFindCode(); var hasCode = !string.IsNullOrEmpty(codeExecutable); if (hasCode) { yield return(CreateProcessRunnerAction(_translationService.Translate("Open in Visual Studio Code"), codeExecutable, '"' + singleRepository.SafePath + '"')); } yield return(CreateFileActionSubMenu(singleRepository, _translationService.Translate("Open Visual Studio solutions"), "*.sln")); var sourceTreeExecutable = TryFindSourceTree(); var hasSourceTree = !string.IsNullOrEmpty(sourceTreeExecutable); if (hasSourceTree) { yield return(CreateProcessRunnerAction(_translationService.Translate("Open in Sourcetree"), sourceTreeExecutable, "-f " + '"' + singleRepository.SafePath + '"')); } yield return(CreateBrowseRemoteAction(singleRepository)); } yield return(CreateActionForMultipleRepositories(_translationService.Translate("Fetch"), repositories, _repositoryWriter.Fetch, beginGroup: true, executionCausesSynchronizing: true)); yield return(CreateActionForMultipleRepositories(_translationService.Translate("Pull"), repositories, _repositoryWriter.Pull, executionCausesSynchronizing: true)); yield return(CreateActionForMultipleRepositories(_translationService.Translate("Push"), repositories, _repositoryWriter.Push, executionCausesSynchronizing: true)); if (singleRepository != null) { // Strip label of "(r)" and "(l)" indicators yield return(new RepositoryAction() { Name = _translationService.Translate("Checkout"), DeferredSubActionsEnumerator = () => singleRepository.AllBranches .Take(50) .Select(branch => new RepositoryAction() { Name = branch, Action = (_, __) => _repositoryWriter.Checkout(singleRepository, branch.Replace(" (r)", "").Replace(" (l)", "")), CanExecute = !singleRepository.CurrentBranch.Equals(branch, StringComparison.OrdinalIgnoreCase) }) .ToArray() }); } yield return(CreateActionForMultipleRepositories(_translationService.Translate("Ignore"), repositories, r => _repositoryMonitor.IgnoreByPath(r.Path), beginGroup: true)); }
public IEnumerable <RepositoryAction> GetContextMenuActions(IEnumerable <Repository> repositories) { var singleRepository = repositories.Count() == 1 ? repositories.Single() : null; if (singleRepository != null) { yield return(GetPrimaryAction(singleRepository)); yield return(GetSecondaryAction(singleRepository)); yield return(CreateProcessRunnerAction(_translationService.Translate("Open in Windows Command Prompt"), "cmd.exe", $"/K \"cd /d {singleRepository.Path}\"")); string bashSubpath = @"Git\git-bash.exe"; string folder = Environment.ExpandEnvironmentVariables("%ProgramW6432%"); string gitbash = Path.Combine(folder, bashSubpath); if (!File.Exists(gitbash)) { folder = Environment.ExpandEnvironmentVariables("%ProgramFiles(x86)%"); gitbash = Path.Combine(folder, bashSubpath); } if (File.Exists(gitbash)) { string path = singleRepository.Path; if (path.EndsWith("\\", StringComparison.OrdinalIgnoreCase)) { path = path.Substring(0, path.Length - 1); } yield return(CreateProcessRunnerAction(_translationService.Translate("Open in Git Bash"), gitbash, $"\"--cd={path}\"")); } } yield return(CreateActionForMultipleRepositories(_translationService.Translate("Fetch"), repositories, _repositoryWriter.Fetch, beginGroup: true, executionCausesSynchronizing: true)); yield return(CreateActionForMultipleRepositories(_translationService.Translate("Pull"), repositories, _repositoryWriter.Pull, executionCausesSynchronizing: true)); yield return(CreateActionForMultipleRepositories(_translationService.Translate("Push"), repositories, _repositoryWriter.Push, executionCausesSynchronizing: true)); if (singleRepository != null) { yield return(new RepositoryAction() { Name = _translationService.Translate("Checkout"), SubActions = singleRepository.LocalBranches.Select(branch => new RepositoryAction() { Name = branch, Action = (s, e) => _repositoryWriter.Checkout(singleRepository, branch), CanExecute = !singleRepository.CurrentBranch.Equals(branch, StringComparison.OrdinalIgnoreCase) }).ToArray() }); } yield return(CreateActionForMultipleRepositories(_translationService.Translate("Ignore"), repositories, r => _repositoryMonitor.IgnoreByPath(r.Path), beginGroup: true)); }
private IEnumerable <RepositoryAction> GetContextMenuActionsInternal(IEnumerable <Repository> repositories) { var singleRepository = repositories.Count() == 1 ? repositories.Single() : null; if (_configuration.State == RepositoryActionConfiguration.LoadState.Error) { yield return(new RepositoryAction() { Name = _translationService.Translate("Could not read repository actions"), CanExecute = false }); yield return(new RepositoryAction() { Name = _configuration.LoadError, CanExecute = false }); var location = ((FileRepositoryStore)_repositoryActionConfigurationStore).GetFileName(); yield return(CreateProcessRunnerAction(_translationService.Translate("Fix"), Path.GetDirectoryName(location))); } if (singleRepository != null && _configuration.State == RepositoryActionConfiguration.LoadState.Ok) { foreach (var action in _configuration.RepositoryActions.Where(a => a.Active)) { yield return(CreateProcessRunnerAction(action, singleRepository, beginGroup: false)); } foreach (var fileAssociaction in _configuration.FileAssociations.Where(a => a.Active)) { yield return(CreateFileAssociationSubMenu( singleRepository, ReplaceTranslatables(fileAssociaction.Name), fileAssociaction.Extension)); } yield return(CreateBrowseRemoteAction(singleRepository)); } yield return(CreateActionForMultipleRepositories(_translationService.Translate("Fetch"), repositories, _repositoryWriter.Fetch, beginGroup: true, executionCausesSynchronizing: true)); yield return(CreateActionForMultipleRepositories(_translationService.Translate("Pull"), repositories, _repositoryWriter.Pull, executionCausesSynchronizing: true)); yield return(CreateActionForMultipleRepositories(_translationService.Translate("Push"), repositories, _repositoryWriter.Push, executionCausesSynchronizing: true)); if (singleRepository != null) { yield return(new RepositoryAction() { Name = _translationService.Translate("Checkout"), DeferredSubActionsEnumerator = () => singleRepository.LocalBranches .Take(50) .Select(branch => new RepositoryAction() { Name = branch, Action = (_, __) => _repositoryWriter.Checkout(singleRepository, branch), CanExecute = !singleRepository.CurrentBranch.Equals(branch, StringComparison.OrdinalIgnoreCase) }) .Union(new[] { new RepositoryAction() { BeginGroup = true, Name = _translationService.Translate("Remote branches"), DeferredSubActionsEnumerator = () => { var remoteBranches = singleRepository.ReadAllBranches().Select(branch => new RepositoryAction() { Name = branch, Action = (_, __) => _repositoryWriter.Checkout(singleRepository, branch), CanExecute = !singleRepository.CurrentBranch.Equals(branch, StringComparison.OrdinalIgnoreCase) }).ToArray(); if (remoteBranches.Any()) { return remoteBranches; } return new RepositoryAction[] { new RepositoryAction() { Name = _translationService.Translate("No remote branches found"), CanExecute = false }, new RepositoryAction() { Name = _translationService.Translate("Try to fetch changes if you're expecting remote branches"), CanExecute = false } }; } } }) .ToArray() }); } yield return(CreateActionForMultipleRepositories(_translationService.Translate("Ignore"), repositories, r => _repositoryMonitor.IgnoreByPath(r.Path), beginGroup: true)); }
public IEnumerable <RepositoryAction> GetContextMenuActions(IEnumerable <Repository> repositories) { var singleRepository = repositories.Count() == 1 ? repositories.Single() : null; if (singleRepository != null) { yield return(GetPrimaryAction(singleRepository)); yield return(GetSecondaryAction(singleRepository)); yield return(CreateProcessRunnerAction("Open in Windows Command Prompt (cmd.exe)", "cmd.exe", $"/K \"cd /d {singleRepository.Path}\"")); string bashSubpath = @"Git\git-bash.exe"; string folder = Environment.ExpandEnvironmentVariables("%ProgramW6432%"); string gitbash = Path.Combine(folder, bashSubpath); if (!File.Exists(gitbash)) { folder = Environment.ExpandEnvironmentVariables("%ProgramFiles(x86)%"); gitbash = Path.Combine(folder, bashSubpath); } if (File.Exists(gitbash)) { string path = singleRepository.Path; if (path.EndsWith("\\", StringComparison.OrdinalIgnoreCase)) { path = path.Substring(0, path.Length - 1); } yield return(CreateProcessRunnerAction("Open in Git Bash", gitbash, $"\"--cd={path}\"")); } } yield return(CreateActionForMultipleRepositories("Fetch", repositories, _repositoryWriter.Fetch, beginGroup: true, executionCausesSynchronizing: true)); yield return(CreateActionForMultipleRepositories("Pull", repositories, _repositoryWriter.Pull, executionCausesSynchronizing: true)); yield return(CreateActionForMultipleRepositories("Push", repositories, _repositoryWriter.Push, executionCausesSynchronizing: true)); if (singleRepository != null) { yield return(new RepositoryAction() { Name = "Checkout", SubActions = singleRepository.LocalBranches.Select(branch => new RepositoryAction() { Name = branch, Action = (s, e) => _repositoryWriter.Checkout(singleRepository, branch), CanExecute = !singleRepository.CurrentBranch.Equals(branch, StringComparison.OrdinalIgnoreCase) }).ToArray() }); yield return(new RepositoryAction() { Name = "Shell", Action = (sender, args) => { var coords = args as float[]; var i = new ShellItem(singleRepository.Path); var m = new ShellContextMenu(i); m.ShowContextMenu(new System.Windows.Forms.Button(), new Point((int)coords[0], (int)coords[1])); }, BeginGroup = true }); } }
private IEnumerable <RepositoryAction> GetContextMenuActionsInternal(IEnumerable <Repository> repositories) { var singleRepository = repositories.Count() == 1 ? repositories.Single() : null; if (singleRepository != null) { yield return(GetPrimaryAction(singleRepository)); yield return(GetSecondaryAction(singleRepository)); var codeExecutable = TryFindCode(); var hasCode = !string.IsNullOrEmpty(codeExecutable); if (hasCode) { yield return(CreateProcessRunnerAction(_translationService.Translate("Open in Visual Studio Code"), codeExecutable, singleRepository.SafePath)); } yield return(CreateFileActionSubMenu(singleRepository, _translationService.Translate("Open Visual Studio solutions"), "*.sln")); yield return(CreateBrowseRemoteAction(singleRepository)); } yield return(CreateActionForMultipleRepositories(_translationService.Translate("Fetch"), repositories, _repositoryWriter.Fetch, beginGroup: true, executionCausesSynchronizing: true)); yield return(CreateActionForMultipleRepositories(_translationService.Translate("Pull"), repositories, _repositoryWriter.Pull, executionCausesSynchronizing: true)); yield return(CreateActionForMultipleRepositories(_translationService.Translate("Push"), repositories, _repositoryWriter.Push, executionCausesSynchronizing: true)); if (singleRepository != null) { yield return(new RepositoryAction() { Name = _translationService.Translate("Checkout"), DeferredSubActionsEnumerator = () => singleRepository.LocalBranches .Take(50) .Select(branch => new RepositoryAction() { Name = branch, Action = (_, __) => _repositoryWriter.Checkout(singleRepository, branch), CanExecute = !singleRepository.CurrentBranch.Equals(branch, StringComparison.OrdinalIgnoreCase) }) .Union(new[] { new RepositoryAction() { BeginGroup = true, Name = _translationService.Translate("Remote branches"), DeferredSubActionsEnumerator = () => { var remoteBranches = singleRepository.ReadAllBranches().Select(branch => new RepositoryAction() { Name = branch, Action = (_, __) => _repositoryWriter.Checkout(singleRepository, branch), CanExecute = !singleRepository.CurrentBranch.Equals(branch, StringComparison.OrdinalIgnoreCase) }).ToArray(); if (remoteBranches.Any()) { return remoteBranches; } return new RepositoryAction[] { new RepositoryAction() { Name = "No remote branches found", CanExecute = false }, new RepositoryAction() { Name = "Try fetching if you expect one", CanExecute = false } }; } } }) .ToArray() }); } yield return(CreateActionForMultipleRepositories(_translationService.Translate("Ignore"), repositories, r => _repositoryMonitor.IgnoreByPath(r.Path), beginGroup: true, executionCausesSynchronizing: true)); }