HandlerSettingsBox.xaml.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Handler Settings Box
  2. //
  3. // Douglas Thrift
  4. //
  5. // HandlerSettingsBox.xaml.cs
  6. /* Copyright 2014 Douglas Thrift
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. using System.Collections.Generic;
  21. using System.Text.RegularExpressions;
  22. using System.Windows.Controls;
  23. public partial class HandlerSettingsBox : GroupBox
  24. {
  25. private Handler handler;
  26. private Button applyButton;
  27. public HandlerSettingsBox(Handler handler, IEnumerable<string> options, Button applyButton)
  28. {
  29. InitializeComponent();
  30. this.applyButton = applyButton;
  31. this.handler = handler;
  32. HandlerRadioButton.Content = handler.Setting.usage;
  33. foreach (Setting setting in handler.Settings)
  34. switch (setting.type)
  35. {
  36. case SettingType.OptionalExecutable:
  37. SettingsPanel.Children.Add(new OptionalExecutablePanel(setting, options, applyButton));
  38. break;
  39. case SettingType.OptionalYesNoExecutable:
  40. SettingsPanel.Children.Add(new OptionalYesNoExecutablePanel(setting, options, applyButton));
  41. break;
  42. case SettingType.OptionalYesNoDirectory:
  43. SettingsPanel.Children.Add(new OptionalYesNoDirectoryPanel(setting, options, applyButton));
  44. break;
  45. }
  46. Regex regex = new Regex(@"^(?:/|--?)" + handler.Setting.option.Substring(1) + @"(?:[:=].*)?$");
  47. foreach (string option in options)
  48. if (regex.IsMatch(option))
  49. HandlerRadioButton.IsChecked = true;
  50. }
  51. public IEnumerable<string> Options
  52. {
  53. get
  54. {
  55. var options = new List<string>();
  56. foreach (SettingPanel panel in SettingsPanel.Children)
  57. if (panel.IsSelected)
  58. options.Add(panel.Option);
  59. return options;
  60. }
  61. }
  62. private void HandlerRadioButton_Checked(object sender, System.Windows.RoutedEventArgs e)
  63. {
  64. SettingsPanel.IsEnabled = true;
  65. }
  66. private void HandlerRadioButton_Unchecked(object sender, System.Windows.RoutedEventArgs e)
  67. {
  68. SettingsPanel.IsEnabled = false;
  69. applyButton.IsEnabled = true;
  70. }
  71. }