Browse Source

Collapse CloseAllTabs/CloseAllTabsExcept into CloseTabsWhere

The two were identical bar the skip predicate (the home tab vs the kept
tab); both snapshot the visible documents and route each through CloseTab.
Extract the shared loop as CloseTabsWhere(predicate).

Assisted-by: Claude:claude-opus-4-8:Claude Code
pull/3755/head
Siegfried Pammer 4 weeks ago
parent
commit
2c5dca8d0b
  1. 22
      ILSpy/Docking/DockWorkspace.cs

22
ILSpy/Docking/DockWorkspace.cs

@ -1257,17 +1257,20 @@ namespace ILSpy.Docking
} }
public void CloseAllTabs() public void CloseAllTabs()
// Close every carve-out tab but keep the One (the persistent preview/home tab that the
// rest of the app relies on always existing -- ShowSelectedNode reuses it). This also keeps
// the document area non-empty, sidestepping Dock's "can't close the last dockable" veto.
=> CloseTabsWhere(doc => !ReferenceEquals(doc, factory.MainTab));
// Snapshot first -- CloseTab -> CloseDockable mutates the visible-dockables list.
void CloseTabsWhere(Func<ContentTabPage, bool> shouldClose)
{ {
var docs = factory.Documents?.VisibleDockables; var docs = factory.Documents?.VisibleDockables;
if (docs == null) if (docs == null)
return; return;
// Close every carve-out tab but keep the One (the persistent preview/home tab that the
// rest of the app relies on always existing -- ShowSelectedNode reuses it). This also keeps
// the document area non-empty, sidestepping Dock's "can't close the last dockable" veto.
// Snapshot first -- CloseDockable mutates the list.
foreach (var doc in docs.OfType<ContentTabPage>().ToArray()) foreach (var doc in docs.OfType<ContentTabPage>().ToArray())
{ {
if (!ReferenceEquals(doc, factory.MainTab)) if (shouldClose(doc))
CloseTab(doc); CloseTab(doc);
} }
} }
@ -1288,14 +1291,7 @@ namespace ILSpy.Docking
public void CloseAllTabsExcept(ContentTabPage keep) public void CloseAllTabsExcept(ContentTabPage keep)
{ {
ArgumentNullException.ThrowIfNull(keep); ArgumentNullException.ThrowIfNull(keep);
var docs = factory.Documents?.VisibleDockables; CloseTabsWhere(doc => !ReferenceEquals(doc, keep));
if (docs == null)
return;
foreach (var doc in docs.OfType<ContentTabPage>().ToArray())
{
if (!ReferenceEquals(doc, keep))
CloseTab(doc);
}
} }
/// <summary>Closes the active document tab (Ctrl+W). The documents dock only holds /// <summary>Closes the active document tab (Ctrl+W). The documents dock only holds

Loading…
Cancel
Save