HandlerSettingsBox.xaml.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. public HandlerSettingsBox(Handler handler, IEnumerable<string> options)
  27. {
  28. InitializeComponent();
  29. this.handler = handler;
  30. HandlerRadioButton.Content = handler.Setting.usage;
  31. foreach (Setting setting in handler.Settings)
  32. switch (setting.type)
  33. {
  34. case SettingType.OptionalExecutable:
  35. SettingsPanel.Children.Add(new OptionalExecutablePanel(setting, options));
  36. break;
  37. case SettingType.OptionalYesNoExecutable:
  38. SettingsPanel.Children.Add(new OptionalYesNoExecutablePanel(setting, options));
  39. break;
  40. case SettingType.OptionalYesNoDirectory:
  41. SettingsPanel.Children.Add(new OptionalYesNoDirectoryPanel(setting, options));
  42. break;
  43. }
  44. Regex regex = new Regex(@"^(?:/|--?)" + handler.Setting.option.Substring(1) + @"(?:[:=].*)?$");
  45. foreach (string option in options)
  46. if (regex.IsMatch(option))
  47. HandlerRadioButton.IsChecked = true;
  48. }
  49. public IEnumerable<string> Options
  50. {
  51. get
  52. {
  53. var options = new List<string>();
  54. foreach (SettingPanel panel in SettingsPanel.Children)
  55. if (panel.IsSelected)
  56. options.Add(panel.Option);
  57. return options;
  58. }
  59. }
  60. private void HandlerRadioButton_Checked(object sender, System.Windows.RoutedEventArgs e)
  61. {
  62. SettingsPanel.IsEnabled = true;
  63. }
  64. private void HandlerRadioButton_Unchecked(object sender, System.Windows.RoutedEventArgs e)
  65. {
  66. SettingsPanel.IsEnabled = false;
  67. }
  68. }