fix(docking): address code quality issues in DockingLayout and DockRegionHighlight
This commit is contained in:
@@ -5,8 +5,11 @@ namespace Ghost.Editor.View.Controls.Docking;
|
|||||||
public abstract class DockModule : Control
|
public abstract class DockModule : Control
|
||||||
{
|
{
|
||||||
public DockContainer? Owner { get; internal set; }
|
public DockContainer? Owner { get; internal set; }
|
||||||
// Note: DockingLayout will be implemented in a later task
|
|
||||||
// public DockingLayout? Root { get; internal set; }
|
/// <summary>
|
||||||
|
/// Gets or sets the root docking layout this module belongs to.
|
||||||
|
/// </summary>
|
||||||
|
public DockingLayout? Root { get; internal set; }
|
||||||
|
|
||||||
public void Detach()
|
public void Detach()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ using CommunityToolkit.WinUI.Controls;
|
|||||||
|
|
||||||
namespace Ghost.Editor.View.Controls.Docking;
|
namespace Ghost.Editor.View.Controls.Docking;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A container that can host multiple dock modules with splitters.
|
||||||
|
/// </summary>
|
||||||
[TemplatePart(Name = PART_GRID, Type = typeof(Grid))]
|
[TemplatePart(Name = PART_GRID, Type = typeof(Grid))]
|
||||||
public class DockPanel : DockContainer
|
public class DockPanel : DockContainer
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ using Microsoft.UI.Xaml.Controls;
|
|||||||
|
|
||||||
namespace Ghost.Editor.View.Controls.Docking;
|
namespace Ghost.Editor.View.Controls.Docking;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a visual highlight for a docking region.
|
||||||
|
/// </summary>
|
||||||
public class DockRegionHighlight : Control
|
public class DockRegionHighlight : Control
|
||||||
{
|
{
|
||||||
public DockRegionHighlight()
|
public DockRegionHighlight()
|
||||||
|
|||||||
@@ -3,13 +3,25 @@ using Microsoft.UI.Xaml.Controls;
|
|||||||
|
|
||||||
namespace Ghost.Editor.View.Controls.Docking;
|
namespace Ghost.Editor.View.Controls.Docking;
|
||||||
|
|
||||||
[TemplatePart(Name = "PART_OverlayCanvas", Type = typeof(Canvas))]
|
/// <summary>
|
||||||
[TemplatePart(Name = "PART_Highlight", Type = typeof(DockRegionHighlight))]
|
/// The root control for the docking system layout.
|
||||||
|
/// </summary>
|
||||||
|
[TemplatePart(Name = PART_OVERLAY_CANVAS, Type = typeof(Canvas))]
|
||||||
|
[TemplatePart(Name = PART_HIGHLIGHT, Type = typeof(DockRegionHighlight))]
|
||||||
public class DockingLayout : Control
|
public class DockingLayout : Control
|
||||||
{
|
{
|
||||||
|
private const string PART_OVERLAY_CANVAS = "PART_OverlayCanvas";
|
||||||
|
private const string PART_HIGHLIGHT = "PART_Highlight";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the root panel of the docking layout.
|
||||||
|
/// </summary>
|
||||||
public static readonly DependencyProperty RootPanelProperty = DependencyProperty.Register(
|
public static readonly DependencyProperty RootPanelProperty = DependencyProperty.Register(
|
||||||
nameof(RootPanel), typeof(DockPanel), typeof(DockingLayout), new PropertyMetadata(null, OnRootPanelChanged));
|
nameof(RootPanel), typeof(DockPanel), typeof(DockingLayout), new PropertyMetadata(null, OnRootPanelChanged));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the root panel of the docking layout.
|
||||||
|
/// </summary>
|
||||||
public DockPanel? RootPanel
|
public DockPanel? RootPanel
|
||||||
{
|
{
|
||||||
get => (DockPanel?)GetValue(RootPanelProperty);
|
get => (DockPanel?)GetValue(RootPanelProperty);
|
||||||
@@ -29,8 +41,8 @@ public class DockingLayout : Control
|
|||||||
protected override void OnApplyTemplate()
|
protected override void OnApplyTemplate()
|
||||||
{
|
{
|
||||||
base.OnApplyTemplate();
|
base.OnApplyTemplate();
|
||||||
_overlayCanvas = GetTemplateChild("PART_OverlayCanvas") as Canvas;
|
_overlayCanvas = GetTemplateChild(PART_OVERLAY_CANVAS) as Canvas;
|
||||||
_highlight = GetTemplateChild("PART_Highlight") as DockRegionHighlight;
|
_highlight = GetTemplateChild(PART_HIGHLIGHT) as DockRegionHighlight;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void OnRootPanelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
private static void OnRootPanelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||||
@@ -49,6 +61,12 @@ public class DockingLayout : Control
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a document to the docking layout.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="document">The document to add.</param>
|
||||||
|
/// <param name="target">The docking target position.</param>
|
||||||
|
/// <param name="targetGroup">The target group to add the document to. If null, a suitable group will be found or created.</param>
|
||||||
public void AddDocument(DockDocument document, DockTarget target, DockGroup? targetGroup = null)
|
public void AddDocument(DockDocument document, DockTarget target, DockGroup? targetGroup = null)
|
||||||
{
|
{
|
||||||
if (target != DockTarget.Center)
|
if (target != DockTarget.Center)
|
||||||
@@ -63,30 +81,37 @@ public class DockingLayout : Control
|
|||||||
|
|
||||||
if (targetGroup == null)
|
if (targetGroup == null)
|
||||||
{
|
{
|
||||||
if (RootPanel.Children.Count == 0)
|
targetGroup = FindFirstLeafDockGroup(RootPanel);
|
||||||
{
|
|
||||||
var group = new DockGroup();
|
|
||||||
group.AddChild(document);
|
|
||||||
RootPanel.AddChild(group);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (RootPanel.Children[0] is DockGroup existingGroup)
|
if (targetGroup == null)
|
||||||
{
|
{
|
||||||
targetGroup = existingGroup;
|
targetGroup = new DockGroup();
|
||||||
}
|
RootPanel.AddChild(targetGroup);
|
||||||
else
|
|
||||||
{
|
|
||||||
var group = new DockGroup();
|
|
||||||
group.AddChild(document);
|
|
||||||
RootPanel.AddChild(group);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetGroup != null)
|
targetGroup.AddChild(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DockGroup? FindFirstLeafDockGroup(DockContainer container)
|
||||||
|
{
|
||||||
|
if (container is DockGroup group)
|
||||||
{
|
{
|
||||||
targetGroup.AddChild(document);
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (var child in container.Children)
|
||||||
|
{
|
||||||
|
if (child is DockContainer childContainer)
|
||||||
|
{
|
||||||
|
var result = FindFirstLeafDockGroup(childContainer);
|
||||||
|
if (result != null)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user