Browse Source

Pair dockable activation and focus in ActivateAndFocus

SetActiveDockable + SetFocusedDockable were always called together at five
sites across the factory and the workspace. Fold the pair into one
factory method so the invariant (a surfaced dockable is also focused) is
expressed once; the per-site "add to the dock first" step, which varies
(unconditional / only-if-absent / none), stays at the call site.

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

9
ILSpy/Docking/DockWorkspace.cs

@ -1137,8 +1137,7 @@ namespace ILSpy.Docking
if (factory.Documents != null) if (factory.Documents != null)
{ {
factory.AddDockable(factory.Documents, tab); factory.AddDockable(factory.Documents, tab);
factory.SetActiveDockable(tab); factory.ActivateAndFocus(factory.Documents, tab);
factory.SetFocusedDockable(factory.Documents, tab);
} }
return tab; return tab;
} }
@ -1169,8 +1168,7 @@ namespace ILSpy.Docking
return; return;
if (docs.VisibleDockables?.Contains(tab) != true) if (docs.VisibleDockables?.Contains(tab) != true)
factory.AddDockable(docs, tab); factory.AddDockable(docs, tab);
factory.SetActiveDockable(tab); factory.ActivateAndFocus(docs, tab);
factory.SetFocusedDockable(docs, tab);
} }
/// <summary> /// <summary>
@ -1221,8 +1219,7 @@ namespace ILSpy.Docking
{ {
if (docs.VisibleDockables?.Contains(main) != true) if (docs.VisibleDockables?.Contains(main) != true)
return false; return false;
factory.SetActiveDockable(main); factory.ActivateAndFocus(docs, main);
factory.SetFocusedDockable(docs, main);
} }
return true; return true;
} }

18
ILSpy/Docking/ILSpyDockFactory.cs

@ -460,6 +460,18 @@ namespace ILSpy.Docking
_ => ("BottomTools", Alignment.Bottom, 0.2), _ => ("BottomTools", Alignment.Bottom, 0.2),
}; };
/// <summary>
/// Makes <paramref name="dockable"/> both the active and the focused dockable within
/// <paramref name="owner"/>. The two always go together -- surfacing a dockable without
/// focusing it (or vice versa) is a half-done activation -- so they're paired here and
/// callers do the (varying) "add it to the dock first" step themselves.
/// </summary>
public void ActivateAndFocus(IDock owner, IDockable dockable)
{
SetActiveDockable(dockable);
SetFocusedDockable(owner, dockable);
}
/// <summary> /// <summary>
/// Brings a tool pane into view: activates it if it is already shown, otherwise /// Brings a tool pane into view: activates it if it is already shown, otherwise
/// materialises it -- (re)creating its home <see cref="ToolDock"/> at the pane's /// materialises it -- (re)creating its home <see cref="ToolDock"/> at the pane's
@ -477,8 +489,7 @@ namespace ILSpy.Docking
// Already live in the layout -> just activate it where it sits. // Already live in the layout -> just activate it where it sits.
if (pane.Owner is IDock current && current.VisibleDockables?.Contains(pane) == true) if (pane.Owner is IDock current && current.VisibleDockables?.Contains(pane) == true)
{ {
SetActiveDockable(pane); ActivateAndFocus(current, pane);
SetFocusedDockable(current, pane);
return pane; return pane;
} }
@ -486,8 +497,7 @@ namespace ILSpy.Docking
if (dock is null) if (dock is null)
return pane; return pane;
AddDockable(dock, pane); AddDockable(dock, pane);
SetActiveDockable(pane); ActivateAndFocus(dock, pane);
SetFocusedDockable(dock, pane);
return pane; return pane;
} }

Loading…
Cancel
Save