Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPF refactoring #3297

Merged
merged 4 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading