PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/GitUI/BranchComboBox.cs

https://github.com/eisnerd/gitextensions
C# | 91 lines | 80 code | 11 blank | 0 comment | 8 complexity | 7d20f7ddc80d05c783e28740abf6fb54 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using GitCommands;
  10. using ResourceManager.Translation;
  11. namespace GitUI
  12. {
  13. public partial class BranchComboBox : GitExtensionsControl
  14. {
  15. private readonly TranslationString _branchCheckoutError = new TranslationString("Branch '{0}' is not selectable, this branch has been removed from the selection.");
  16. public BranchComboBox()
  17. {
  18. InitializeComponent();
  19. Translate();
  20. branches.DisplayMember = "Name";
  21. }
  22. private IList<GitHead> _branchesToSelect;
  23. public IList<GitHead> BranchesToSelect
  24. {
  25. get
  26. {
  27. return _branchesToSelect;
  28. }
  29. set
  30. {
  31. _branchesToSelect = value;
  32. LoadBranches();
  33. }
  34. }
  35. private void LoadBranches()
  36. {
  37. if (_branchesToSelect != null)
  38. branches.Items.AddRange(_branchesToSelect.ToArray());
  39. }
  40. public IEnumerable<GitHead> GetSelectedBranches()
  41. {
  42. foreach (var branchName in branches.Text.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
  43. {
  44. foreach (string branch in branches.Text.Split(new char[]{',', ' '}, StringSplitOptions.RemoveEmptyEntries))
  45. {
  46. GitHead gitHead = _branchesToSelect.FirstOrDefault(g => g.Name == branch);
  47. if (gitHead == null)
  48. MessageBox.Show(string.Format(_branchCheckoutError.Text, branch));
  49. else
  50. yield return gitHead;
  51. }
  52. }
  53. }
  54. public string GetSelectedText()
  55. {
  56. return branches.Text;
  57. }
  58. public void SetSelectedText(string text)
  59. {
  60. if (text == null)
  61. throw new ArgumentNullException("text");
  62. branches.Text = text;
  63. }
  64. private void selectMultipleBranchesButton_Click(object sender, EventArgs e)
  65. {
  66. FormSelectMultipleBranches formSelectMultipleBranches = new FormSelectMultipleBranches(_branchesToSelect);
  67. foreach (GitHead branch in GetSelectedBranches())
  68. formSelectMultipleBranches.SelectBranch(branch.Name);
  69. formSelectMultipleBranches.ShowDialog(this);
  70. string branchesText = string.Empty;
  71. foreach (GitHead branch in formSelectMultipleBranches.GetSelectedBranches())
  72. {
  73. if (!string.IsNullOrEmpty(branchesText))
  74. branchesText += " ";
  75. branchesText += branch.Name;
  76. }
  77. branches.Text = branchesText;
  78. }
  79. }
  80. }