Skip to content

Commit

Permalink
Fix unwanted group orientation change when using mixed orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Zwart authored and Roy Zwart committed Mar 17, 2023
1 parent 58ec136 commit a48e689
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions source/Components/AvalonDock/Controls/DocumentPaneDropTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,42 @@ internal DocumentPaneDropTarget(LayoutDocumentPaneControl paneControl,
/// <param name="floatingWindow"></param>
protected override void Drop(LayoutDocumentFloatingWindow floatingWindow)
{
ILayoutDocumentPane targetModel = _targetPane.Model as ILayoutDocumentPane;
LayoutDocument documentActive = floatingWindow.Descendents().OfType<LayoutDocument>().FirstOrDefault();
var targetModel = (ILayoutDocumentPane)_targetPane.Model;
var documentActive = floatingWindow.Descendents().OfType<LayoutDocument>().FirstOrDefault();

// ensure paneGroup
var paneGroup = targetModel.Parent as LayoutDocumentPaneGroup;
var requiredOrientation = Type == DropTargetType.DocumentPaneDockBottom || Type == DropTargetType.DocumentPaneDockTop ?
System.Windows.Controls.Orientation.Vertical : System.Windows.Controls.Orientation.Horizontal;
var allowMixedOrientation = targetModel.Root.Manager.AllowMixedOrientation;

if(paneGroup == null)
{
var targetModelAsPositionableElement = targetModel as ILayoutPositionableElement;
var layoutGroup = targetModel.Parent as ILayoutGroup;
paneGroup = new LayoutDocumentPaneGroup()
var targetModelAsPositionableElement = (ILayoutPositionableElement)targetModel;
var layoutGroup = (ILayoutGroup)targetModel.Parent;
paneGroup = new LayoutDocumentPaneGroup
{
Orientation = System.Windows.Controls.Orientation.Vertical,
Orientation = requiredOrientation,
DockWidth = targetModelAsPositionableElement.DockWidth,
DockHeight = targetModelAsPositionableElement.DockHeight,
};

paneGroup.Children.Add(targetModel);
layoutGroup.InsertChildAt(0, paneGroup);
}
var paneGroupOrientaion = paneGroup as ILayoutOrientableGroup;

else if (allowMixedOrientation && paneGroup.Orientation != requiredOrientation && Type != DropTargetType.DocumentPaneDockInside)
{
var targetModelAsPositionableElement = (ILayoutPositionableElement)targetModel;
var newGroup = new LayoutDocumentPaneGroup
{
Orientation = requiredOrientation,
DockWidth = targetModelAsPositionableElement.DockWidth,
DockHeight = targetModelAsPositionableElement.DockHeight,
};

paneGroup.ReplaceChild(targetModel, newGroup);
newGroup.Children.Add(targetModel);
paneGroup = newGroup;
}

switch (Type)
{
Expand All @@ -104,7 +119,7 @@ protected override void Drop(LayoutDocumentFloatingWindow floatingWindow)

{

if (paneGroupOrientaion.Orientation != System.Windows.Controls.Orientation.Vertical)
if (!allowMixedOrientation && paneGroup.Orientation != System.Windows.Controls.Orientation.Vertical)
{
paneGroup.Orientation = System.Windows.Controls.Orientation.Vertical;
}
Expand Down Expand Up @@ -132,7 +147,7 @@ protected override void Drop(LayoutDocumentFloatingWindow floatingWindow)

{

if(paneGroupOrientaion.Orientation != System.Windows.Controls.Orientation.Vertical)
if(!allowMixedOrientation && paneGroup.Orientation != System.Windows.Controls.Orientation.Vertical)
{
paneGroup.Orientation = System.Windows.Controls.Orientation.Vertical;
}
Expand All @@ -159,7 +174,7 @@ protected override void Drop(LayoutDocumentFloatingWindow floatingWindow)
#region DropTargetType.DocumentPaneDockLeft

{
if (paneGroupOrientaion.Orientation != System.Windows.Controls.Orientation.Horizontal)
if (!allowMixedOrientation && paneGroup.Orientation != System.Windows.Controls.Orientation.Horizontal)
{
paneGroup.Orientation = System.Windows.Controls.Orientation.Horizontal;
}
Expand All @@ -186,7 +201,7 @@ protected override void Drop(LayoutDocumentFloatingWindow floatingWindow)
#region DropTargetType.DocumentPaneDockRight

{
if (paneGroupOrientaion.Orientation != System.Windows.Controls.Orientation.Horizontal)
if (!allowMixedOrientation && paneGroup.Orientation != System.Windows.Controls.Orientation.Horizontal)
{
paneGroup.Orientation = System.Windows.Controls.Orientation.Horizontal;
}
Expand Down

0 comments on commit a48e689

Please sign in to comment.