PageRenderTime 58ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/GitUI/FormCommitTemplateSettings.cs

https://github.com/eisnerd/gitextensions
C# | 122 lines | 97 code | 25 blank | 0 comment | 7 complexity | 7ddc7a634dbdb4c27227e16241de8195 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.Data;
  5. using System.Drawing;
  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 FormCommitTemplateSettings : GitExtensionsForm
  14. {
  15. private readonly TranslationString _emptyTemplate =
  16. new TranslationString("empty");
  17. private CommitTemplateItem[] _commitTemplates;
  18. private const int _maxCommitTemplates = 5;
  19. private const int _maxShownCharsForName = 15;
  20. private const int _maxUsedCharsForName = 80;
  21. public FormCommitTemplateSettings()
  22. {
  23. InitializeComponent();
  24. Translate();
  25. _NO_TRANSLATE_textBoxCommitTemplateName.MaxLength = _maxUsedCharsForName;
  26. LoadSettings();
  27. }
  28. private void LoadSettings()
  29. {
  30. _NO_TRANSLATE_numericMaxFirstLineLength.Value = Settings.CommitValidationMaxCntCharsFirstLine;
  31. _NO_TRANSLATE_numericMaxLineLength.Value = Settings.CommitValidationMaxCntCharsPerLine;
  32. checkBoxSecondLineEmpty.Checked = Settings.CommitValidationSecondLineMustBeEmpty;
  33. _NO_TRANSLATE_textBoxCommitValidationRegex.Text = Settings.CommitValidationRegEx;
  34. _commitTemplates = CommitTemplateItem.DeserializeCommitTemplates(Settings.CommitTemplates);
  35. if (null == _commitTemplates)
  36. {
  37. _commitTemplates = new CommitTemplateItem[_maxCommitTemplates];
  38. for (int i = 0; i < _commitTemplates.Length; i++)
  39. _commitTemplates[i] = new CommitTemplateItem();
  40. }
  41. _NO_TRANSLATE_comboBoxCommitTemplates.Items.Clear();
  42. for (int i = 0; i < _commitTemplates.Length; i++)
  43. {
  44. _NO_TRANSLATE_comboBoxCommitTemplates.Items.Add(String.Empty);
  45. RefreshLineInListBox(i);
  46. }
  47. _NO_TRANSLATE_comboBoxCommitTemplates.SelectedIndex = 0;
  48. }
  49. private void SaveSettings()
  50. {
  51. Settings.CommitValidationMaxCntCharsFirstLine = Convert.ToInt32(_NO_TRANSLATE_numericMaxFirstLineLength.Value);
  52. Settings.CommitValidationMaxCntCharsPerLine = Convert.ToInt32(_NO_TRANSLATE_numericMaxLineLength.Value);
  53. Settings.CommitValidationSecondLineMustBeEmpty = checkBoxSecondLineEmpty.Checked;
  54. Settings.CommitValidationRegEx = _NO_TRANSLATE_textBoxCommitValidationRegex.Text;
  55. string serializedCommitTemplates = CommitTemplateItem.SerializeCommitTemplates(_commitTemplates);
  56. if (null == serializedCommitTemplates)
  57. Settings.CommitTemplates = "";
  58. else
  59. Settings.CommitTemplates = serializedCommitTemplates;
  60. }
  61. private void buttonOk_Click(object sender, EventArgs e)
  62. {
  63. SaveSettings();
  64. Close();
  65. }
  66. private void buttonCancel_Click(object sender, EventArgs e)
  67. {
  68. Close();
  69. }
  70. private void textCommitTemplateText_TextChanged(object sender, EventArgs e)
  71. {
  72. _commitTemplates[_NO_TRANSLATE_comboBoxCommitTemplates.SelectedIndex].Text = _NO_TRANSLATE_textCommitTemplateText.Text;
  73. }
  74. private void textBoxCommitTemplateName_TextChanged(object sender, EventArgs e)
  75. {
  76. _commitTemplates[_NO_TRANSLATE_comboBoxCommitTemplates.SelectedIndex].Name = _NO_TRANSLATE_textBoxCommitTemplateName.Text;
  77. RefreshLineInListBox(_NO_TRANSLATE_comboBoxCommitTemplates.SelectedIndex);
  78. }
  79. private void comboBoxCommitTemplates_SelectedIndexChanged(object sender, EventArgs e)
  80. {
  81. _NO_TRANSLATE_textCommitTemplateText.Text = _commitTemplates[_NO_TRANSLATE_comboBoxCommitTemplates.SelectedIndex].Text;
  82. _NO_TRANSLATE_textBoxCommitTemplateName.Text = _commitTemplates[_NO_TRANSLATE_comboBoxCommitTemplates.SelectedIndex].Name;
  83. }
  84. private void RefreshLineInListBox(int line)
  85. {
  86. string comboBoxText;
  87. if (!_commitTemplates[line].Name.IsNullOrEmpty())
  88. {
  89. comboBoxText = _commitTemplates[line].Name.Substring(0, _commitTemplates[line].Name.Length > _maxShownCharsForName ? (_maxShownCharsForName - 3) : _commitTemplates[line].Name.Length);
  90. comboBoxText += _commitTemplates[line].Name.Length > _maxShownCharsForName ? "..." : "";
  91. }
  92. else
  93. comboBoxText = "<" + _emptyTemplate.Text + ">";
  94. _NO_TRANSLATE_comboBoxCommitTemplates.Items[line] = String.Format("{0} : {1}", (line + 1), comboBoxText);
  95. }
  96. }
  97. }