Skip to content

Commit

Permalink
Refactor window menu composition: simplify by using WPF patterns.
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-englert committed Sep 3, 2024
1 parent 4e8566e commit d29d3dc
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 255 deletions.
13 changes: 10 additions & 3 deletions ILSpy/Docking/PaneCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand All @@ -25,10 +26,10 @@

namespace ICSharpCode.ILSpy.Docking
{
public class PaneCollection<T> : INotifyCollectionChanged, ICollection<T>
public class PaneCollection<T> : INotifyCollectionChanged, IList<T>
where T : PaneModel, new()
{
private ObservableCollection<T> observableCollection = new ObservableCollection<T>();
private readonly ObservableCollection<T> observableCollection = [];

public event NotifyCollectionChangedEventHandler CollectionChanged;

Expand All @@ -46,7 +47,6 @@ public void Add(T item = null)
item.IsVisible = true;
item.IsActive = true;
}

public int Count => observableCollection.Count;
public bool IsReadOnly => false;
public void Clear() => observableCollection.Clear();
Expand All @@ -55,5 +55,12 @@ public void Add(T item = null)
public bool Remove(T item) => observableCollection.Remove(item);
public IEnumerator<T> GetEnumerator() => observableCollection.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => observableCollection.GetEnumerator();
int IList<T>.IndexOf(T item) => observableCollection.IndexOf(item);

Check warning on line 58 in ILSpy/Docking/PaneCollection.cs

View workflow job for this annotation

GitHub Actions / Build (Debug)

Make 'PaneCollection' sealed (a breaking change if this class has previously shipped), implement the method non-explicitly, or implement a new method that exposes the functionality of 'System.Collections.Generic.IList<T>.IndexOf' and is visible to derived classes (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1033)

Check warning on line 58 in ILSpy/Docking/PaneCollection.cs

View workflow job for this annotation

GitHub Actions / Build (Debug)

Make 'PaneCollection' sealed (a breaking change if this class has previously shipped), implement the method non-explicitly, or implement a new method that exposes the functionality of 'System.Collections.Generic.IList<T>.IndexOf' and is visible to derived classes (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1033)

Check warning on line 58 in ILSpy/Docking/PaneCollection.cs

View workflow job for this annotation

GitHub Actions / Build (Release)

Make 'PaneCollection' sealed (a breaking change if this class has previously shipped), implement the method non-explicitly, or implement a new method that exposes the functionality of 'System.Collections.Generic.IList<T>.IndexOf' and is visible to derived classes (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1033)

Check warning on line 58 in ILSpy/Docking/PaneCollection.cs

View workflow job for this annotation

GitHub Actions / Build (Release)

Make 'PaneCollection' sealed (a breaking change if this class has previously shipped), implement the method non-explicitly, or implement a new method that exposes the functionality of 'System.Collections.Generic.IList<T>.IndexOf' and is visible to derived classes (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1033)
void IList<T>.Insert(int index, T item) => throw new NotImplementedException("Only Add is supported");
void IList<T>.RemoveAt(int index) => observableCollection.RemoveAt(index);

Check warning on line 60 in ILSpy/Docking/PaneCollection.cs

View workflow job for this annotation

GitHub Actions / Build (Debug)

Make 'PaneCollection' sealed (a breaking change if this class has previously shipped), implement the method non-explicitly, or implement a new method that exposes the functionality of 'System.Collections.Generic.IList<T>.RemoveAt' and is visible to derived classes (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1033)

Check warning on line 60 in ILSpy/Docking/PaneCollection.cs

View workflow job for this annotation

GitHub Actions / Build (Debug)

Make 'PaneCollection' sealed (a breaking change if this class has previously shipped), implement the method non-explicitly, or implement a new method that exposes the functionality of 'System.Collections.Generic.IList<T>.RemoveAt' and is visible to derived classes (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1033)

Check warning on line 60 in ILSpy/Docking/PaneCollection.cs

View workflow job for this annotation

GitHub Actions / Build (Release)

Make 'PaneCollection' sealed (a breaking change if this class has previously shipped), implement the method non-explicitly, or implement a new method that exposes the functionality of 'System.Collections.Generic.IList<T>.RemoveAt' and is visible to derived classes (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1033)

Check warning on line 60 in ILSpy/Docking/PaneCollection.cs

View workflow job for this annotation

GitHub Actions / Build (Release)

Make 'PaneCollection' sealed (a breaking change if this class has previously shipped), implement the method non-explicitly, or implement a new method that exposes the functionality of 'System.Collections.Generic.IList<T>.RemoveAt' and is visible to derived classes (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1033)
T IList<T>.this[int index] {
get => observableCollection[index];

Check warning on line 62 in ILSpy/Docking/PaneCollection.cs

View workflow job for this annotation

GitHub Actions / Build (Debug)

Make 'PaneCollection' sealed (a breaking change if this class has previously shipped), implement the method non-explicitly, or implement a new method that exposes the functionality of 'System.Collections.Generic.IList<T>.get_Item' and is visible to derived classes (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1033)

Check warning on line 62 in ILSpy/Docking/PaneCollection.cs

View workflow job for this annotation

GitHub Actions / Build (Debug)

Make 'PaneCollection' sealed (a breaking change if this class has previously shipped), implement the method non-explicitly, or implement a new method that exposes the functionality of 'System.Collections.Generic.IList<T>.get_Item' and is visible to derived classes (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1033)

Check warning on line 62 in ILSpy/Docking/PaneCollection.cs

View workflow job for this annotation

GitHub Actions / Build (Release)

Make 'PaneCollection' sealed (a breaking change if this class has previously shipped), implement the method non-explicitly, or implement a new method that exposes the functionality of 'System.Collections.Generic.IList<T>.get_Item' and is visible to derived classes (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1033)

Check warning on line 62 in ILSpy/Docking/PaneCollection.cs

View workflow job for this annotation

GitHub Actions / Build (Release)

Make 'PaneCollection' sealed (a breaking change if this class has previously shipped), implement the method non-explicitly, or implement a new method that exposes the functionality of 'System.Collections.Generic.IList<T>.get_Item' and is visible to derived classes (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1033)
set => observableCollection[index] = value;

Check warning on line 63 in ILSpy/Docking/PaneCollection.cs

View workflow job for this annotation

GitHub Actions / Build (Debug)

Make 'PaneCollection' sealed (a breaking change if this class has previously shipped), implement the method non-explicitly, or implement a new method that exposes the functionality of 'System.Collections.Generic.IList<T>.set_Item' and is visible to derived classes (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1033)

Check warning on line 63 in ILSpy/Docking/PaneCollection.cs

View workflow job for this annotation

GitHub Actions / Build (Debug)

Make 'PaneCollection' sealed (a breaking change if this class has previously shipped), implement the method non-explicitly, or implement a new method that exposes the functionality of 'System.Collections.Generic.IList<T>.set_Item' and is visible to derived classes (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1033)

Check warning on line 63 in ILSpy/Docking/PaneCollection.cs

View workflow job for this annotation

GitHub Actions / Build (Release)

Make 'PaneCollection' sealed (a breaking change if this class has previously shipped), implement the method non-explicitly, or implement a new method that exposes the functionality of 'System.Collections.Generic.IList<T>.set_Item' and is visible to derived classes (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1033)

Check warning on line 63 in ILSpy/Docking/PaneCollection.cs

View workflow job for this annotation

GitHub Actions / Build (Release)

Make 'PaneCollection' sealed (a breaking change if this class has previously shipped), implement the method non-explicitly, or implement a new method that exposes the functionality of 'System.Collections.Generic.IList<T>.set_Item' and is visible to derived classes (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1033)
}
}
}
60 changes: 32 additions & 28 deletions ILSpy/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>

<Window
x:Class="ICSharpCode.ILSpy.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tv="clr-namespace:ICSharpCode.ILSpy.Controls.TreeView"
xmlns:local="clr-namespace:ICSharpCode.ILSpy"
xmlns:avalondock="https://github.com/Dirkster99/AvalonDock"
xmlns:controls="clr-namespace:ICSharpCode.ILSpy.Controls"
xmlns:docking="clr-namespace:ICSharpCode.ILSpy.Docking"
xmlns:properties="clr-namespace:ICSharpCode.ILSpy.Properties"
Title="ILSpy"
MinWidth="250"
MinHeight="200"
UseLayoutRounding="True"
TextOptions.TextFormattingMode="Display"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" d:DesignHeight="500" d:DesignWidth="500"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
xmlns:themes="clr-namespace:ICSharpCode.ILSpy.Themes"
xmlns:toms="urn:TomsToolbox"
xmlns:viewModels="clr-namespace:ICSharpCode.ILSpy.ViewModels"
d:DataContext="{d:DesignInstance local:MainWindowViewModel}">
<Window x:Class="ICSharpCode.ILSpy.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ICSharpCode.ILSpy"
xmlns:avalondock="https://github.com/Dirkster99/AvalonDock"
xmlns:controls="clr-namespace:ICSharpCode.ILSpy.Controls"
xmlns:docking="clr-namespace:ICSharpCode.ILSpy.Docking"
xmlns:properties="clr-namespace:ICSharpCode.ILSpy.Properties"
Title="ILSpy"
MinWidth="250"
MinHeight="200"
UseLayoutRounding="True"
TextOptions.TextFormattingMode="Display"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" d:DesignHeight="500" d:DesignWidth="500"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
xmlns:themes="clr-namespace:ICSharpCode.ILSpy.Themes"
xmlns:toms="urn:TomsToolbox"
xmlns:viewModels="clr-namespace:ICSharpCode.ILSpy.ViewModels"
d:DataContext="{d:DesignInstance local:MainWindowViewModel}">
<Window.Resources>

<DataTemplate DataType="{x:Type viewModels:TabPageModel}">
Expand Down Expand Up @@ -78,9 +76,12 @@
<MenuItem Header="{x:Static properties:Resources._File}" Tag="_File" />
<!-- contents of file menu are added using MEF -->
<MenuItem Header="{x:Static properties:Resources._View}" Tag="_View">
<MenuItem Header="{x:Static properties:Resources.Show_publiconlyTypesMembers}" IsCheckable="True" IsChecked="{Binding SessionSettings.LanguageSettings.ApiVisPublicOnly}" />
<MenuItem Header="{x:Static properties:Resources.Show_internalTypesMembers}" IsCheckable="True" IsChecked="{Binding SessionSettings.LanguageSettings.ApiVisPublicAndInternal}" />
<MenuItem Header="{x:Static properties:Resources.Show_allTypesAndMembers}" IsCheckable="True" IsChecked="{Binding SessionSettings.LanguageSettings.ApiVisAll}" />
<MenuItem Header="{x:Static properties:Resources.Show_publiconlyTypesMembers}" IsCheckable="True"
IsChecked="{Binding SessionSettings.LanguageSettings.ApiVisPublicOnly}" />
<MenuItem Header="{x:Static properties:Resources.Show_internalTypesMembers}" IsCheckable="True"
IsChecked="{Binding SessionSettings.LanguageSettings.ApiVisPublicAndInternal}" />
<MenuItem Header="{x:Static properties:Resources.Show_allTypesAndMembers}" IsCheckable="True"
IsChecked="{Binding SessionSettings.LanguageSettings.ApiVisAll}" />
<Separator />
<MenuItem Header="{x:Static properties:Resources.Theme}" ItemsSource="{x:Static themes:ThemeManager.AllThemes}">
<MenuItem.ItemContainerStyle>
Expand All @@ -101,9 +102,12 @@
</MenuItem.ItemContainerStyle>
</MenuItem>
<MenuItem Header="{x:Static properties:Resources.UILanguage}">
<MenuItem Header="{x:Static properties:Resources.UILanguage_System}" IsCheckable="True" IsChecked="{Binding SessionSettings.CurrentCulture, Converter={controls:CultureSelectionConverter}, ConverterParameter={x:Null}}" />
<MenuItem Header="English" IsCheckable="True" IsChecked="{Binding SessionSettings.CurrentCulture, Converter={controls:CultureSelectionConverter}, ConverterParameter=en-US}" />
<MenuItem Header="中文" IsCheckable="True" IsChecked="{Binding SessionSettings.CurrentCulture, Converter={controls:CultureSelectionConverter}, ConverterParameter=zh-Hans}" />
<MenuItem Header="{x:Static properties:Resources.UILanguage_System}" IsCheckable="True"
IsChecked="{Binding SessionSettings.CurrentCulture, Converter={controls:CultureSelectionConverter}, ConverterParameter={x:Null}}" />
<MenuItem Header="English" IsCheckable="True"
IsChecked="{Binding SessionSettings.CurrentCulture, Converter={controls:CultureSelectionConverter}, ConverterParameter=en-US}" />
<MenuItem Header="中文" IsCheckable="True"
IsChecked="{Binding SessionSettings.CurrentCulture, Converter={controls:CultureSelectionConverter}, ConverterParameter=zh-Hans}" />
</MenuItem>
</MenuItem>
<MenuItem Header="{x:Static properties:Resources._Window}" Tag="_Window" />
Expand Down
2 changes: 1 addition & 1 deletion ILSpy/Metadata/CorTables/PtrTableTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ struct PtrEntry

public void OnHandleClick()
{
MainWindow.Instance.JumpToReference(new EntityReference(metadataFile, handlePtr.Handle, protocol: "metadata"));
MessageBus.Send(this, new NavigateToReferenceEventArgs(new EntityReference(metadataFile, handlePtr.Handle, protocol: "metadata")));
}

string handleTooltip;
Expand Down
Loading

0 comments on commit d29d3dc

Please sign in to comment.