Skip to content

Commit

Permalink
Merge pull request #224 from sukamoni/fix-docking-bug
Browse files Browse the repository at this point in the history
Fixed a bug that freezed when changing DocumentPane Orientation
  • Loading branch information
Dirkster99 authored Jan 13, 2021
2 parents 92fc645 + aaa7a08 commit 50f9be2
Showing 1 changed file with 60 additions and 122 deletions.
182 changes: 60 additions & 122 deletions source/Components/AvalonDock/Controls/DocumentPaneDropTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,41 +83,26 @@ protected override void Drop(LayoutDocumentFloatingWindow floatingWindow)
#region DropTargetType.DocumentPaneDockBottom

{
var parentModel = targetModel.Parent as ILayoutGroup;
var parentModelOrientable = targetModel.Parent as ILayoutOrientableGroup;
int insertToIndex = parentModel.IndexOfChild(targetModel);
var paneGroupContainer = targetModel.Parent;
var paneGroupOrientaion = paneGroupContainer as ILayoutOrientableGroup;
var paneGroup = paneGroupContainer as LayoutDocumentPaneGroup;

if (parentModelOrientable.Orientation != System.Windows.Controls.Orientation.Vertical &&
parentModel.ChildrenCount == 1)
parentModelOrientable.Orientation = System.Windows.Controls.Orientation.Vertical;
if (paneGroupOrientaion.Orientation != System.Windows.Controls.Orientation.Vertical)
{
paneGroup.Orientation = System.Windows.Controls.Orientation.Vertical;
}

if (parentModelOrientable.Orientation == System.Windows.Controls.Orientation.Vertical)
var insertToIndex = paneGroup.IndexOfChild(targetModel);
if (insertToIndex == (paneGroup.Children.Count - 1))
{
var layoutDocumentPaneGroup = floatingWindow.RootPanel as LayoutDocumentPaneGroup;
if (layoutDocumentPaneGroup != null &&
(layoutDocumentPaneGroup.Children.Count == 1 ||
layoutDocumentPaneGroup.Orientation == System.Windows.Controls.Orientation.Vertical))
{
var documentsToMove = layoutDocumentPaneGroup.Children.ToArray();
for (int i = 0; i < documentsToMove.Length; i++)
parentModel.InsertChildAt(insertToIndex + 1 + i, documentsToMove[i]);
}
else
parentModel.InsertChildAt(insertToIndex + 1, floatingWindow.RootPanel);
insertToIndex = paneGroup.Children.Count;
}
else
var documentsToMove = floatingWindow.Children.ToArray();
for (int i = 0; i < documentsToMove.Length; i++)
{
var targetModelAsPositionableElement = targetModel as ILayoutPositionableElement;
var newOrientedPanel = new LayoutDocumentPaneGroup()
{
Orientation = System.Windows.Controls.Orientation.Vertical,
DockWidth = targetModelAsPositionableElement.DockWidth,
DockHeight = targetModelAsPositionableElement.DockHeight,
};

parentModel.InsertChildAt(insertToIndex, newOrientedPanel);
newOrientedPanel.Children.Add(targetModel);
newOrientedPanel.Children.Add(floatingWindow.RootPanel);
var floatingChild = documentsToMove[i];
paneGroup.InsertChildAt(insertToIndex + i, floatingChild);

}
}
break;
Expand All @@ -129,42 +114,26 @@ protected override void Drop(LayoutDocumentFloatingWindow floatingWindow)
#region DropTargetType.DocumentPaneDockTop

{
var parentModel = targetModel.Parent as ILayoutGroup;
var parentModelOrientable = targetModel.Parent as ILayoutOrientableGroup;
int insertToIndex = parentModel.IndexOfChild(targetModel);
var paneGroupContainer = targetModel.Parent;
var paneGroupOrientaion = paneGroupContainer as ILayoutOrientableGroup;
var paneGroup = paneGroupContainer as LayoutDocumentPaneGroup;

if (parentModelOrientable.Orientation != System.Windows.Controls.Orientation.Vertical &&
parentModel.ChildrenCount == 1)
parentModelOrientable.Orientation = System.Windows.Controls.Orientation.Vertical;
if(paneGroupOrientaion.Orientation != System.Windows.Controls.Orientation.Vertical)
{
paneGroup.Orientation = System.Windows.Controls.Orientation.Vertical;
}

if (parentModelOrientable.Orientation == System.Windows.Controls.Orientation.Vertical)
var insertToIndex = paneGroup.IndexOfChild(targetModel);
if(insertToIndex < 0 )
{
var layoutDocumentPaneGroup = floatingWindow.RootPanel as LayoutDocumentPaneGroup;
if (layoutDocumentPaneGroup != null &&
(layoutDocumentPaneGroup.Children.Count == 1 ||
layoutDocumentPaneGroup.Orientation == System.Windows.Controls.Orientation.Vertical))
{
var documentsToMove = layoutDocumentPaneGroup.Children.ToArray();
for (int i = 0; i < documentsToMove.Length; i++)
parentModel.InsertChildAt(insertToIndex + i, documentsToMove[i]);
}
else
parentModel.InsertChildAt(insertToIndex, floatingWindow.RootPanel);
insertToIndex = 0;
}
else
var documentsToMove = floatingWindow.Children.ToArray();
for (int i = 0; i < documentsToMove.Length; i++)
{
var targetModelAsPositionableElement = targetModel as ILayoutPositionableElement;
var newOrientedPanel = new LayoutDocumentPaneGroup()
{
Orientation = System.Windows.Controls.Orientation.Vertical,
DockWidth = targetModelAsPositionableElement.DockWidth,
DockHeight = targetModelAsPositionableElement.DockHeight,
};

parentModel.InsertChildAt(insertToIndex, newOrientedPanel);
//the floating window must be added after the target modal as it could be raise a CollectGarbage call
newOrientedPanel.Children.Add(targetModel);
newOrientedPanel.Children.Insert(0, floatingWindow.RootPanel);
var floatingChild = documentsToMove[i];
paneGroup.InsertChildAt(insertToIndex + i, floatingChild);

}
}
break;
Expand All @@ -176,42 +145,26 @@ protected override void Drop(LayoutDocumentFloatingWindow floatingWindow)
#region DropTargetType.DocumentPaneDockLeft

{
var parentModel = targetModel.Parent as ILayoutGroup;
var parentModelOrientable = targetModel.Parent as ILayoutOrientableGroup;
int insertToIndex = parentModel.IndexOfChild(targetModel);
var paneGroupContainer = targetModel.Parent;
var paneGroupOrientaion = paneGroupContainer as ILayoutOrientableGroup;
var paneGroup = paneGroupContainer as LayoutDocumentPaneGroup;

if (parentModelOrientable.Orientation != System.Windows.Controls.Orientation.Horizontal &&
parentModel.ChildrenCount == 1)
parentModelOrientable.Orientation = System.Windows.Controls.Orientation.Horizontal;
if (paneGroupOrientaion.Orientation != System.Windows.Controls.Orientation.Horizontal)
{
paneGroup.Orientation = System.Windows.Controls.Orientation.Horizontal;
}

if (parentModelOrientable.Orientation == System.Windows.Controls.Orientation.Horizontal)
var insertToIndex = paneGroup.IndexOfChild(targetModel);
if (insertToIndex < 0)
{
var layoutDocumentPaneGroup = floatingWindow.RootPanel as LayoutDocumentPaneGroup;
if (layoutDocumentPaneGroup != null &&
(layoutDocumentPaneGroup.Children.Count == 1 ||
layoutDocumentPaneGroup.Orientation == System.Windows.Controls.Orientation.Horizontal))
{
var documentsToMove = layoutDocumentPaneGroup.Children.ToArray();
for (int i = 0; i < documentsToMove.Length; i++)
parentModel.InsertChildAt(insertToIndex + i, documentsToMove[i]);
}
else
parentModel.InsertChildAt(insertToIndex, floatingWindow.RootPanel);
insertToIndex = 0;
}
else
var documentsToMove = floatingWindow.Children.ToArray();
for (int i = 0; i < documentsToMove.Length; i++)
{
var targetModelAsPositionableElement = targetModel as ILayoutPositionableElement;
var newOrientedPanel = new LayoutDocumentPaneGroup()
{
Orientation = System.Windows.Controls.Orientation.Horizontal,
DockWidth = targetModelAsPositionableElement.DockWidth,
DockHeight = targetModelAsPositionableElement.DockHeight,
};

parentModel.InsertChildAt(insertToIndex, newOrientedPanel);
//the floating window must be added after the target modal as it could be raise a CollectGarbage call
newOrientedPanel.Children.Add(targetModel);
newOrientedPanel.Children.Insert(0, floatingWindow.RootPanel);
var floatingChild = documentsToMove[i];
paneGroup.InsertChildAt(insertToIndex + i, floatingChild);

}
}
break;
Expand All @@ -223,41 +176,26 @@ protected override void Drop(LayoutDocumentFloatingWindow floatingWindow)
#region DropTargetType.DocumentPaneDockRight

{
var parentModel = targetModel.Parent as ILayoutGroup;
var parentModelOrientable = targetModel.Parent as ILayoutOrientableGroup;
int insertToIndex = parentModel.IndexOfChild(targetModel);
var paneGroupContainer = targetModel.Parent;
var paneGroupOrientaion = paneGroupContainer as ILayoutOrientableGroup;
var paneGroup = paneGroupContainer as LayoutDocumentPaneGroup;

if (parentModelOrientable.Orientation != System.Windows.Controls.Orientation.Horizontal &&
parentModel.ChildrenCount == 1)
parentModelOrientable.Orientation = System.Windows.Controls.Orientation.Horizontal;
if (paneGroupOrientaion.Orientation != System.Windows.Controls.Orientation.Horizontal)
{
paneGroup.Orientation = System.Windows.Controls.Orientation.Horizontal;
}

if (parentModelOrientable.Orientation == System.Windows.Controls.Orientation.Horizontal)
var insertToIndex = paneGroup.IndexOfChild(targetModel);
if (insertToIndex == (paneGroup.Children.Count - 1))
{
var layoutDocumentPaneGroup = floatingWindow.RootPanel as LayoutDocumentPaneGroup;
if (layoutDocumentPaneGroup != null &&
(layoutDocumentPaneGroup.Children.Count == 1 ||
layoutDocumentPaneGroup.Orientation == System.Windows.Controls.Orientation.Horizontal))
{
var documentToMove = layoutDocumentPaneGroup.Children.ToArray();
for (int i = 0; i < documentToMove.Length; i++)
parentModel.InsertChildAt(insertToIndex + 1 + i, documentToMove[i]);
}
else
parentModel.InsertChildAt(insertToIndex + 1, floatingWindow.RootPanel);
insertToIndex = paneGroup.Children.Count;
}
else
var documentsToMove = floatingWindow.Children.ToArray();
for (int i = 0; i < documentsToMove.Length; i++)
{
var targetModelAsPositionableElement = targetModel as ILayoutPositionableElement;
var newOrientedPanel = new LayoutDocumentPaneGroup()
{
Orientation = System.Windows.Controls.Orientation.Horizontal,
DockWidth = targetModelAsPositionableElement.DockWidth,
DockHeight = targetModelAsPositionableElement.DockHeight,
};

parentModel.InsertChildAt(insertToIndex, newOrientedPanel);
newOrientedPanel.Children.Add(targetModel);
newOrientedPanel.Children.Add(floatingWindow.RootPanel);
var floatingChild = documentsToMove[i];
paneGroup.InsertChildAt(insertToIndex + i, floatingChild);

}
}
break;
Expand Down

0 comments on commit 50f9be2

Please sign in to comment.