simplified how inheritance is globally disabled/enabled

This commit is contained in:
David Sparer
2019-04-25 10:21:09 -05:00
parent 0d518e44c7
commit 11ad8a8398
2 changed files with 30 additions and 27 deletions

View File

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

View File

@@ -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; }
/// <summary>
/// Indicates whether this inheritance object is enabled.
/// When false, users of this object should not respect inheritance
/// settings for individual properties.
/// </summary>
[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
/// <returns></returns>
public IEnumerable<string> 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<string>();
}
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;
}