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 Canvas? _overlayCanvas;
|
||||||
private DockRegionHighlight? _highlight;
|
private DockRegionHighlight? _highlight;
|
||||||
|
private readonly List<FloatingWindow> _floatingWindows = new();
|
||||||
|
|
||||||
public DockingLayout()
|
public DockingLayout()
|
||||||
{
|
{
|
||||||
@@ -113,16 +114,36 @@ public class DockingLayout : Control
|
|||||||
private void SplitGroup(DockGroup targetGroup, DockDocument doc, DockTarget target)
|
private void SplitGroup(DockGroup targetGroup, DockDocument doc, DockTarget target)
|
||||||
{
|
{
|
||||||
var parentPanel = targetGroup.Owner as DockPanel;
|
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();
|
var newGroup = new DockGroup();
|
||||||
newGroup.AddChild(doc);
|
newGroup.AddChild(doc);
|
||||||
|
|
||||||
var orientation = (target == DockTarget.Left || target == DockTarget.Right) ? Orientation.Horizontal : Orientation.Vertical;
|
var orientation = (target == DockTarget.Left || target == DockTarget.Right) ? Orientation.Horizontal : Orientation.Vertical;
|
||||||
|
|
||||||
if (parentPanel == null)
|
int index = parentPanel.Children.IndexOf(targetGroup);
|
||||||
|
|
||||||
|
if (parentPanel.Orientation == orientation)
|
||||||
{
|
{
|
||||||
// targetGroup is the root
|
// Same orientation, just insert
|
||||||
|
if (target == DockTarget.Left || target == DockTarget.Top)
|
||||||
|
{
|
||||||
|
parentPanel.InsertChild(index, newGroup);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
parentPanel.InsertChild(index + 1, newGroup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Different orientation, need a new sub-panel
|
||||||
var newPanel = new DockPanel { Orientation = orientation };
|
var newPanel = new DockPanel { Orientation = orientation };
|
||||||
RootPanel = newPanel;
|
parentPanel.ReplaceChild(targetGroup, newPanel);
|
||||||
|
|
||||||
if (target == DockTarget.Left || target == DockTarget.Top)
|
if (target == DockTarget.Left || target == DockTarget.Top)
|
||||||
{
|
{
|
||||||
@@ -135,40 +156,6 @@ public class DockingLayout : Control
|
|||||||
newPanel.AddChild(newGroup);
|
newPanel.AddChild(newGroup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
int index = parentPanel.Children.IndexOf(targetGroup);
|
|
||||||
|
|
||||||
if (parentPanel.Orientation == orientation)
|
|
||||||
{
|
|
||||||
// Same orientation, just insert
|
|
||||||
if (target == DockTarget.Left || target == DockTarget.Top)
|
|
||||||
{
|
|
||||||
parentPanel.InsertChild(index, newGroup);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
parentPanel.InsertChild(index + 1, newGroup);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Different orientation, need a new sub-panel
|
|
||||||
var newPanel = new DockPanel { Orientation = orientation };
|
|
||||||
parentPanel.ReplaceChild(targetGroup, newPanel);
|
|
||||||
|
|
||||||
if (target == DockTarget.Left || target == DockTarget.Top)
|
|
||||||
{
|
|
||||||
newPanel.AddChild(newGroup);
|
|
||||||
newPanel.AddChild(targetGroup);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
newPanel.AddChild(targetGroup);
|
|
||||||
newPanel.AddChild(newGroup);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DockGroup? FindFirstDockGroup(DockContainer container)
|
private static DockGroup? FindFirstDockGroup(DockContainer container)
|
||||||
@@ -262,6 +249,8 @@ public class DockingLayout : Control
|
|||||||
internal void CreateFloatingWindow(DockDocument doc)
|
internal void CreateFloatingWindow(DockDocument doc)
|
||||||
{
|
{
|
||||||
var window = new FloatingWindow(doc);
|
var window = new FloatingWindow(doc);
|
||||||
|
_floatingWindows.Add(window);
|
||||||
|
window.Closed += (s, e) => _floatingWindows.Remove(window);
|
||||||
window.Activate();
|
window.Activate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,19 @@ using Microsoft.UI.Xaml;
|
|||||||
|
|
||||||
namespace Ghost.Editor.View.Controls.Docking;
|
namespace Ghost.Editor.View.Controls.Docking;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A floating window that contains a docking layout.
|
||||||
|
/// </summary>
|
||||||
public class FloatingWindow : Window
|
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)
|
public FloatingWindow(DockDocument document)
|
||||||
{
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(document);
|
||||||
|
|
||||||
var layout = new DockingLayout();
|
var layout = new DockingLayout();
|
||||||
var group = new DockGroup();
|
var group = new DockGroup();
|
||||||
group.AddChild(document);
|
group.AddChild(document);
|
||||||
|
|||||||
Reference in New Issue
Block a user