fix(docking): improve DockGroup robustness and state preservation
This commit is contained in:
@@ -4,10 +4,10 @@ using Microsoft.UI.Xaml.Data;
|
|||||||
|
|
||||||
namespace Ghost.Editor.View.Controls.Docking;
|
namespace Ghost.Editor.View.Controls.Docking;
|
||||||
|
|
||||||
[TemplatePart(Name = PART_TabView, Type = typeof(TabView))]
|
[TemplatePart(Name = PART_TAB_VIEW, Type = typeof(TabView))]
|
||||||
public partial class DockGroup : DockContainer
|
public partial class DockGroup : DockContainer
|
||||||
{
|
{
|
||||||
private const string PART_TabView = "PART_TabView";
|
private const string PART_TAB_VIEW = "PART_TabView";
|
||||||
private TabView? _tabView;
|
private TabView? _tabView;
|
||||||
|
|
||||||
public DockGroup()
|
public DockGroup()
|
||||||
@@ -17,6 +17,8 @@ public partial class DockGroup : DockContainer
|
|||||||
|
|
||||||
public override void AddChild(DockModule module)
|
public override void AddChild(DockModule module)
|
||||||
{
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(module);
|
||||||
|
|
||||||
if (module is not DockDocument)
|
if (module is not DockDocument)
|
||||||
{
|
{
|
||||||
throw new ArgumentException($"{nameof(DockGroup)} only accepts {nameof(DockDocument)} children.", nameof(module));
|
throw new ArgumentException($"{nameof(DockGroup)} only accepts {nameof(DockDocument)} children.", nameof(module));
|
||||||
@@ -28,7 +30,7 @@ public partial class DockGroup : DockContainer
|
|||||||
protected override void OnApplyTemplate()
|
protected override void OnApplyTemplate()
|
||||||
{
|
{
|
||||||
base.OnApplyTemplate();
|
base.OnApplyTemplate();
|
||||||
_tabView = GetTemplateChild(PART_TabView) as TabView;
|
_tabView = GetTemplateChild(PART_TAB_VIEW) as TabView;
|
||||||
UpdateTabs();
|
UpdateTabs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +43,11 @@ public partial class DockGroup : DockContainer
|
|||||||
{
|
{
|
||||||
if (_tabView == null) return;
|
if (_tabView == null) return;
|
||||||
|
|
||||||
|
var selectedDoc = _tabView.SelectedItem is TabViewItem selectedItem ? selectedItem.Tag as DockDocument : null;
|
||||||
|
|
||||||
_tabView.TabItems.Clear();
|
_tabView.TabItems.Clear();
|
||||||
|
TabViewItem? newSelectedItem = null;
|
||||||
|
|
||||||
foreach (var child in Children)
|
foreach (var child in Children)
|
||||||
{
|
{
|
||||||
if (child is DockDocument doc)
|
if (child is DockDocument doc)
|
||||||
@@ -66,7 +72,17 @@ public partial class DockGroup : DockContainer
|
|||||||
});
|
});
|
||||||
|
|
||||||
_tabView.TabItems.Add(tabItem);
|
_tabView.TabItems.Add(tabItem);
|
||||||
|
|
||||||
|
if (doc == selectedDoc)
|
||||||
|
{
|
||||||
|
newSelectedItem = tabItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (newSelectedItem != null)
|
||||||
|
{
|
||||||
|
_tabView.SelectedItem = newSelectedItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
<Grid>
|
<Grid>
|
||||||
<TabView x:Name="PART_TabView"
|
<TabView x:Name="PART_TabView"
|
||||||
IsAddTabButtonVisible="False"
|
IsAddTabButtonVisible="False"
|
||||||
CanDragTabs="True"
|
CanDragTabs="False"
|
||||||
CanReorderTabs="True"
|
CanReorderTabs="False"
|
||||||
AllowDrop="True">
|
AllowDrop="True">
|
||||||
</TabView>
|
</TabView>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
Reference in New Issue
Block a user