Colors.xaml.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using System.Windows;
  2. using System.Windows.Controls;
  3. namespace MPE
  4. {
  5. public partial class Colors : Window
  6. {
  7. Properties.Settings param = Properties.Settings.Default;
  8. FunkDelegate func; public delegate void FunkDelegate(object sender, FastColoredTextBoxNS.TextChangedEventArgs e);
  9. public Colors(FunkDelegate func)
  10. {
  11. InitializeComponent(); this.func = func;
  12. if (param.selectedTheme) DarkTheme.IsChecked = true; else WhiteTheme.IsChecked = true;
  13. }
  14. void SetDefault_Click(object sender, RoutedEventArgs e)
  15. {
  16. if (param.selectedTheme)
  17. {//DarkTheme
  18. DataHelper.setDarkColors(); //if (param.darkTheme == null) param.darkTheme = new System.Collections.Specialized.StringCollection(); param.darkTheme.Clear(); param.darkTheme.Add(BackColorTB.Text = "#232629"); param.darkTheme.Add(ForeColorTB.Text = "#FFF"); param.darkTheme.Add(LineNumberColorTB.Text = "#FFF"); param.darkTheme.Add(IndentBackColorTB.Text = "#232629"); param.darkTheme.Add(SelectionColorTB.Text = "#00FFFF"); param.darkTheme.Add(bracketsTB.Text = "#D26922"); param.darkTheme.Add(commandTB.Text = "#20B2AA"); param.darkTheme.Add(varableTB.Text = "#FF2E2C"); param.darkTheme.Add(keywordsTB.Text = "#EEC900"); param.darkTheme.Add(commentTB.Text = "#00FF10"); param.darkTheme.Add(userVarableTB.Text = "#FF2E2C"); param.darkTheme.Add(codeMapBackgroundTB.Text = "#000"); param.darkTheme.Add(changedLineColorTB.Text = "#E89F0E"); param.darkTheme.Add(caretColorTB.Text = "#FFF"); param.darkTheme.Add(currLineColorTB.Text = "#FFF");
  19. }
  20. else
  21. {//LightTheme
  22. DataHelper.setLightsColors();//if (param.lightTheme == null) param.lightTheme = new System.Collections.Specialized.StringCollection(); param.lightTheme.Clear(); param.lightTheme.Add(BackColorTB.Text = "#FFF"); param.lightTheme.Add(ForeColorTB.Text = "#000"); param.lightTheme.Add(LineNumberColorTB.Text = "#000"); param.lightTheme.Add(IndentBackColorTB.Text = "#FFF"); param.lightTheme.Add(SelectionColorTB.Text = "#FF0000"); param.lightTheme.Add(bracketsTB.Text = "#D26922"); param.lightTheme.Add(commandTB.Text = "#20B2AA"); param.lightTheme.Add(varableTB.Text = "#FF2E2C"); param.lightTheme.Add(keywordsTB.Text = "#EEC900"); param.lightTheme.Add(commentTB.Text = "#545656"); param.lightTheme.Add(userVarableTB.Text = "#FF2E2C"); param.lightTheme.Add(codeMapBackgroundTB.Text = "#fff"); param.lightTheme.Add(changedLineColorTB.Text = "#E89F0E"); param.lightTheme.Add(caretColorTB.Text = "#FFF"); param.lightTheme.Add(currLineColorTB.Text = "#FFF");
  23. }
  24. DataHelper.SetColorsForAllTabs();
  25. func(null, null);
  26. }
  27. void TB_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
  28. {
  29. TextBox tb = (sender as TextBox);
  30. if (new System.Text.RegularExpressions.Regex("#").Matches(tb.Text).Count > 1 || tb.Text.IndexOf("#") > 0)
  31. { tb.Text = tb.Text.Replace("#", ""); tb.Text = tb.Text.Insert(0, "#"); }
  32. for (int i = 0; i < tb.Text.Length; i++)
  33. if (!System.Text.RegularExpressions.Regex.IsMatch(tb.Text[i] + "", @"[#0-9a-fA-F]")) tb.Text = tb.Text.Replace(tb.Text[i] + "", "");
  34. }
  35. void TB_LostFocus(object sender, RoutedEventArgs e) { TextBox tb = (sender as TextBox); if (tb.Text.Length < 4) tb.Text = "#000"; }
  36. void Exec_Click(object sender, RoutedEventArgs e)
  37. {
  38. if (DarkTheme.IsChecked == true)
  39. {
  40. if (param.darkTheme == null) param.darkTheme = new System.Collections.Specialized.StringCollection();
  41. param.darkTheme.Clear();
  42. param.darkTheme.Add(BackColorTB.Text);
  43. param.darkTheme.Add(ForeColorTB.Text);
  44. param.darkTheme.Add(LineNumberColorTB.Text);
  45. param.darkTheme.Add(IndentBackColorTB.Text);
  46. param.darkTheme.Add(SelectionColorTB.Text);
  47. param.darkTheme.Add(bracketsTB.Text);
  48. param.darkTheme.Add(commandTB.Text);
  49. param.darkTheme.Add(varableTB.Text);
  50. param.darkTheme.Add(keywordsTB.Text);
  51. param.darkTheme.Add(commentTB.Text);
  52. param.darkTheme.Add(userVarableTB.Text);
  53. param.darkTheme.Add(codeMapBackgroundTB.Text);
  54. param.darkTheme.Add(changedLineColorTB.Text);
  55. param.darkTheme.Add(caretColorTB.Text);
  56. param.darkTheme.Add(currLineColorTB.Text);
  57. }
  58. else
  59. {
  60. if (param.lightTheme == null) param.lightTheme = new System.Collections.Specialized.StringCollection();
  61. param.lightTheme.Clear();
  62. param.lightTheme.Add(BackColorTB.Text);
  63. param.lightTheme.Add(ForeColorTB.Text);
  64. param.lightTheme.Add(LineNumberColorTB.Text);
  65. param.lightTheme.Add(IndentBackColorTB.Text);
  66. param.lightTheme.Add(SelectionColorTB.Text);
  67. param.lightTheme.Add(bracketsTB.Text);
  68. param.lightTheme.Add(commandTB.Text);
  69. param.lightTheme.Add(varableTB.Text);
  70. param.lightTheme.Add(keywordsTB.Text);
  71. param.lightTheme.Add(commentTB.Text);
  72. param.lightTheme.Add(userVarableTB.Text);
  73. param.lightTheme.Add(codeMapBackgroundTB.Text);
  74. param.lightTheme.Add(changedLineColorTB.Text);
  75. param.lightTheme.Add(caretColorTB.Text);
  76. param.lightTheme.Add(currLineColorTB.Text);
  77. }
  78. param.Save();
  79. DataHelper.SetColorsForAllTabs();
  80. func(null, null);
  81. }
  82. void Window_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) => DragMove();
  83. void Theme_Checked(object sender, RoutedEventArgs e)
  84. {
  85. if ((sender as RadioButton).Content.ToString() == "Темная")// Нажали на тёмную тему
  86. param.selectedTheme = true;
  87. else// Нажали на светлую тему
  88. param.selectedTheme = false;
  89. param.Save();
  90. BackColorTB.Text = DataHelper.getThemeColor(0);
  91. ForeColorTB.Text = DataHelper.getThemeColor(1);
  92. LineNumberColorTB.Text = DataHelper.getThemeColor(2);
  93. IndentBackColorTB.Text = DataHelper.getThemeColor(3);
  94. SelectionColorTB.Text = DataHelper.getThemeColor(4);
  95. bracketsTB.Text = DataHelper.getThemeColor(5);
  96. commandTB.Text = DataHelper.getThemeColor(6);
  97. varableTB.Text = DataHelper.getThemeColor(7);
  98. keywordsTB.Text = DataHelper.getThemeColor(8);
  99. commentTB.Text = DataHelper.getThemeColor(9);
  100. userVarableTB.Text = DataHelper.getThemeColor(10);
  101. codeMapBackgroundTB.Text = DataHelper.getThemeColor(11);
  102. changedLineColorTB.Text = DataHelper.getThemeColor(12);
  103. caretColorTB.Text = DataHelper.getThemeColor(13);
  104. currLineColorTB.Text = DataHelper.getThemeColor(14);
  105. DataHelper.SetColorsForAllTabs();
  106. }
  107. }
  108. }