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.

105 lines
3.4 KiB

14 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;
  19. using System.Collections.Generic;
  20. using System.Collections.Specialized;
  21. using System.Linq;
  22. using System.Windows;
  23. using ICSharpCode.ILSpy.TreeNodes.Analyzer;
  24. using ICSharpCode.TreeView;
  25. namespace ICSharpCode.ILSpy
  26. {
  27. /// <summary>
  28. /// Analyzer tree view.
  29. /// </summary>
  30. public class AnalyzerTreeView : SharpTreeView, IPane
  31. {
  32. static AnalyzerTreeView instance;
  33. public static AnalyzerTreeView Instance
  34. {
  35. get
  36. {
  37. if (instance == null) {
  38. App.Current.VerifyAccess();
  39. instance = new AnalyzerTreeView();
  40. }
  41. return instance;
  42. }
  43. }
  44. private AnalyzerTreeView()
  45. {
  46. this.ShowRoot = false;
  47. this.Root = new AnalyzerRootNode { Language = MainWindow.Instance.CurrentLanguage };
  48. this.BorderThickness = new Thickness(0);
  49. ContextMenuProvider.Add(this);
  50. MainWindow.Instance.CurrentAssemblyListChanged += MainWindow_Instance_CurrentAssemblyListChanged;
  51. }
  52. void MainWindow_Instance_CurrentAssemblyListChanged(object sender, NotifyCollectionChangedEventArgs e)
  53. {
  54. if (e.Action == NotifyCollectionChangedAction.Reset) {
  55. this.Root.Children.Clear();
  56. } else {
  57. List<LoadedAssembly> removedAssemblies = new List<LoadedAssembly>();
  58. if (e.OldItems != null)
  59. removedAssemblies.AddRange(e.OldItems.Cast<LoadedAssembly>());
  60. List<LoadedAssembly> addedAssemblies = new List<LoadedAssembly>();
  61. if (e.NewItems != null)
  62. addedAssemblies.AddRange(e.NewItems.Cast<LoadedAssembly>());
  63. ((AnalyzerRootNode)this.Root).HandleAssemblyListChanged(removedAssemblies, addedAssemblies);
  64. }
  65. }
  66. public void Show()
  67. {
  68. if (!IsVisible)
  69. MainWindow.Instance.ShowInBottomPane("Analyzer", this);
  70. }
  71. public void Show(AnalyzerTreeNode node)
  72. {
  73. Show();
  74. node.IsExpanded = true;
  75. this.Root.Children.Add(node);
  76. this.SelectedItem = node;
  77. this.FocusNode(node);
  78. }
  79. void IPane.Closed()
  80. {
  81. this.Root.Children.Clear();
  82. }
  83. sealed class AnalyzerRootNode : AnalyzerTreeNode
  84. {
  85. public override bool HandleAssemblyListChanged(ICollection<LoadedAssembly> removedAssemblies, ICollection<LoadedAssembly> addedAssemblies)
  86. {
  87. this.Children.RemoveAll(
  88. delegate(SharpTreeNode n) {
  89. AnalyzerTreeNode an = n as AnalyzerTreeNode;
  90. return an == null || !an.HandleAssemblyListChanged(removedAssemblies, addedAssemblies);
  91. });
  92. return true;
  93. }
  94. }
  95. }
  96. }