Skip to content

Commit

Permalink
Merge pull request #3297 from tom-englert/dev/WpfRefactoring
Browse files Browse the repository at this point in the history
WPF refactoring
  • Loading branch information
siegfriedpammer authored Oct 6, 2024
2 parents f9ae51b + 5a1ec2c commit 7f46aab
Show file tree
Hide file tree
Showing 18 changed files with 235 additions and 147 deletions.
8 changes: 4 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
<PackageVersion Include="System.Reflection.Metadata" Version="8.0.0" />
<PackageVersion Include="System.Resources.Extensions" Version="8.0.0" />
<PackageVersion Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
<PackageVersion Include="TomsToolbox.Wpf.Composition" Version="2.18.1" />
<PackageVersion Include="TomsToolbox.Wpf.Composition.Mef" Version="2.18.1" />
<PackageVersion Include="TomsToolbox.Wpf.Styles" Version="2.18.1" />
<PackageVersion Include="TomsToolbox.Wpf.Composition" Version="2.20.0" />
<PackageVersion Include="TomsToolbox.Wpf.Composition.Mef" Version="2.20.0" />
<PackageVersion Include="TomsToolbox.Wpf.Styles" Version="2.20.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
</ItemGroup>
<ItemGroup>
<GlobalPackageReference Include="TomsToolbox.Composition.Analyzer" Version="2.18.1" />
<GlobalPackageReference Include="TomsToolbox.Composition.Analyzer" Version="2.20.0" />
</ItemGroup>
</Project>
14 changes: 6 additions & 8 deletions ICSharpCode.ILSpyX/AssemblyListManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,16 @@ public bool RenameList(string selectedAssemblyList, string newListName)
public void SaveList(AssemblyList list)
{
this.settingsProvider.Update(
delegate (XElement root) {
root => {
XElement? doc = root.Element("AssemblyLists");
if (doc == null)
{
doc = new XElement("AssemblyLists");
root.Add(doc);
}
XElement? listElement = doc.Elements("List").FirstOrDefault(e => (string?)e.Attribute("name") == list.ListName);

XElement? listElement = doc.Elements("List")
.FirstOrDefault(e => (string?)e.Attribute("name") == list.ListName);
if (listElement != null)
listElement.ReplaceWith(list.SaveAsXml());
else
Expand Down Expand Up @@ -163,13 +165,9 @@ public void ClearAll()
{
AssemblyLists.Clear();
this.settingsProvider.Update(
delegate (XElement root) {
root => {
XElement? doc = root.Element("AssemblyLists");
if (doc == null)
{
return;
}
doc.Remove();
doc?.Remove();
});
}

Expand Down
3 changes: 1 addition & 2 deletions ILSpy/Analyzers/AnalyzerTreeView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
ShowRoot="False"
BorderThickness="0"
Root="{Binding Root}"
toms:MultiSelectorExtensions.SelectionBinding="{Binding SelectedItems}"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
toms:MultiSelectorExtensions.SelectionBinding="{Binding SelectedItems, Mode=TwoWay}"
SelectionChanged="AnalyzerTreeView_OnSelectionChanged">

<UIElement.InputBindings>
Expand Down
24 changes: 13 additions & 11 deletions ILSpy/Analyzers/AnalyzerTreeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
// DEALINGS IN THE SOFTWARE.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.Composition;
using System.Linq;
using System.Windows;
Expand All @@ -38,8 +36,6 @@ namespace ICSharpCode.ILSpy.Analyzers
[Export]
public class AnalyzerTreeViewModel : ToolPaneModel
{
private AnalyzerTreeNode selectedItem;

public const string PaneContentId = "analyzerPane";

public AnalyzerTreeViewModel()
Expand All @@ -52,14 +48,20 @@ public AnalyzerTreeViewModel()

public AnalyzerRootNode Root { get; } = new();

public AnalyzerTreeNode SelectedItem {
get => selectedItem;
set => SetProperty(ref selectedItem, value);
}

public ICommand AnalyzeCommand => new DelegateCommand(AnalyzeSelected);

public ObservableCollection<AnalyzerTreeNode> SelectedItems { get; } = [];
private AnalyzerTreeNode[] selectedItems = [];

public AnalyzerTreeNode[] SelectedItems {
get => selectedItems ?? [];
set {
if (SelectedItems.SequenceEqual(value))
return;

selectedItems = value;
OnPropertyChanged();
}
}

private void AnalyzeSelected()
{
Expand Down Expand Up @@ -87,7 +89,7 @@ void AddOrSelect(AnalyzerTreeNode node)
}

target.IsExpanded = true;
this.SelectedItem = target;
this.SelectedItems = [target];
}

public void Analyze(IEntity entity)
Expand Down
3 changes: 0 additions & 3 deletions ILSpy/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,6 @@ protected override void OnStartup(StartupEventArgs e)
}

MainWindow = new MainWindow();
MainWindow.Loaded += (sender, args) => {
ExportProvider.GetExportedValue<AssemblyTreeModel>().Initialize();
};
MainWindow.Show();
}

Expand Down
5 changes: 3 additions & 2 deletions ILSpy/AssemblyTree/AssemblyListPane.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
xmlns:treeNodes="clr-namespace:ICSharpCode.ILSpy.TreeNodes"
xmlns:assemblyTree="clr-namespace:ICSharpCode.ILSpy.AssemblyTree"
xmlns:toms="urn:TomsToolbox"
xmlns:viewModels="clr-namespace:ICSharpCode.ILSpy.ViewModels"
mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance assemblyTree:AssemblyTreeModel}"
AutomationProperties.Name="Assemblies and Classes"
Expand All @@ -15,8 +16,8 @@
AllowDrop="True"
BorderThickness="0" Visibility="Visible"
Root="{Binding Root}"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
toms:MultiSelectorExtensions.SelectionBinding="{Binding SelectedItems}">
toms:MultiSelectorExtensions.SelectionBinding="{Binding SelectedItems, Mode=TwoWay}"
viewModels:Pane.IsActive="{Binding IsActive}">
<treeView:SharpTreeView.ItemContainerStyle>
<Style TargetType="treeView:SharpTreeViewItem">
<Setter Property="Template">
Expand Down
17 changes: 17 additions & 0 deletions ILSpy/AssemblyTree/AssemblyListPane.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
using System.Windows;
using System.Windows.Threading;

using ICSharpCode.ILSpy.ViewModels;
using ICSharpCode.ILSpyX.TreeView;

using TomsToolbox.Wpf.Composition.Mef;

namespace ICSharpCode.ILSpy.AssemblyTree
Expand Down Expand Up @@ -59,6 +62,20 @@ protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
});
}
}
else if (e.Property == Pane.IsActiveProperty)
{
if (!true.Equals(e.NewValue))
return;

if (SelectedItem is SharpTreeNode selectedItem)
{
FocusNode(selectedItem);
}
else
{
Focus();
}
}
}
}
}
Loading

0 comments on commit 7f46aab

Please sign in to comment.