Skip to content

Commit

Permalink
Simplify adding tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-englert committed Aug 20, 2024
1 parent 97bd5cb commit d71394c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
4 changes: 3 additions & 1 deletion BuildTools/format.bat
Original file line number Diff line number Diff line change
@@ -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.
"%ProgramFiles%\Git\usr\bin\bash.exe" BuildTools\pre-commit --format
pushd %~dp0\..
"%ProgramFiles%\Git\usr\bin\bash.exe" BuildTools\pre-commit --format
popd
5 changes: 5 additions & 0 deletions ILSpy/Docking/DockWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ private void MainWindow_Instance_CurrentAssemblyListChanged(object sender, Notif
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)
{
Expand Down
8 changes: 4 additions & 4 deletions ILSpy/Docking/PaneCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
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>();

Expand All @@ -39,8 +37,10 @@ public PaneCollection()
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;
Expand Down
12 changes: 4 additions & 8 deletions ILSpy/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,7 @@ static bool CanResolveTypeInPEFile(MetadataFile module, ITypeReference typeRef,

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;

Expand Down Expand Up @@ -1087,8 +1086,7 @@ public void SelectNode(SharpTreeNode obj, bool inNewTabPage, bool setFocus)
{
if (inNewTabPage)
{
DockWorkspace.Instance.TabPages.Add(new TabPageModel() { });
DockWorkspace.Instance.ActiveTabPage = DockWorkspace.Instance.TabPages.Last();
DockWorkspace.Instance.TabPages.Add();
AssemblyTreeView.SelectedItem = null;
}

Expand Down Expand Up @@ -1130,8 +1128,7 @@ internal void SelectNodes(IEnumerable<SharpTreeNode> nodes, bool inNewTabPage,
{
if (inNewTabPage)
{
DockWorkspace.Instance.TabPages.Add(new TabPageModel() { });
DockWorkspace.Instance.ActiveTabPage = DockWorkspace.Instance.TabPages.Last();
DockWorkspace.Instance.TabPages.Add();
}

// Ensure nodes exist
Expand Down Expand Up @@ -1575,8 +1572,7 @@ internal void NavigateTo(RequestNavigateEventArgs e, bool recordHistory = true,
{
if (inNewTabPage)
{
DockWorkspace.Instance.TabPages.Add(new() { });
DockWorkspace.Instance.ActiveTabPage = DockWorkspace.Instance.TabPages.Last();
DockWorkspace.Instance.TabPages.Add();
}

if (e.Uri.Host == "aboutpage")
Expand Down

0 comments on commit d71394c

Please sign in to comment.