Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions samples/DockControlPanelsSample/MainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<Factory />
</DockControl.Factory>

<RootDock Id="ProportionalRoot" IsCollapsable="False" ActiveDockable="ProportionalMain">
<RootDock Id="ProportionalRoot" IsCollapsable="False">
<ProportionalDock x:Name="ProportionalMain" Id="ProportionalMain" Orientation="Horizontal">

<!-- Left Tool -->
Expand Down Expand Up @@ -68,7 +68,7 @@
<Factory />
</DockControl.Factory>

<RootDock Id="StackRoot" IsCollapsable="False" ActiveDockable="StackMain">
<RootDock Id="StackRoot" IsCollapsable="False">
<StackDock x:Name="StackMain" Id="StackMain" Orientation="Horizontal" Spacing="5">

<ToolDock Id="StackTool1" Alignment="Unset">
Expand Down Expand Up @@ -107,7 +107,7 @@
<Factory />
</DockControl.Factory>

<RootDock Id="GridRoot" IsCollapsable="False" ActiveDockable="GridMain">
<RootDock Id="GridRoot" IsCollapsable="False">
<GridDock x:Name="GridMain" Id="GridMain" ColumnDefinitions="*,Auto,2*,Auto,*" RowDefinitions="Auto,*">

<!-- Top row toolbar -->
Expand Down Expand Up @@ -159,7 +159,7 @@
<Factory />
</DockControl.Factory>

<RootDock Id="WrapRoot" IsCollapsable="False" ActiveDockable="WrapMain">
<RootDock Id="WrapRoot" IsCollapsable="False">
<WrapDock x:Name="WrapMain" Id="WrapMain" Orientation="Horizontal">

<ToolDock Id="WrapTool1" Alignment="Unset">
Expand Down Expand Up @@ -210,7 +210,7 @@
<Factory />
</DockControl.Factory>

<RootDock Id="UniformRoot" IsCollapsable="False" ActiveDockable="UniformMain">
<RootDock Id="UniformRoot" IsCollapsable="False">
<UniformGridDock x:Name="UniformMain" Id="UniformMain" Rows="2" Columns="3">

<ToolDock Id="UniformTool1" Alignment="Unset">
Expand Down Expand Up @@ -261,7 +261,7 @@
<Factory />
</DockControl.Factory>

<RootDock Id="DockRoot" IsCollapsable="False" ActiveDockable="DockMain">
<RootDock Id="DockRoot" IsCollapsable="False">
<DockDock x:Name="DockMain" Id="DockMain" LastChildFill="True">

<!-- Top toolbar -->
Expand Down
2 changes: 1 addition & 1 deletion src/Dock.Model/Controls/IGridDockSplitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Dock.Model.Controls;
/// Grid splitter dock contract.
/// </summary>
[RequiresDataTemplate]
public interface IGridDockSplitter : IDockable
public interface IGridDockSplitter : ISplitter
{
/// <summary>
/// Gets or sets resize direction.
Expand Down
2 changes: 1 addition & 1 deletion src/Dock.Model/Controls/IProportionalDockSplitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Dock.Model.Controls;
/// Proportional dock splitter contract.
/// </summary>
[RequiresDataTemplate]
public interface IProportionalDockSplitter : IDockable
public interface IProportionalDockSplitter : ISplitter
{
/// <summary>
/// Gets or sets whether the splitter allows resizing.
Expand Down
12 changes: 12 additions & 0 deletions src/Dock.Model/Controls/ISplitter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Wiesław Šoltés. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.
using Dock.Model.Core;

namespace Dock.Model.Controls;

/// <summary>
/// Splitter contract.
/// </summary>
public interface ISplitter : IDockable
{
}
18 changes: 9 additions & 9 deletions src/Dock.Model/FactoryBase.Dockable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public virtual void RemoveDockable(IDockable dockable, bool collapse)
if (dock.VisibleDockables.Count > 0)
{
var nextActiveDockable = dock.VisibleDockables[indexActiveDockable];
dock.ActiveDockable = nextActiveDockable is not IProportionalDockSplitter ? nextActiveDockable : null;
dock.ActiveDockable = nextActiveDockable is not ISplitter ? nextActiveDockable : null;
}
else
{
Expand Down Expand Up @@ -98,21 +98,21 @@ protected void CleanupOrphanedSplitters(IDock dock)
var dockables = dock.VisibleDockables.ToList();

// If we only have splitters, remove all of them
if (dockables.Count > 0 && dockables.All(d => d is IProportionalDockSplitter))
if (dockables.Count > 0 && dockables.All(d => d is ISplitter))
{
toRemove.AddRange(dockables);
}
else
{
// Remove splitters that are at the beginning
while (dockables.Count > 0 && dockables[0] is IProportionalDockSplitter)
while (dockables.Count > 0 && dockables[0] is ISplitter)
{
toRemove.Add(dockables[0]);
dockables.RemoveAt(0);
}

// Remove splitters that are at the end
while (dockables.Count > 0 && dockables[dockables.Count - 1] is IProportionalDockSplitter)
while (dockables.Count > 0 && dockables[dockables.Count - 1] is ISplitter)
{
toRemove.Add(dockables[dockables.Count - 1]);
dockables.RemoveAt(dockables.Count - 1);
Expand All @@ -121,11 +121,11 @@ protected void CleanupOrphanedSplitters(IDock dock)
// Remove consecutive splitters - keep only the first one in each sequence
for (int i = 0; i < dockables.Count - 1; i++)
{
if (dockables[i] is IProportionalDockSplitter)
if (dockables[i] is ISplitter)
{
// Remove all consecutive splitters after this one
int j = i + 1;
while (j < dockables.Count && dockables[j] is IProportionalDockSplitter)
while (j < dockables.Count && dockables[j] is ISplitter)
{
toRemove.Add(dockables[j]);
j++;
Expand All @@ -147,10 +147,10 @@ protected void CleanupOrphanedSplitters(IDock dock)
}

// Update active dockable if it was a splitter that got removed
if (dock.ActiveDockable is IProportionalDockSplitter ||
if (dock.ActiveDockable is ISplitter ||
(dock.ActiveDockable is not null && !dock.VisibleDockables.Contains(dock.ActiveDockable)))
{
dock.ActiveDockable = dock.VisibleDockables?.FirstOrDefault(d => d is not IProportionalDockSplitter);
dock.ActiveDockable = dock.VisibleDockables?.FirstOrDefault(d => d is not ISplitter);
}
}

Expand Down Expand Up @@ -1254,7 +1254,7 @@ private void UpdateIsEmpty(IDock dock)

var newIsEmpty = dock.VisibleDockables == null
|| dock.VisibleDockables?.Count == 0
|| dock.VisibleDockables!.All(x => x is IDock { IsEmpty: true, IsCollapsable: true } or IProportionalDockSplitter);
|| dock.VisibleDockables!.All(x => x is IDock { IsEmpty: true, IsCollapsable: true } or ISplitter);

if (oldIsEmpty != newIsEmpty)
{
Expand Down
48 changes: 48 additions & 0 deletions src/Dock.Model/FactoryBase.Init.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,19 @@ public virtual void InitLayout(IDockable layout)
}
}

// Auto-set ActiveDockable for RootDock if not already set
if (layout is IRootDock rootDock)
{
if (rootDock.ActiveDockable is null && rootDock.VisibleDockables is not null)
{
// Find first visible dockable that is not a splitter
var firstVisible = FindFirstVisibleDockable(rootDock);
if (firstVisible is not null)
{
rootDock.ActiveDockable = firstVisible;
}
}

if (rootDock.ShowWindows.CanExecute(null))
{
rootDock.ShowWindows.Execute(null);
Expand Down Expand Up @@ -108,6 +119,43 @@ public virtual void InitDockable(IDockable dockable, IDockable? owner)
OnDockableInit(dockable);
}

/// <summary>
/// Finds the first visible dockable in the hierarchy that is not a splitter.
/// </summary>
/// <param name="dock">The dock to search in.</param>
/// <returns>The first visible dockable or null if none found.</returns>
private IDockable? FindFirstVisibleDockable(IDock dock)
{
if (dock.VisibleDockables is null)
{
return null;
}

// First look for direct visible dockables that are not splitters
foreach (var dockable in dock.VisibleDockables)
{
if (dockable is not ISplitter)
{
return dockable;
}
}

// If no direct dockables found, recursively search in child docks
foreach (var dockable in dock.VisibleDockables)
{
if (dockable is IDock childDock)
{
var result = FindFirstVisibleDockable(childDock);
if (result is not null)
{
return result;
}
}
}

return null;
}

private void InitDockables(IDockable dockable, IList<IDockable> dockables)
{
foreach (var child in dockables)
Expand Down
Loading