Browse Source

Simplify adding tabs

pull/3257/head
tom-englert 9 months ago
parent
commit
d71394c43a
  1. 2
      BuildTools/format.bat
  2. 5
      ILSpy/Docking/DockWorkspace.cs
  3. 8
      ILSpy/Docking/PaneCollection.cs
  4. 12
      ILSpy/MainWindow.xaml.cs

2
BuildTools/format.bat

@ -1,3 +1,5 @@ @@ -1,3 +1,5 @@
@rem This file can be used to trigger the commit hook's formatting,
@rem modifying the local formatting even if not committing all changes.
pushd %~dp0\..
"%ProgramFiles%\Git\usr\bin\bash.exe" BuildTools\pre-commit --format
popd

5
ILSpy/Docking/DockWorkspace.cs

@ -88,6 +88,11 @@ namespace ICSharpCode.ILSpy.Docking @@ -88,6 +88,11 @@ namespace ICSharpCode.ILSpy.Docking
private void Documents_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
var collection = (PaneCollection<TabPageModel>)sender;
if (e.Action == NotifyCollectionChangedAction.Add)
{
ActiveTabPage = e.NewItems?[0] as TabPageModel;
}
bool canClose = collection.Count > 1;
foreach (var item in collection)
{

8
ILSpy/Docking/PaneCollection.cs

@ -20,15 +20,13 @@ using System.Collections; @@ -20,15 +20,13 @@ using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using ICSharpCode.ILSpy.ViewModels;
namespace ICSharpCode.ILSpy.Docking
{
public class PaneCollection<T> : INotifyCollectionChanged, ICollection<T>
where T : PaneModel
where T : PaneModel, new()
{
private ObservableCollection<T> observableCollection = new ObservableCollection<T>();
@ -39,8 +37,10 @@ namespace ICSharpCode.ILSpy.Docking @@ -39,8 +37,10 @@ namespace ICSharpCode.ILSpy.Docking
observableCollection.CollectionChanged += (sender, e) => CollectionChanged?.Invoke(this, e);
}
public void Add(T item)
public void Add(T item = null)
{
item ??= new T();
observableCollection.Add(item);
item.IsVisible = true;

12
ILSpy/MainWindow.xaml.cs

@ -831,8 +831,7 @@ namespace ICSharpCode.ILSpy @@ -831,8 +831,7 @@ namespace ICSharpCode.ILSpy
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
DockWorkspace.Instance.TabPages.Add(new() { });
DockWorkspace.Instance.ActiveTabPage = DockWorkspace.Instance.TabPages.First();
DockWorkspace.Instance.TabPages.Add();
var loadPreviousAssemblies = Options.MiscSettingsPanel.CurrentMiscSettings.LoadPreviousAssemblies;
@ -1087,8 +1086,7 @@ namespace ICSharpCode.ILSpy @@ -1087,8 +1086,7 @@ namespace ICSharpCode.ILSpy
{
if (inNewTabPage)
{
DockWorkspace.Instance.TabPages.Add(new TabPageModel() { });
DockWorkspace.Instance.ActiveTabPage = DockWorkspace.Instance.TabPages.Last();
DockWorkspace.Instance.TabPages.Add();
AssemblyTreeView.SelectedItem = null;
}
@ -1130,8 +1128,7 @@ namespace ICSharpCode.ILSpy @@ -1130,8 +1128,7 @@ namespace ICSharpCode.ILSpy
{
if (inNewTabPage)
{
DockWorkspace.Instance.TabPages.Add(new TabPageModel() { });
DockWorkspace.Instance.ActiveTabPage = DockWorkspace.Instance.TabPages.Last();
DockWorkspace.Instance.TabPages.Add();
}
// Ensure nodes exist
@ -1575,8 +1572,7 @@ namespace ICSharpCode.ILSpy @@ -1575,8 +1572,7 @@ namespace ICSharpCode.ILSpy
{
if (inNewTabPage)
{
DockWorkspace.Instance.TabPages.Add(new() { });
DockWorkspace.Instance.ActiveTabPage = DockWorkspace.Instance.TabPages.Last();
DockWorkspace.Instance.TabPages.Add();
}
if (e.Uri.Host == "aboutpage")

Loading…
Cancel
Save