You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.4 KiB

  1. // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
  2. // This code is distributed under MIT X11 license (for details please see \doc\license.txt)
  3. using System.ComponentModel;
  4. using System.Windows.Controls;
  5. using System.Xml.Linq;
  6. using ICSharpCode.ILSpy;
  7. using ICSharpCode.ILSpy.Options;
  8. namespace TestPlugin
  9. {
  10. [ExportOptionPage(Title = "TestPlugin", Order = 0)]
  11. partial class CustomOptionPage : UserControl, IOptionPage
  12. {
  13. static readonly XNamespace ns = "http://www.ilspy.net/testplugin";
  14. public CustomOptionPage()
  15. {
  16. InitializeComponent();
  17. }
  18. public void Load(ILSpySettings settings)
  19. {
  20. // For loading options, use ILSpySetting's indexer.
  21. // If the specified section does exist, the indexer will return a new empty element.
  22. XElement e = settings[ns + "CustomOptions"];
  23. // Now load the options from the XML document:
  24. Options s = new Options();
  25. s.UselessOption1 = (bool?)e.Attribute("useless1") ?? s.UselessOption1;
  26. s.UselessOption2 = (double?)e.Attribute("useless2") ?? s.UselessOption2;
  27. this.DataContext = s;
  28. }
  29. public void LoadDefaults()
  30. {
  31. this.DataContext = new Options();
  32. }
  33. public void Save(XElement root)
  34. {
  35. Options s = (Options)this.DataContext;
  36. // Save the options back into XML:
  37. XElement section = new XElement(ns + "CustomOptions");
  38. section.SetAttributeValue("useless1", s.UselessOption1);
  39. section.SetAttributeValue("useless2", s.UselessOption2);
  40. // Replace the existing section in the settings file, or add a new section,
  41. // if required.
  42. XElement existingElement = root.Element(ns + "CustomOptions");
  43. if (existingElement != null)
  44. existingElement.ReplaceWith(section);
  45. else
  46. root.Add(section);
  47. }
  48. }
  49. class Options : INotifyPropertyChanged
  50. {
  51. bool uselessOption1;
  52. public bool UselessOption1 {
  53. get { return uselessOption1; }
  54. set {
  55. if (uselessOption1 != value)
  56. {
  57. uselessOption1 = value;
  58. OnPropertyChanged("UselessOption1");
  59. }
  60. }
  61. }
  62. double uselessOption2;
  63. public double UselessOption2 {
  64. get { return uselessOption2; }
  65. set {
  66. if (uselessOption2 != value)
  67. {
  68. uselessOption2 = value;
  69. OnPropertyChanged("UselessOption2");
  70. }
  71. }
  72. }
  73. public event PropertyChangedEventHandler PropertyChanged;
  74. protected virtual void OnPropertyChanged(string propertyName)
  75. {
  76. if (PropertyChanged != null)
  77. {
  78. PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  79. }
  80. }
  81. }
  82. }