Browse Source

Omit the need for a special PaneCollection

pull/3274/head
tom-englert 9 months ago committed by tom-englert
parent
commit
84d635633e
  1. 4
      ILSpy/AssemblyTree/AssemblyListPaneModel.cs
  2. 54
      ILSpy/Docking/DockWorkspace.cs
  3. 66
      ILSpy/Docking/PaneCollection.cs
  4. 4
      ILSpy/MainWindow.xaml.cs

4
ILSpy/AssemblyTree/AssemblyListPaneModel.cs

@ -481,7 +481,7 @@ namespace ICSharpCode.ILSpy.AssemblyTree @@ -481,7 +481,7 @@ namespace ICSharpCode.ILSpy.AssemblyTree
if (inNewTabPage)
{
DockWorkspace.Instance.TabPages.Add();
DockWorkspace.Instance.AddTabPage();
SelectedItem = null;
}
@ -505,7 +505,7 @@ namespace ICSharpCode.ILSpy.AssemblyTree @@ -505,7 +505,7 @@ namespace ICSharpCode.ILSpy.AssemblyTree
if (inNewTabPage)
{
DockWorkspace.Instance.TabPages.Add();
DockWorkspace.Instance.AddTabPage();
}
// Ensure nodes exist

54
ILSpy/Docking/DockWorkspace.cs

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
@ -49,9 +50,15 @@ namespace ICSharpCode.ILSpy.Docking @@ -49,9 +50,15 @@ namespace ICSharpCode.ILSpy.Docking
public static readonly DockWorkspace Instance = new();
private readonly ObservableCollection<TabPageModel> tabPages = [];
private readonly ObservableCollection<ToolPaneModel> toolPanes = [];
private DockWorkspace()
{
this.TabPages.CollectionChanged += Documents_CollectionChanged;
this.tabPages.CollectionChanged += TabPages_CollectionChanged;
TabPages = new(tabPages);
ToolPanes = new(toolPanes);
MessageBus<CurrentAssemblyListChangedEventArgs>.Subscribers += (sender, e) => CurrentAssemblyList_Changed(sender, e);
}
@ -61,7 +68,7 @@ namespace ICSharpCode.ILSpy.Docking @@ -61,7 +68,7 @@ namespace ICSharpCode.ILSpy.Docking
{
return;
}
foreach (var tab in TabPages.ToArray())
foreach (var tab in tabPages.ToArray())
{
var state = tab.GetState();
if (state == null || state.DecompiledNodes == null)
@ -78,35 +85,45 @@ namespace ICSharpCode.ILSpy.Docking @@ -78,35 +85,45 @@ namespace ICSharpCode.ILSpy.Docking
break;
}
}
if (!found && TabPages.Count > 1)
if (!found && tabPages.Count > 1)
{
TabPages.Remove(tab);
tabPages.Remove(tab);
}
}
}
private void Documents_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
private void TabPages_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
var collection = (PaneCollection<TabPageModel>)sender;
if (e.Action == NotifyCollectionChangedAction.Add)
{
ActiveTabPage = e.NewItems?[0] as TabPageModel;
if (e.NewItems?[0] is TabPageModel model)
{
ActiveTabPage = model;
model.IsActive = true;
model.IsVisible = true;
}
}
bool canClose = collection.Count > 1;
foreach (var item in collection)
bool canClose = tabPages.Count > 1;
foreach (var item in tabPages)
{
item.IsCloseable = canClose;
}
}
public PaneCollection<TabPageModel> TabPages { get; } = new PaneCollection<TabPageModel>();
public void AddTabPage(TabPageModel tabPage = null)
{
tabPages.Add(tabPage ?? new TabPageModel());
}
public ObservableCollection<ToolPaneModel> ToolPanes { get; } = new ObservableCollection<ToolPaneModel>();
public ReadOnlyObservableCollection<TabPageModel> TabPages { get; }
public ReadOnlyObservableCollection<ToolPaneModel> ToolPanes { get; }
public bool ShowToolPane(string contentId)
{
var pane = ToolPanes.FirstOrDefault(p => p.ContentId == contentId);
var pane = toolPanes.FirstOrDefault(p => p.ContentId == contentId);
if (pane != null)
{
pane.Show();
@ -118,7 +135,7 @@ namespace ICSharpCode.ILSpy.Docking @@ -118,7 +135,7 @@ namespace ICSharpCode.ILSpy.Docking
public void Remove(PaneModel model)
{
if (model is TabPageModel document)
TabPages.Remove(document);
tabPages.Remove(document);
if (model is ToolPaneModel tool)
tool.IsVisible = false;
}
@ -153,7 +170,8 @@ namespace ICSharpCode.ILSpy.Docking @@ -153,7 +170,8 @@ namespace ICSharpCode.ILSpy.Docking
public void InitializeLayout(DockingManager manager)
{
var toolPanes = exportProvider.GetExportedValues<ToolPaneModel>("ToolPane").OrderBy(item => item.Title);
ToolPanes.AddRange(toolPanes);
this.toolPanes.AddRange(toolPanes);
manager.LayoutUpdateStrategy = this;
XmlLayoutSerializer serializer = new XmlLayoutSerializer(manager);
@ -173,7 +191,7 @@ namespace ICSharpCode.ILSpy.Docking @@ -173,7 +191,7 @@ namespace ICSharpCode.ILSpy.Docking
switch (e.Model)
{
case LayoutAnchorable la:
e.Content = ToolPanes.FirstOrDefault(p => p.ContentId == la.ContentId);
e.Content = this.toolPanes.FirstOrDefault(p => p.ContentId == la.ContentId);
e.Cancel = e.Content == null;
la.CanDockAsTabbedDocument = false;
if (!e.Cancel)
@ -205,16 +223,16 @@ namespace ICSharpCode.ILSpy.Docking @@ -205,16 +223,16 @@ namespace ICSharpCode.ILSpy.Docking
internal void CloseAllTabs()
{
foreach (var doc in TabPages.ToArray())
foreach (var doc in tabPages.ToArray())
{
if (doc.IsCloseable)
TabPages.Remove(doc);
tabPages.Remove(doc);
}
}
internal void ResetLayout()
{
foreach (var pane in ToolPanes)
foreach (var pane in toolPanes)
{
pane.IsVisible = false;
}

66
ILSpy/Docking/PaneCollection.cs

@ -1,66 +0,0 @@ @@ -1,66 +0,0 @@
// Copyright (c) 2019 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// 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;
using System.Collections.Specialized;
using ICSharpCode.ILSpy.ViewModels;
namespace ICSharpCode.ILSpy.Docking
{
public class PaneCollection<T> : INotifyCollectionChanged, IList<T>
where T : PaneModel, new()
{
private readonly ObservableCollection<T> observableCollection = [];
public event NotifyCollectionChangedEventHandler CollectionChanged;
public PaneCollection()
{
observableCollection.CollectionChanged += (sender, e) => CollectionChanged?.Invoke(this, e);
}
public void Add(T item = null)
{
item ??= new T();
observableCollection.Add(item);
item.IsVisible = true;
item.IsActive = true;
}
public int Count => observableCollection.Count;
public bool IsReadOnly => false;
public void Clear() => observableCollection.Clear();
public bool Contains(T item) => observableCollection.Contains(item);
public void CopyTo(T[] array, int arrayIndex) => observableCollection.CopyTo(array, arrayIndex);
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);
void IList<T>.Insert(int index, T item) => throw new NotImplementedException("Only Add is supported");
void IList<T>.RemoveAt(int index) => observableCollection.RemoveAt(index);
T IList<T>.this[int index] {
get => observableCollection[index];
set => observableCollection[index] = value;
}
}
}

4
ILSpy/MainWindow.xaml.cs

@ -191,7 +191,7 @@ namespace ICSharpCode.ILSpy @@ -191,7 +191,7 @@ namespace ICSharpCode.ILSpy
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
DockWorkspace.Instance.TabPages.Add();
DockWorkspace.Instance.AddTabPage();
AssemblyTreeModel.Initialize();
}
@ -380,7 +380,7 @@ namespace ICSharpCode.ILSpy @@ -380,7 +380,7 @@ namespace ICSharpCode.ILSpy
{
if (inNewTabPage)
{
DockWorkspace.Instance.TabPages.Add();
DockWorkspace.Instance.AddTabPage();
}
if (e.Uri.Host == "aboutpage")

Loading…
Cancel
Save