Skip to content

Commit

Permalink
Merge pull request #187 from bdachev/CanClose_serialization
Browse files Browse the repository at this point in the history
Allow to serialize CanClose if set to true for LayoutAnchorable instance
  • Loading branch information
Dirkster99 committed Aug 21, 2020
2 parents f5536ad + 7804a49 commit 4bed7c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 4 additions & 2 deletions source/Components/AvalonDock/Layout/LayoutAnchorable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public class LayoutAnchorable : LayoutContent
public LayoutAnchorable()
{
// LayoutAnchorable will hide by default, not close.
_canClose = false;
// BD: 14.08.2020 Inverting both _canClose and _canCloseDefault to false as anchorables are only hidden but not closed
// That would allow CanClose to be properly serialized if set to true for an instance of LayoutAnchorable
_canClose = _canCloseDefault = false;
}

#endregion Constructors
Expand Down Expand Up @@ -608,4 +610,4 @@ private void UpdateParentVisibility()

#endregion Private Methods
}
}
}
12 changes: 9 additions & 3 deletions source/Components/AvalonDock/Layout/LayoutContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,10 @@ public ImageSource IconSource

#region CanClose

internal bool _canClose = true;
// BD: 14.08.2020 added _canCloseDefault to properly implement inverting _canClose default value in inheritors (e.g. LayoutAnchorable)
// Thus CanClose property will be serialized only when not equal to its default for given class
// With previous code it was not possible to serialize CanClose if set to true for LayoutAnchorable instance
internal bool _canClose = true, _canCloseDefault = true;

public bool CanClose
{
Expand Down Expand Up @@ -559,7 +562,10 @@ public virtual void WriteXml(System.Xml.XmlWriter writer)
if (FloatingHeight != 0.0) writer.WriteAttributeString(nameof(FloatingHeight), FloatingHeight.ToString(CultureInfo.InvariantCulture));

if (IsMaximized) writer.WriteAttributeString(nameof(IsMaximized), IsMaximized.ToString());
if (!CanClose) writer.WriteAttributeString(nameof(CanClose), CanClose.ToString());
// BD: 14.08.2020 changed to check CanClose value against the default in _canCloseDefault
// thus CanClose property will be serialized only when not equal to its default for given class
// With previous code it was not possible to serialize CanClose if set to true for LayoutAnchorable instance
if (CanClose != _canCloseDefault) writer.WriteAttributeString(nameof(CanClose), CanClose.ToString());
if (!CanFloat) writer.WriteAttributeString(nameof(CanFloat), CanFloat.ToString());

if (LastActivationTimeStamp != null) writer.WriteAttributeString(nameof(LastActivationTimeStamp), LastActivationTimeStamp.Value.ToString(CultureInfo.InvariantCulture));
Expand Down Expand Up @@ -760,4 +766,4 @@ protected virtual void InternalDock()

#endregion Internal Methods
}
}
}

0 comments on commit 4bed7c8

Please sign in to comment.