mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
simplified how inheritance is globally disabled/enabled
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user