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.

86 lines
2.6 KiB

  1. // Copyright (c) 2024 Tom Englert 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.Composition;
  19. using System.Windows;
  20. using System.Windows.Threading;
  21. using ICSharpCode.ILSpy.ViewModels;
  22. using ICSharpCode.ILSpyX.TreeView;
  23. using TomsToolbox.Wpf;
  24. using TomsToolbox.Wpf.Composition.AttributedModel;
  25. namespace ICSharpCode.ILSpy.AssemblyTree
  26. {
  27. /// <summary>
  28. /// Interaction logic for AssemblyListPane.xaml
  29. /// </summary>
  30. [DataTemplate(typeof(AssemblyTreeModel))]
  31. [NonShared]
  32. public partial class AssemblyListPane
  33. {
  34. public AssemblyListPane()
  35. {
  36. InitializeComponent();
  37. ContextMenuProvider.Add(this);
  38. }
  39. protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
  40. {
  41. base.OnPropertyChanged(e);
  42. if (e.Property == DataContextProperty)
  43. {
  44. if (e.NewValue is not AssemblyTreeModel model)
  45. return;
  46. model.SetActiveView(this);
  47. // If there is already a selected item in the model, we need to scroll it into view, so it can be selected in the UI.
  48. var selected = model.SelectedItem;
  49. if (selected != null)
  50. {
  51. this.BeginInvoke(DispatcherPriority.Background, () => {
  52. ScrollIntoView(selected);
  53. this.SelectedItem = selected;
  54. });
  55. }
  56. }
  57. else if (e.Property == Pane.IsActiveProperty)
  58. {
  59. if (!true.Equals(e.NewValue))
  60. return;
  61. if (SelectedItem is SharpTreeNode selectedItem)
  62. {
  63. // defer focusing, so it does not interfere with selection via mouse click
  64. this.BeginInvoke(() => {
  65. if (this.SelectedItem == selectedItem)
  66. FocusNode(selectedItem);
  67. });
  68. }
  69. else
  70. {
  71. Focus();
  72. }
  73. }
  74. }
  75. }
  76. }