Skip to content
Permalink
Browse files

[GameStudio] AvalonDock: Fix a bug in AvalonDock 3.4.0 which sets Can…

…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 9076b1eb951d2fced51103725f517155d823dad2
Showing with 16 additions and 5 deletions.
  1. +16 −5 sources/editor/Xenko.GameStudio/AvalonDockHelper.cs
@@ -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);
}

@@ -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>
@@ -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));

0 comments on commit 9076b1e

Please sign in to comment.
You can’t perform that action at this time.