diff --git a/src/Editor/Ghost.Editor/Ghost.Editor.csproj b/src/Editor/Ghost.Editor/Ghost.Editor.csproj index 6a908f6..c59202d 100644 --- a/src/Editor/Ghost.Editor/Ghost.Editor.csproj +++ b/src/Editor/Ghost.Editor/Ghost.Editor.csproj @@ -36,6 +36,7 @@ + diff --git a/src/Editor/Ghost.Editor/View/Controls/Docking/DockContainer.cs b/src/Editor/Ghost.Editor/View/Controls/Docking/DockContainer.cs index 2329ad3..b616121 100644 --- a/src/Editor/Ghost.Editor/View/Controls/Docking/DockContainer.cs +++ b/src/Editor/Ghost.Editor/View/Controls/Docking/DockContainer.cs @@ -9,6 +9,9 @@ namespace Ghost.Editor.View.Controls.Docking; public abstract class DockContainer : DockModule { private readonly ObservableCollection _children = new(); + /// + /// Gets the collection of child modules. + /// public ReadOnlyObservableCollection Children { get; } protected DockContainer() @@ -22,15 +25,27 @@ public abstract class DockContainer : DockModule OnChildrenUpdated(); } + /// + /// Adds a child module to the end of the container. + /// + /// The module to add. public virtual void AddChild(DockModule module) { InsertChild(_children.Count, module); } + /// + /// Inserts a child module at the specified index. + /// + /// The zero-based index at which the module should be inserted. + /// The module to insert. public virtual void InsertChild(int index, DockModule module) { ArgumentNullException.ThrowIfNull(module); + if (index < 0 || index > _children.Count) + throw new ArgumentOutOfRangeException(nameof(index)); + if (module == this) throw new ArgumentException("Cannot add a container to itself.", nameof(module)); @@ -54,6 +69,10 @@ public abstract class DockContainer : DockModule _children.Insert(index, module); } + /// + /// Removes a child module from the container. + /// + /// The module to remove. public virtual void RemoveChild(DockModule module) { ArgumentNullException.ThrowIfNull(module); @@ -74,6 +93,9 @@ public abstract class DockContainer : DockModule } } + /// + /// Removes all child modules from the container. + /// public void Clear() { foreach (var child in _children) diff --git a/src/Editor/Ghost.Editor/View/Controls/Docking/DockDocument.cs b/src/Editor/Ghost.Editor/View/Controls/Docking/DockDocument.cs index 9454c2e..68ee5c9 100644 --- a/src/Editor/Ghost.Editor/View/Controls/Docking/DockDocument.cs +++ b/src/Editor/Ghost.Editor/View/Controls/Docking/DockDocument.cs @@ -11,12 +11,18 @@ public partial class DockDocument : DockModule public static readonly DependencyProperty ContentProperty = DependencyProperty.Register( nameof(Content), typeof(object), typeof(DockDocument), new PropertyMetadata(null)); + /// + /// Gets or sets the title of the document. + /// public string? Title { get => (string?)GetValue(TitleProperty); set => SetValue(TitleProperty, value); } + /// + /// Gets or sets the content of the document. + /// public object? Content { get => GetValue(ContentProperty); diff --git a/src/Editor/Ghost.Editor/View/Controls/Docking/DockGroup.cs b/src/Editor/Ghost.Editor/View/Controls/Docking/DockGroup.cs index 90fd4da..d2a32bd 100644 --- a/src/Editor/Ghost.Editor/View/Controls/Docking/DockGroup.cs +++ b/src/Editor/Ghost.Editor/View/Controls/Docking/DockGroup.cs @@ -157,5 +157,9 @@ public partial class DockGroup : DockContainer { _tabView.SelectedItem = newSelectedItem; } + else + { + _tabView.SelectedItem = _tabView.TabItems.FirstOrDefault(); + } } } diff --git a/src/Editor/Ghost.Editor/View/Controls/Docking/DockModule.cs b/src/Editor/Ghost.Editor/View/Controls/Docking/DockModule.cs index f0a6631..34ddfef 100644 --- a/src/Editor/Ghost.Editor/View/Controls/Docking/DockModule.cs +++ b/src/Editor/Ghost.Editor/View/Controls/Docking/DockModule.cs @@ -7,6 +7,9 @@ namespace Ghost.Editor.View.Controls.Docking; /// public abstract class DockModule : Control { + /// + /// Gets the container that owns this module. + /// public DockContainer? Owner { get; internal set; } private DockingLayout? _root; @@ -29,6 +32,9 @@ public abstract class DockModule : Control protected virtual void OnRootChanged() { } + /// + /// Detaches this module from its current owner. + /// public void Detach() { Owner?.RemoveChild(this); diff --git a/src/Editor/Ghost.Editor/View/Controls/Docking/DockPanel.cs b/src/Editor/Ghost.Editor/View/Controls/Docking/DockPanel.cs index dd573a6..4f15ada 100644 --- a/src/Editor/Ghost.Editor/View/Controls/Docking/DockPanel.cs +++ b/src/Editor/Ghost.Editor/View/Controls/Docking/DockPanel.cs @@ -16,6 +16,9 @@ public class DockPanel : DockContainer public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register( nameof(Orientation), typeof(Orientation), typeof(DockPanel), new PropertyMetadata(Orientation.Horizontal, OnOrientationChanged)); + /// + /// Gets or sets the orientation of the panel. + /// public Orientation Orientation { get => (Orientation)GetValue(OrientationProperty); @@ -89,7 +92,7 @@ public class DockPanel : DockContainer if (i < Children.Count - 1) { _grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); - var splitter = new CommunityToolkit.WinUI.Controls.GridSplitter { ResizeDirection = CommunityToolkit.WinUI.Controls.GridSplitter.GridResizeDirection.Columns, Width = SPLITTER_THICKNESS }; + var splitter = new GridSplitter { ResizeDirection = GridSplitter.GridResizeDirection.Columns, Width = SPLITTER_THICKNESS }; Grid.SetColumn(splitter, i * 2 + 1); _grid.Children.Add(splitter); } @@ -107,7 +110,7 @@ public class DockPanel : DockContainer if (i < Children.Count - 1) { _grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); - var splitter = new CommunityToolkit.WinUI.Controls.GridSplitter { ResizeDirection = CommunityToolkit.WinUI.Controls.GridSplitter.GridResizeDirection.Rows, Height = SPLITTER_THICKNESS }; + var splitter = new GridSplitter { ResizeDirection = GridSplitter.GridResizeDirection.Rows, Height = SPLITTER_THICKNESS }; Grid.SetRow(splitter, i * 2 + 1); _grid.Children.Add(splitter); } diff --git a/src/Editor/Ghost.Editor/View/Controls/Docking/DockingLayout.cs b/src/Editor/Ghost.Editor/View/Controls/Docking/DockingLayout.cs index 4e1f2e1..f41cfe7 100644 --- a/src/Editor/Ghost.Editor/View/Controls/Docking/DockingLayout.cs +++ b/src/Editor/Ghost.Editor/View/Controls/Docking/DockingLayout.cs @@ -147,8 +147,8 @@ public class DockingLayout : Control else { // Different orientation, need a new sub-panel - targetGroup.Detach(); var newPanel = new DockPanel { Orientation = orientation }; + parentPanel.InsertChild(index, newPanel); if (target == DockTarget.Left || target == DockTarget.Top) { @@ -160,8 +160,6 @@ public class DockingLayout : Control newPanel.AddChild(targetGroup); newPanel.AddChild(newGroup); } - - parentPanel.InsertChild(index, newPanel); } } } @@ -228,10 +226,9 @@ public class DockingLayout : Control HideHighlight(); var target = CalculateDockTarget(targetGroup, position); - doc.Detach(); - if (target == DockTarget.Center) { + if (doc.Owner == targetGroup) return; targetGroup.AddChild(doc); } else @@ -256,7 +253,6 @@ public class DockingLayout : Control internal void CreateFloatingWindow(DockDocument doc) { - doc.Detach(); // To be implemented in Task 6 } }