From 11ad8a8398f73300d36b232c3889db7028250570 Mon Sep 17 00:00:00 2001 From: David Sparer Date: Thu, 25 Apr 2019 10:21:09 -0500 Subject: [PATCH] simplified how inheritance is globally disabled/enabled --- mRemoteV1/Connection/ConnectionInfo.cs | 5 +- .../Connection/ConnectionInfoInheritance.cs | 52 +++++++++---------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/mRemoteV1/Connection/ConnectionInfo.cs b/mRemoteV1/Connection/ConnectionInfo.cs index aeca82a6..cdd3bcfe 100644 --- a/mRemoteV1/Connection/ConnectionInfo.cs +++ b/mRemoteV1/Connection/ConnectionInfo.cs @@ -197,7 +197,10 @@ namespace mRemoteNG.Connection private bool ShouldThisPropertyBeInherited(string propertyName) { - return ParentIsValidInheritanceTarget() && IsInheritanceTurnedOnForThisProperty(propertyName); + return + Inheritance.InheritanceActive && + ParentIsValidInheritanceTarget() && + IsInheritanceTurnedOnForThisProperty(propertyName); } private bool ParentIsValidInheritanceTarget() diff --git a/mRemoteV1/Connection/ConnectionInfoInheritance.cs b/mRemoteV1/Connection/ConnectionInfoInheritance.cs index 08849dba..47909de3 100644 --- a/mRemoteV1/Connection/ConnectionInfoInheritance.cs +++ b/mRemoteV1/Connection/ConnectionInfoInheritance.cs @@ -8,8 +8,6 @@ namespace mRemoteNG.Connection { public class ConnectionInfoInheritance { - private ConnectionInfoInheritance _tempInheritanceStorage; - #region Public Properties #region General @@ -20,8 +18,8 @@ namespace mRemoteNG.Connection TypeConverter(typeof(MiscTools.YesNoTypeConverter))] public bool EverythingInherited { - get { return EverythingIsInherited(); } - set { SetAllValues(value); } + get => EverythingIsInherited(); + set => SetAllValues(value); } #endregion @@ -391,7 +389,16 @@ namespace mRemoteNG.Connection TypeConverter(typeof(MiscTools.YesNoTypeConverter))]public bool VNCViewOnly {get; set;} #endregion - [Browsable(false)] public ConnectionInfo Parent { get; private set; } + [Browsable(false)] + public ConnectionInfo Parent { get; private set; } + + /// + /// Indicates whether this inheritance object is enabled. + /// When false, users of this object should not respect inheritance + /// settings for individual properties. + /// + [Browsable(false)] + public bool InheritanceActive { get; set; } #endregion @@ -408,31 +415,17 @@ namespace mRemoteNG.Connection { var newInheritance = (ConnectionInfoInheritance)MemberwiseClone(); newInheritance.Parent = parent; - newInheritance._tempInheritanceStorage = null; return newInheritance; } public void EnableInheritance() { - if (_tempInheritanceStorage != null) - UnstashInheritanceData(); - } - - private void UnstashInheritanceData() - { - SetAllValues(_tempInheritanceStorage); - _tempInheritanceStorage = null; + InheritanceActive = true; } public void DisableInheritance() { - StashInheritanceData(); - TurnOffInheritanceCompletely(); - } - - private void StashInheritanceData() - { - _tempInheritanceStorage = Clone(Parent); + InheritanceActive = false; } public void TurnOnInheritanceCompletely() @@ -466,15 +459,22 @@ namespace mRemoteNG.Connection /// public IEnumerable GetEnabledInheritanceProperties() { - return GetProperties() - .Where(property => (bool)property.GetValue(this)) - .Select(property => property.Name) - .ToList(); + return InheritanceActive + ? GetProperties() + .Where(property => (bool)property.GetValue(this)) + .Select(property => property.Name) + .ToList() + : Enumerable.Empty(); } private bool FilterProperty(PropertyInfo propertyInfo) { - var exclusions = new[] {"EverythingInherited", "Parent"}; + var exclusions = new[] + { + nameof(EverythingInherited), + nameof(Parent), + nameof(InheritanceActive) + }; var valueShouldNotBeFiltered = !exclusions.Contains(propertyInfo.Name); return valueShouldNotBeFiltered; }