OptionsPanelGeneral.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.ComponentModel;
  3. using System.Text.RegularExpressions;
  4. using System.Windows;
  5. using static com.insanitydesign.MarkdownViewerPlusPlus.MarkdownViewerConfiguration;
  6. /// <summary>
  7. ///
  8. /// </summary>
  9. namespace com.insanitydesign.MarkdownViewerPlusPlus.Forms
  10. {
  11. /// <summary>
  12. ///
  13. /// </summary>
  14. public partial class OptionsPanelGeneral : AbstractOptionsPanel
  15. {
  16. /// <summary>
  17. ///
  18. /// </summary>
  19. protected string msgFileExtensions = "Add a list of comma-separated file extensions (e.g. \'log,txt,html\'). Empty the box for \'All files\'.";
  20. /// <summary>
  21. ///
  22. /// </summary>
  23. protected string regExFileExtensions = "^([a-zA-Z,]*)$";
  24. /// <summary>
  25. ///
  26. /// </summary>
  27. public OptionsPanelGeneral()
  28. {
  29. //
  30. this.txtFileExtensions.Enter += txtFileExtensions_Enter;
  31. this.txtFileExtensions.Leave += txtFileExtensions_Leave;
  32. this.txtFileExtensions.Validating += txtFileExtensions_Validating;
  33. }
  34. /// <summary>
  35. /// Validate that the file extensions field has a correct value
  36. /// </summary>
  37. /// <param name="sender"></param>
  38. /// <param name="e"></param>
  39. protected void txtFileExtensions_Validating(object sender, CancelEventArgs e)
  40. {
  41. if (!Regex.IsMatch(this.txtFileExtensions.Text, this.regExFileExtensions, RegexOptions.IgnoreCase))
  42. {
  43. MessageBox.Show(string.Format("Please check \'{0}\'\r\n" + this.msgFileExtensions, this.lblFileExtensions.Text), "Warning!", MessageBoxButton.OK, MessageBoxImage.Error);
  44. e.Cancel = true;
  45. }
  46. else
  47. {
  48. e.Cancel = false;
  49. }
  50. }
  51. /// <summary>
  52. ///
  53. /// </summary>
  54. /// <param name="sender"></param>
  55. /// <param name="e"></param>
  56. private void txtFileExtensions_Enter(object sender, EventArgs e)
  57. {
  58. this.toolTipFileExtensions.Show(this.msgFileExtensions, this.txtFileExtensions, this.lblFileExtensions.Width, -75);
  59. }
  60. /// <summary>
  61. ///
  62. /// </summary>
  63. /// <param name="sender"></param>
  64. /// <param name="e"></param>
  65. private void txtFileExtensions_Leave(object sender, EventArgs e)
  66. {
  67. this.toolTipFileExtensions.Hide(this.txtFileExtensions);
  68. }
  69. /// <summary>
  70. ///
  71. /// </summary>
  72. public override void SaveOptions(ref Options options)
  73. {
  74. options.inclNewFiles = this.chkBoxNewFiles.Checked;
  75. options.fileExtensions = this.txtFileExtensions.Text;
  76. }
  77. /// <summary>
  78. ///
  79. /// </summary>
  80. public override void LoadOptions(Options options)
  81. {
  82. this.chkBoxNewFiles.Checked = options.inclNewFiles;
  83. this.txtFileExtensions.Text = options.fileExtensions;
  84. }
  85. }
  86. }