Skip to content

Commit

Permalink
[GameStudio] AvalonDock: Fix a bug in AvalonDock 3.4.0 which sets Can…
Browse files Browse the repository at this point in the history
…Close to false once a LayoutAnchorable is dragged into a new floating window or a new pane.
  • Loading branch information
xen2 committed Mar 18, 2019
1 parent e4bae81 commit 9076b1e
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions sources/editor/Xenko.GameStudio/AvalonDockHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void RegisterDockingManager(IViewModelServiceProvider viewModelSer
foreach (var anchorable in GetAllAnchorables(docking))
{
if (!string.IsNullOrEmpty(anchorable.ContentId))
anchorable.IsVisibleChanged += AnchorableIsVisibleChanged;
anchorable.IsVisibleChanged += AnchorableIsVisibleChanged;
AdjustAnchorableHideAndCloseCommands(anchorable);
}

Expand Down Expand Up @@ -101,7 +101,17 @@ private static void AnchorableIsVisibleChanged(object sender, EventArgs e)

private static void ElementAdded(object sender, LayoutElementEventArgs e)
{
AdjustAnchorableHideAndCloseCommands(e.Element as LayoutAnchorable);
if (e.Element is LayoutAnchorable anchorable)
{
AdjustAnchorableHideAndCloseCommands(anchorable);
}
else
{
foreach (var anchorable2 in e.Element.Descendents().OfType<LayoutAnchorable>())
{
AdjustAnchorableHideAndCloseCommands(anchorable2);
}
}
}

/// <summary>
Expand All @@ -117,13 +127,14 @@ private static void ElementAdded(object sender, LayoutElementEventArgs e)
/// </remarks>
private static void AdjustAnchorableHideAndCloseCommands(LayoutAnchorable anchorable)
{
if (anchorable == null)
return;

var layoutItem = (LayoutAnchorableItem)anchorable.Root.Manager.GetLayoutItemFromModel(anchorable);
if (layoutItem == null)
throw new InvalidOperationException("The anchorable must be added to the docking manager before calling this method.");

// There's a bug in AvalonDock 3.4.0 which sets CanClose to false once a LayoutAnchorable is dragged into a new floating window or a new pane.
// This is because ResetCanCloseInternal() is called without SetCanCloseInternal() so value gets reset to false.
layoutItem.CanClose = true;

var isPersistent = !string.IsNullOrEmpty(anchorable.ContentId);
if (isPersistent)
layoutItem.CloseCommand = new AnonymousCommand(serviceProvider, () => layoutItem.HideCommand.Execute(null), () => layoutItem.HideCommand.CanExecute(null));
Expand Down

0 comments on commit 9076b1e

Please sign in to comment.