fix(docking): address code quality issues in DockingLayout and FloatingWindow
This commit is contained in:
@@ -30,6 +30,7 @@ public class DockingLayout : Control
|
||||
|
||||
private Canvas? _overlayCanvas;
|
||||
private DockRegionHighlight? _highlight;
|
||||
private readonly List<FloatingWindow> _floatingWindows = new();
|
||||
|
||||
public DockingLayout()
|
||||
{
|
||||
@@ -113,30 +114,17 @@ public class DockingLayout : Control
|
||||
private void SplitGroup(DockGroup targetGroup, DockDocument doc, DockTarget target)
|
||||
{
|
||||
var parentPanel = targetGroup.Owner as DockPanel;
|
||||
|
||||
if (parentPanel == null)
|
||||
{
|
||||
throw new InvalidOperationException("targetGroup must be owned by a DockPanel to be split.");
|
||||
}
|
||||
|
||||
var newGroup = new DockGroup();
|
||||
newGroup.AddChild(doc);
|
||||
|
||||
var orientation = (target == DockTarget.Left || target == DockTarget.Right) ? Orientation.Horizontal : Orientation.Vertical;
|
||||
|
||||
if (parentPanel == null)
|
||||
{
|
||||
// targetGroup is the root
|
||||
var newPanel = new DockPanel { Orientation = orientation };
|
||||
RootPanel = newPanel;
|
||||
|
||||
if (target == DockTarget.Left || target == DockTarget.Top)
|
||||
{
|
||||
newPanel.AddChild(newGroup);
|
||||
newPanel.AddChild(targetGroup);
|
||||
}
|
||||
else
|
||||
{
|
||||
newPanel.AddChild(targetGroup);
|
||||
newPanel.AddChild(newGroup);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int index = parentPanel.Children.IndexOf(targetGroup);
|
||||
|
||||
if (parentPanel.Orientation == orientation)
|
||||
@@ -169,7 +157,6 @@ public class DockingLayout : Control
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static DockGroup? FindFirstDockGroup(DockContainer container)
|
||||
{
|
||||
@@ -262,6 +249,8 @@ public class DockingLayout : Control
|
||||
internal void CreateFloatingWindow(DockDocument doc)
|
||||
{
|
||||
var window = new FloatingWindow(doc);
|
||||
_floatingWindows.Add(window);
|
||||
window.Closed += (s, e) => _floatingWindows.Remove(window);
|
||||
window.Activate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,19 @@ using Microsoft.UI.Xaml;
|
||||
|
||||
namespace Ghost.Editor.View.Controls.Docking;
|
||||
|
||||
/// <summary>
|
||||
/// A floating window that contains a docking layout.
|
||||
/// </summary>
|
||||
public class FloatingWindow : Window
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FloatingWindow"/> class with the specified document.
|
||||
/// </summary>
|
||||
/// <param name="document">The document to display in the floating window.</param>
|
||||
public FloatingWindow(DockDocument document)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(document);
|
||||
|
||||
var layout = new DockingLayout();
|
||||
var group = new DockGroup();
|
||||
group.AddChild(document);
|
||||
|
||||
Reference in New Issue
Block a user