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.

154 lines
5.4 KiB

15 years ago
15 years ago
15 years ago
  1. // Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4. // software and associated documentation files (the "Software"), to deal in the Software
  5. // without restriction, including without limitation the rights to use, copy, modify, merge,
  6. // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7. // to whom the Software is furnished to do so, subject to the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be included in all copies or
  10. // substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  13. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  14. // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  15. // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  16. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. // DEALINGS IN THE SOFTWARE.
  18. using System.Collections.Generic;
  19. using System.Xml.Linq;
  20. using ICSharpCode.ILSpyX;
  21. using ICSharpCode.ILSpyX.Settings;
  22. using TomsToolbox.Wpf;
  23. #nullable enable
  24. namespace ICSharpCode.ILSpy
  25. {
  26. /// <summary>
  27. /// Represents the filters applied to the tree view.
  28. /// </summary>
  29. public class LanguageSettings : ObservableObject, IChildSettings
  30. {
  31. /// <summary>
  32. /// This dictionary is necessary to remember language versions across language changes. For example,
  33. /// the user first select C# 10, then switches to IL, then switches back to C#. After that we must be
  34. /// able to restore the original selection (i.e., C# 10).
  35. /// </summary>
  36. private readonly Dictionary<Language, LanguageVersion> languageVersionHistory = new Dictionary<Language, LanguageVersion>();
  37. public LanguageSettings(XElement element, ISettingsSection parent)
  38. {
  39. Parent = parent;
  40. this.ShowApiLevel = (ApiVisibility?)(int?)element.Element("ShowAPILevel") ?? ApiVisibility.PublicAndInternal;
  41. this.LanguageId = (string?)element.Element("Language");
  42. this.LanguageVersionId = (string?)element.Element("LanguageVersion");
  43. }
  44. public ISettingsSection Parent { get; }
  45. public XElement SaveAsXml()
  46. {
  47. return new XElement(
  48. "FilterSettings",
  49. new XElement("ShowAPILevel", (int)this.ShowApiLevel),
  50. new XElement("Language", this.LanguageId),
  51. new XElement("LanguageVersion", this.LanguageVersionId)
  52. );
  53. }
  54. ApiVisibility showApiLevel;
  55. /// <summary>
  56. /// Gets/Sets whether public, internal or all API members should be shown.
  57. /// </summary>
  58. public ApiVisibility ShowApiLevel {
  59. get { return showApiLevel; }
  60. set {
  61. if (showApiLevel != value)
  62. {
  63. showApiLevel = value;
  64. OnPropertyChanged(nameof(ShowApiLevel));
  65. }
  66. }
  67. }
  68. public bool ApiVisPublicOnly {
  69. get { return showApiLevel == ApiVisibility.PublicOnly; }
  70. set {
  71. if (value == (showApiLevel == ApiVisibility.PublicOnly))
  72. return;
  73. ShowApiLevel = ApiVisibility.PublicOnly;
  74. OnPropertyChanged(nameof(ApiVisPublicOnly));
  75. OnPropertyChanged(nameof(ApiVisPublicAndInternal));
  76. OnPropertyChanged(nameof(ApiVisAll));
  77. }
  78. }
  79. public bool ApiVisPublicAndInternal {
  80. get { return showApiLevel == ApiVisibility.PublicAndInternal; }
  81. set {
  82. if (value == (showApiLevel == ApiVisibility.PublicAndInternal))
  83. return;
  84. ShowApiLevel = ApiVisibility.PublicAndInternal;
  85. OnPropertyChanged(nameof(ApiVisPublicOnly));
  86. OnPropertyChanged(nameof(ApiVisPublicAndInternal));
  87. OnPropertyChanged(nameof(ApiVisAll));
  88. }
  89. }
  90. public bool ApiVisAll {
  91. get { return showApiLevel == ApiVisibility.All; }
  92. set {
  93. if (value == (showApiLevel == ApiVisibility.All))
  94. return;
  95. ShowApiLevel = ApiVisibility.All;
  96. OnPropertyChanged(nameof(ApiVisPublicOnly));
  97. OnPropertyChanged(nameof(ApiVisPublicAndInternal));
  98. OnPropertyChanged(nameof(ApiVisAll));
  99. }
  100. }
  101. string? languageId;
  102. /// <summary>
  103. /// Gets/Sets the current language.
  104. /// </summary>
  105. /// <remarks>
  106. /// While this isn't related to filtering, having it as part of the FilterSettings
  107. /// makes it easy to pass it down into all tree nodes.
  108. /// </remarks>
  109. public string? LanguageId {
  110. get => languageId;
  111. set => SetProperty(ref languageId, value);
  112. }
  113. string? languageVersionId;
  114. /// <summary>
  115. /// Gets/Sets the current language version.
  116. /// </summary>
  117. /// <remarks>
  118. /// While this isn't related to filtering, having it as part of the FilterSettings
  119. /// makes it easy to pass it down into all tree nodes.
  120. /// </remarks>
  121. public string? LanguageVersionId {
  122. get { return languageVersionId; }
  123. set => SetProperty(ref languageVersionId, value);
  124. }
  125. // This class has been initially called FilterSettings, but then has been Hijacked to store language settings as well.
  126. // While the filter settings were some sort of local, the language settings are global. This is a bit of a mess.
  127. // There has been a lot of workarounds cloning the FilterSettings to pass them down to the tree nodes, without messing up the global language settings.
  128. // Finally, this filtering was not used at all, so this SearchTerm is just a placeholder to make the filtering code compile, in case someone wants to reactivate filtering in the future.
  129. public string SearchTerm => string.Empty;
  130. public bool SearchTermMatches(string value)
  131. {
  132. return true;
  133. }
  134. }
  135. }