diff --git a/mRemoteNGTests/Connection/ConnectionInfoTests.cs b/mRemoteNGTests/Connection/ConnectionInfoTests.cs index 9e127a0ba..685138a60 100644 --- a/mRemoteNGTests/Connection/ConnectionInfoTests.cs +++ b/mRemoteNGTests/Connection/ConnectionInfoTests.cs @@ -53,7 +53,8 @@ namespace mRemoteNGTests.Connection [Test] public void CloneCorrectlySetsParentOfInheritanceObject() { - var clonedConnection = _connectionInfo.Clone(); + var originalConnection = new ConnectionInfo(); + var clonedConnection = originalConnection.Clone(); Assert.That(clonedConnection.Inheritance.Parent, Is.EqualTo(clonedConnection)); } @@ -135,7 +136,7 @@ namespace mRemoteNGTests.Connection { public static IEnumerable GetProperties() { - return new ConnectionInfoInheritance(new object()).GetProperties(); + return new ConnectionInfoInheritance(new ConnectionInfo()).GetProperties(); } } } diff --git a/mRemoteNGTests/Connection/DefaultConnectionInheritanceTests.cs b/mRemoteNGTests/Connection/DefaultConnectionInheritanceTests.cs index b86f15de7..93669fd54 100644 --- a/mRemoteNGTests/Connection/DefaultConnectionInheritanceTests.cs +++ b/mRemoteNGTests/Connection/DefaultConnectionInheritanceTests.cs @@ -11,7 +11,7 @@ namespace mRemoteNGTests.Connection [TestCaseSource(nameof(GetInheritanceProperties))] public void LoadingDefaultInheritanceUpdatesAllProperties(PropertyInfo property) { - var inheritanceSource = new ConnectionInfoInheritance(new object(), true); + var inheritanceSource = new ConnectionInfoInheritance(new ConnectionInfo(), true); inheritanceSource.TurnOnInheritanceCompletely(); DefaultConnectionInheritance.Instance.TurnOffInheritanceCompletely(); @@ -25,7 +25,7 @@ namespace mRemoteNGTests.Connection [TestCaseSource(nameof(GetInheritanceProperties))] public void SavingDefaultInheritanceExportsAllProperties(PropertyInfo property) { - var saveTarget = new ConnectionInfoInheritance(new object(), true); + var saveTarget = new ConnectionInfoInheritance(new ConnectionInfo(), true); saveTarget.TurnOffInheritanceCompletely(); DefaultConnectionInheritance.Instance.TurnOnInheritanceCompletely(); @@ -40,7 +40,7 @@ namespace mRemoteNGTests.Connection public void NewInheritanceInstancesCreatedWithDefaultInheritanceValues() { DefaultConnectionInheritance.Instance.Domain = true; - var inheritanceInstance = new ConnectionInfoInheritance(new object()); + var inheritanceInstance = new ConnectionInfoInheritance(new ConnectionInfo()); Assert.That(inheritanceInstance.Domain, Is.True); } @@ -48,7 +48,7 @@ namespace mRemoteNGTests.Connection public void NewInheritanceInstancesCreatedWithAllDefaultInheritanceValues(PropertyInfo property) { DefaultConnectionInheritance.Instance.TurnOnInheritanceCompletely(); - var inheritanceInstance = new ConnectionInfoInheritance(new object()); + var inheritanceInstance = new ConnectionInfoInheritance(new ConnectionInfo()); var valueInDestination = property.GetValue(inheritanceInstance); var valueInSource = property.GetValue(DefaultConnectionInheritance.Instance); @@ -57,7 +57,7 @@ namespace mRemoteNGTests.Connection private static IEnumerable GetInheritanceProperties() { - return new ConnectionInfoInheritance(new object(), true).GetProperties(); + return new ConnectionInfoInheritance(new ConnectionInfo(), true).GetProperties(); } } } \ No newline at end of file diff --git a/mRemoteNGTests/TestHelpers/ConnectionInfoHelpers.cs b/mRemoteNGTests/TestHelpers/ConnectionInfoHelpers.cs index d920923bc..9014ace65 100644 --- a/mRemoteNGTests/TestHelpers/ConnectionInfoHelpers.cs +++ b/mRemoteNGTests/TestHelpers/ConnectionInfoHelpers.cs @@ -1,94 +1,17 @@ -using System; -using mRemoteNG.Connection; -using mRemoteNG.Connection.Protocol; -using mRemoteNG.Connection.Protocol.Http; -using mRemoteNG.Connection.Protocol.ICA; -using mRemoteNG.Connection.Protocol.RDP; -using mRemoteNG.Connection.Protocol.VNC; +using mRemoteNG.Connection; +using mRemoteNG.Container; namespace mRemoteNGTests.TestHelpers { - internal static class ConnectionInfoHelpers + internal static class ConnectionInfoHelpers { - private static readonly Random _random = new Random(); - /// /// Returns a object with randomized /// values in all fields. /// internal static ConnectionInfo GetRandomizedConnectionInfo(bool randomizeInheritance = false) { - var connectionInfo = new ConnectionInfo - { - // string types - Name = RandomString(), - Hostname = RandomString(), - Description = RandomString(), - Domain = RandomString(), - ExtApp = RandomString(), - Icon = RandomString(), - LoadBalanceInfo = RandomString(), - MacAddress = RandomString(), - Panel = RandomString(), - Password = RandomString(), - PostExtApp = RandomString(), - PreExtApp = RandomString(), - PuttySession = RandomString(), - RDGatewayHostname = RandomString(), - RDGatewayUsername = RandomString(), - RDGatewayDomain = RandomString(), - RDGatewayPassword = RandomString(), - UserField = RandomString(), - Username = RandomString(), - VNCProxyIP = RandomString(), - VNCProxyPassword = RandomString(), - VNCProxyUsername = RandomString(), - - // bool types - AutomaticResize = RandomBool(), - CacheBitmaps = RandomBool(), - DisplayThemes = RandomBool(), - DisplayWallpaper = RandomBool(), - EnableDesktopComposition = RandomBool(), - EnableFontSmoothing = RandomBool(), - IsContainer = RandomBool(), - IsDefault = RandomBool(), - IsQuickConnect = RandomBool(), - PleaseConnect = RandomBool(), - RDPAlertIdleTimeout = RandomBool(), - RedirectDiskDrives = RandomBool(), - RedirectKeys = RandomBool(), - RedirectPorts = RandomBool(), - RedirectPrinters = RandomBool(), - RedirectSmartCards = RandomBool(), - UseConsoleSession = RandomBool(), - UseCredSsp = RandomBool(), - VNCViewOnly = RandomBool(), - Favorite = RandomBool(), - - // ints - Port = RandomInt(), - RDPMinutesToIdleTimeout = RandomInt(), - VNCProxyPort = RandomInt(), - - // enums - Colors = RandomEnum(), - ICAEncryptionStrength = RandomEnum (), - Protocol = RandomEnum(), - RDGatewayUsageMethod = RandomEnum(), - RDGatewayUseConnectionCredentials = RandomEnum(), - RDPAuthenticationLevel = RandomEnum(), - RedirectSound = RandomEnum(), - RenderingEngine = RandomEnum(), - Resolution = RandomEnum(), - SoundQuality = RandomEnum(), - VNCAuthMode = RandomEnum(), - VNCColors = RandomEnum(), - VNCCompression = RandomEnum(), - VNCEncoding = RandomEnum(), - VNCProxyType = RandomEnum(), - VNCSmartSizeMode = RandomEnum(), - }; + var connectionInfo = new ConnectionInfo().RandomizeValues(); if (randomizeInheritance) connectionInfo.Inheritance = GetRandomizedInheritance(connectionInfo); @@ -96,38 +19,24 @@ namespace mRemoteNGTests.TestHelpers return connectionInfo; } + internal static ContainerInfo GetRandomizedContainerInfo(bool randomizeInheritance = false) + { + var containerInfo = new ContainerInfo().RandomizeValues(); + + if (randomizeInheritance) + containerInfo.Inheritance = GetRandomizedInheritance(containerInfo); + + return containerInfo; + } + internal static ConnectionInfoInheritance GetRandomizedInheritance(ConnectionInfo parent) { var inheritance = new ConnectionInfoInheritance(parent, true); foreach (var property in inheritance.GetProperties()) { - property.SetValue(inheritance, RandomBool()); + property.SetValue(inheritance, Randomizer.RandomBool()); } return inheritance; } - - internal static string RandomString() - { - return Guid.NewGuid().ToString("N"); - } - - internal static bool RandomBool() - { - return _random.Next() % 2 == 0; - } - - internal static int RandomInt() - { - return _random.Next(); - } - - internal static T RandomEnum() where T : struct, IConvertible - { - if (!typeof(T).IsEnum) - throw new ArgumentException("T must be an enum"); - - var values = Enum.GetValues(typeof(T)); - return (T)values.GetValue(_random.Next(values.Length)); - } } } diff --git a/mRemoteNGTests/TestHelpers/Randomizer.cs b/mRemoteNGTests/TestHelpers/Randomizer.cs index 7286dee3b..d66f3f804 100644 --- a/mRemoteNGTests/TestHelpers/Randomizer.cs +++ b/mRemoteNGTests/TestHelpers/Randomizer.cs @@ -6,7 +6,7 @@ using Enum = System.Enum; namespace mRemoteNGTests.TestHelpers { - internal static class Randomizer + internal static class Randomizer { private static readonly Random Random = new Random(); @@ -98,7 +98,8 @@ namespace mRemoteNGTests.TestHelpers if (opByType.TryGetValue(property.PropertyType, out var mutator)) mutator(property, con); - else if (opByType.TryGetValue(property.PropertyType.BaseType, out var mutator2)) + else if (property.PropertyType.BaseType != null && + opByType.TryGetValue(property.PropertyType.BaseType, out var mutator2)) mutator2(property, con); } diff --git a/mRemoteNGTests/UI/Controls/FilteredPropertyGridTests.cs b/mRemoteNGTests/UI/Controls/FilteredPropertyGridTests.cs new file mode 100644 index 000000000..491882b8f --- /dev/null +++ b/mRemoteNGTests/UI/Controls/FilteredPropertyGridTests.cs @@ -0,0 +1,133 @@ +using System; +using System.Linq; +using mRemoteNG.UI.Controls.FilteredPropertyGrid; +using NUnit.Framework; + +namespace mRemoteNGTests.UI.Controls +{ + public class FilteredPropertyGridTests + { + [Test] + public void AllPropertiesVisibleByDefault() + { + var grid = new FilteredPropertyGrid(); + var obj = new {Prop1 = "hello"}; + grid.SelectedObject = obj; + + Assert.That(grid.VisibleProperties, Is.EquivalentTo(new []{ nameof(obj.Prop1) })); + } + + [Test] + public void PropertiesOnTheHiddenPropertiesListAreNotShown() + { + var grid = new FilteredPropertyGrid(); + var obj = new { Prop1 = "hello", Prop2 = "world" }; + grid.HiddenProperties = new[] { nameof(obj.Prop1) }; + grid.SelectedObject = obj; + + Assert.That(grid.VisibleProperties, Is.EquivalentTo(new[] { nameof(obj.Prop2) })); + } + + [Test] + public void OnlyPropertiesOnTheBrowsablePropertiesListAreShown() + { + var grid = new FilteredPropertyGrid(); + var obj = new { Prop1 = "hello", Prop2 = "world" }; + grid.BrowsableProperties = new[] { nameof(obj.Prop1) }; + grid.SelectedObject = obj; + + Assert.That(grid.VisibleProperties, Is.EquivalentTo(new[] { nameof(obj.Prop1) })); + } + + [Test] + public void APropertyOnBothTheBrowsableAndHiddenListWillNotBeShown() + { + var grid = new FilteredPropertyGrid(); + var obj = new { Prop1 = "hello", Prop2 = "world", Prop3 = "!" }; + grid.BrowsableProperties = new[] { nameof(obj.Prop1), nameof(obj.Prop2) }; + grid.HiddenProperties = new[] { nameof(obj.Prop1) }; + grid.SelectedObject = obj; + + Assert.That(grid.VisibleProperties, Is.EquivalentTo(new[] { nameof(obj.Prop2) })); + } + + [Test] + public void ExceptionThrownWhenNonExistantPropertyFoundInBrowsablePropertiesList() + { + var grid = new FilteredPropertyGrid(); + var obj = new { Prop1 = "hello" }; + grid.SelectedObject = obj; + + Assert.Throws(() => + grid.BrowsableProperties = new[] {"NonExistantProperty"}); + } + + [Test] + public void HiddenPropertiesListCanHandleNonExistentProperties() + { + var grid = new FilteredPropertyGrid(); + var obj = new { Prop1 = "hello" }; + grid.SelectedObject = obj; + + Assert.DoesNotThrow(() => grid.HiddenProperties = new[] { "NonExistantProperty" }); + } + + [Test] + public void GetVisibleGridItemsReturnsAllExpandedItems() + { + var grid = new FilteredPropertyGrid(); + var obj = new { Prop1 = "hello", Prop2 = new{Prop3 = "world"} }; + grid.SelectedObject = obj; + + var visibleGridItems = grid.GetVisibleGridItems(); + + Assert.That(visibleGridItems.Select(i => i.Label), + Is.EquivalentTo(new[] + { + nameof(obj.Prop1), + nameof(obj.Prop2) + })); + } + + [Test] + public void CanSelectGridItem() + { + var grid = new FilteredPropertyGrid(); + var obj = new { Prop1 = "hello", Prop2 = "world" }; + grid.SelectedObject = obj; + + grid.SelectGridItem(nameof(obj.Prop2)); + + Assert.That(grid.SelectedGridItem.PropertyDescriptor?.Name, + Is.EqualTo(nameof(obj.Prop2))); + } + + [Test] + public void FindNextGridItemPropertyReturnsTheCorrectItem() + { + var grid = new FilteredPropertyGrid(); + var obj = new { Prop1 = "hello", Prop2 = "world" }; + grid.SelectedObject = obj; + + grid.SelectGridItem(nameof(obj.Prop1)); + var nextGridItem = grid.FindNextGridItemProperty(grid.SelectedGridItem); + + Assert.That(nextGridItem?.PropertyDescriptor?.Name, + Is.EqualTo(nameof(obj.Prop2))); + } + + [Test] + public void FindPreviousGridItemPropertyReturnsTheCorrectItem() + { + var grid = new FilteredPropertyGrid(); + var obj = new { Prop1 = "hello", Prop2 = "world", Prop3 = "!" }; + grid.SelectedObject = obj; + + grid.SelectGridItem(nameof(obj.Prop3)); + var nextGridItem = grid.FindPreviousGridItemProperty(grid.SelectedGridItem); + + Assert.That(nextGridItem?.PropertyDescriptor?.Name, + Is.EqualTo(nameof(obj.Prop2))); + } + } +} diff --git a/mRemoteNGTests/UI/Window/ConfigWindowTests/ConfigWindowGeneralTests.cs b/mRemoteNGTests/UI/Window/ConfigWindowTests/ConfigWindowGeneralTests.cs index c4ee2a102..4e47ad581 100644 --- a/mRemoteNGTests/UI/Window/ConfigWindowTests/ConfigWindowGeneralTests.cs +++ b/mRemoteNGTests/UI/Window/ConfigWindowTests/ConfigWindowGeneralTests.cs @@ -12,17 +12,14 @@ using NUnit.Framework; namespace mRemoteNGTests.UI.Window.ConfigWindowTests { - public class ConfigWindowGeneralTests + public class ConfigWindowGeneralTests { private ConfigWindow _configWindow; [SetUp] public void Setup() { - _configWindow = new ConfigWindow - { - PropertiesVisible = true - }; + _configWindow = new ConfigWindow(); } [TestCaseSource(nameof(ConnectionInfoGeneralTestCases))] @@ -57,7 +54,92 @@ namespace mRemoteNGTests.UI.Window.ConfigWindowTests Assert.That(_configWindow.VisibleObjectProperties, Is.EquivalentTo(expectedVisibleProperties)); } - private static IEnumerable ConnectionInfoGeneralTestCases() + [Test] + public void SwitchFromInheritanceToConnectionPropertiesWhenClickingRootNode() + { + // connection with a normal parent container + var connection = new ConnectionInfo(); + connection.SetParent(new ContainerInfo()); + + _configWindow.SelectedTreeNode = connection; + _configWindow.ShowInheritanceProperties(); + + _configWindow.SelectedTreeNode = new RootNodeInfo(RootNodeType.Connection); + Assert.That(_configWindow.PropertiesVisible, Is.True, + () => "The property mode should switch from inheritance to connection properties when clicking on the root node."); + } + + [Test] + public void SwitchFromInheritanceToConnectionPropertiesWhenClickingRootPuttyNode() + { + // connection with a normal parent container + var connection = new ConnectionInfo(); + connection.SetParent(new ContainerInfo()); + + _configWindow.SelectedTreeNode = connection; + _configWindow.ShowInheritanceProperties(); + + _configWindow.SelectedTreeNode = new RootPuttySessionsNodeInfo(); + Assert.That(_configWindow.PropertiesVisible, Is.True, + () => "The property mode should switch from inheritance to connection properties when clicking on the root node."); + } + + [Test] + public void SwitchFromInheritanceToConnectionPropertiesWhenClickingChildOfRootNode() + { + // connection with a normal parent container + var root = new RootNodeInfo(RootNodeType.Connection); + var containerWhoseParentIsRoot = new ContainerInfo(); + var connection = new ConnectionInfo(); + root.AddChild(containerWhoseParentIsRoot); + containerWhoseParentIsRoot.AddChild(connection); + + _configWindow.SelectedTreeNode = connection; + _configWindow.ShowInheritanceProperties(); + + _configWindow.SelectedTreeNode = containerWhoseParentIsRoot; + Assert.That(_configWindow.PropertiesVisible, Is.True, + () => "The property mode should switch from inheritance to connection properties " + + "when clicking on a container whose parent is the root node."); + } + + [TestCaseSource(nameof(EveryNodeType))] + public void DefaultConnectionPropertiesCanBeShownRegardlessOfWhichNodeIsSelected(ConnectionInfo selectedObject) + { + _configWindow.SelectedTreeNode = selectedObject; + Assert.That(_configWindow.CanShowDefaultProperties, Is.True); + } + + [TestCaseSource(nameof(EveryNodeType))] + public void DefaultInheritancePropertiesCanBeShownRegardlessOfWhichNodeIsSelected(ConnectionInfo selectedObject) + { + _configWindow.SelectedTreeNode = selectedObject; + Assert.That(_configWindow.CanShowDefaultInheritance, Is.True); + } + + [TestCaseSource(nameof(EveryNodeType))] + public void ConnectionPropertiesCanAlwaysBeShownUnlessNothingIsSelected(ConnectionInfo selectedObject) + { + _configWindow.SelectedTreeNode = selectedObject; + + var selectedObjectNotNull = selectedObject != null; + Assert.That(_configWindow.CanShowProperties, Is.EqualTo(selectedObjectNotNull)); + } + + [TestCaseSource(nameof(EveryNodeType))] + public void InheritancePropertiesAreVisibleInCertainCases(ConnectionInfo selectedObject) + { + _configWindow.SelectedTreeNode = selectedObject; + + var shouldBeAvailable = selectedObject != null && + !(selectedObject is RootNodeInfo) && + !(selectedObject is PuttySessionInfo) && + !(selectedObject.Parent is RootNodeInfo); + + Assert.That(_configWindow.CanShowInheritance, Is.EqualTo(shouldBeAvailable)); + } + + private static IEnumerable ConnectionInfoGeneralTestCases() { var protocolTypes = typeof(ProtocolType).GetEnumValues().OfType(); var testCases = new List(); @@ -80,6 +162,56 @@ namespace mRemoteNGTests.UI.Window.ConfigWindowTests return testCases; } + private static IEnumerable EveryNodeType() + { + var protocolTypes = typeof(ProtocolType).GetEnumValues().OfType().ToList(); + var root = new RootNodeInfo(RootNodeType.Connection); + var container = new ContainerInfo(); + var connectionsWithNormalParent = protocolTypes + .Select(protocolType => + { + var c = new ConnectionInfo {Protocol = protocolType}; + c.SetParent(container); + return new TestCaseData(c).SetName(protocolType + ", Connection, NormalParent"); + }); + + var connectionsWithRootParent = protocolTypes + .Select(protocolType => + { + var c = new ConnectionInfo { Protocol = protocolType }; + c.SetParent(root); + return new TestCaseData(c).SetName(protocolType + ", Connection, RootParent"); + }); + + var contianersWithNormalParent = protocolTypes + .Select(protocolType => + { + var c = new ContainerInfo { Protocol = protocolType }; + c.SetParent(container); + return new TestCaseData(c).SetName(protocolType + ", Connection, NormalParent"); + }); + + var containersWithRootParent = protocolTypes + .Select(protocolType => + { + var c = new ContainerInfo { Protocol = protocolType }; + c.SetParent(root); + return new TestCaseData(c).SetName(protocolType + ", Connection, RootParent"); + }); + + return connectionsWithNormalParent + .Concat(connectionsWithRootParent) + .Concat(contianersWithNormalParent) + .Concat(containersWithRootParent) + .Concat(new[] + { + new TestCaseData(root).SetName("RootNode"), + new TestCaseData(new RootPuttySessionsNodeInfo()).SetName("RootPuttyNode"), + new TestCaseData(new PuttySessionInfo()).SetName("PuttyNode"), + new TestCaseData(null).SetName("Null"), + }); + } + internal static ConnectionInfo ConstructConnectionInfo(ProtocolType protocol, bool isContainer) { // build connection info. set certain connection properties so diff --git a/mRemoteNGTests/UI/Window/ConfigWindowTests/ConfigWindowSpecialTestsBase.cs b/mRemoteNGTests/UI/Window/ConfigWindowTests/ConfigWindowSpecialTestsBase.cs index e5f9169c4..d2c0eb8c6 100644 --- a/mRemoteNGTests/UI/Window/ConfigWindowTests/ConfigWindowSpecialTestsBase.cs +++ b/mRemoteNGTests/UI/Window/ConfigWindowTests/ConfigWindowSpecialTestsBase.cs @@ -6,7 +6,7 @@ using NUnit.Framework; namespace mRemoteNGTests.UI.Window.ConfigWindowTests { - public abstract class ConfigWindowSpecialTestsBase + public abstract class ConfigWindowSpecialTestsBase { protected abstract ProtocolType Protocol { get; } protected bool TestAgainstContainerInfo { get; set; } = false; @@ -20,10 +20,7 @@ namespace mRemoteNGTests.UI.Window.ConfigWindowTests ConnectionInfo = ConfigWindowGeneralTests.ConstructConnectionInfo(Protocol, TestAgainstContainerInfo); ExpectedPropertyList = ConfigWindowGeneralTests.BuildExpectedConnectionInfoPropertyList(Protocol, TestAgainstContainerInfo); - ConfigWindow = new ConfigWindow - { - PropertiesVisible = true, - }; + ConfigWindow = new ConfigWindow(); } public void RunVerification() diff --git a/mRemoteNGTests/mRemoteNGTests.csproj b/mRemoteNGTests/mRemoteNGTests.csproj index 8f41e3262..a42e6e6ea 100644 --- a/mRemoteNGTests/mRemoteNGTests.csproj +++ b/mRemoteNGTests/mRemoteNGTests.csproj @@ -218,6 +218,7 @@ + Form diff --git a/mRemoteV1/Connection/AbstractConnectionRecord.cs b/mRemoteV1/Connection/AbstractConnectionRecord.cs index f9a947f4b..4630e825e 100644 --- a/mRemoteV1/Connection/AbstractConnectionRecord.cs +++ b/mRemoteV1/Connection/AbstractConnectionRecord.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.ComponentModel; using mRemoteNG.Connection.Protocol; using mRemoteNG.Connection.Protocol.Http; @@ -7,11 +6,11 @@ using mRemoteNG.Connection.Protocol.ICA; using mRemoteNG.Connection.Protocol.RDP; using mRemoteNG.Connection.Protocol.VNC; using mRemoteNG.Tools; +using mRemoteNG.Tools.Attributes; namespace mRemoteNG.Connection { - [Obsolete("Valid for mRemoteNG v1.75 (confCons v2.6) or earlier")] public abstract class AbstractConnectionRecord : INotifyPropertyChanged { #region Fields @@ -132,7 +131,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryConnection", 2), LocalizedAttributes.LocalizedDisplayName("strPropertyNameAddress"), - LocalizedAttributes.LocalizedDescription("strPropertyDescriptionAddress")] + LocalizedAttributes.LocalizedDescription("strPropertyDescriptionAddress"), + UsedInAllProtocolsExcept()] public virtual string Hostname { get => _hostname.Trim(); @@ -141,7 +141,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryConnection", 2), LocalizedAttributes.LocalizedDisplayName("strPropertyNameUsername"), - LocalizedAttributes.LocalizedDescription("strPropertyDescriptionUsername")] + LocalizedAttributes.LocalizedDescription("strPropertyDescriptionUsername"), + UsedInAllProtocolsExcept(ProtocolType.VNC, ProtocolType.Telnet, ProtocolType.Rlogin, ProtocolType.RAW)] public virtual string Username { get => GetPropertyValue("Username", _username); @@ -151,7 +152,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryConnection", 2), LocalizedAttributes.LocalizedDisplayName("strPropertyNamePassword"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionPassword"), - PasswordPropertyText(true)] + PasswordPropertyText(true), + UsedInAllProtocolsExcept(ProtocolType.Telnet, ProtocolType.Rlogin, ProtocolType.RAW)] public virtual string Password { get => GetPropertyValue("Password", _password); @@ -160,7 +162,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryConnection", 2), LocalizedAttributes.LocalizedDisplayName("strPropertyNameDomain"), - LocalizedAttributes.LocalizedDescription("strPropertyDescriptionDomain")] + LocalizedAttributes.LocalizedDescription("strPropertyDescriptionDomain"), + UsedInProtocol(ProtocolType.RDP, ProtocolType.ICA, ProtocolType.IntApp)] public string Domain { get => GetPropertyValue("Domain", _domain).Trim(); @@ -184,7 +187,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryProtocol", 3), LocalizedAttributes.LocalizedDisplayName("strPropertyNameExternalTool"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionExternalTool"), - TypeConverter(typeof(ExternalToolsTypeConverter))] + TypeConverter(typeof(ExternalToolsTypeConverter)), + UsedInProtocol(ProtocolType.IntApp)] public string ExtApp { get => GetPropertyValue("ExtApp", _extApp); @@ -193,7 +197,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryProtocol", 3), LocalizedAttributes.LocalizedDisplayName("strPropertyNamePort"), - LocalizedAttributes.LocalizedDescription("strPropertyDescriptionPort")] + LocalizedAttributes.LocalizedDescription("strPropertyDescriptionPort"), + UsedInAllProtocolsExcept(ProtocolType.ICA)] public virtual int Port { get => GetPropertyValue("Port", _port); @@ -203,7 +208,9 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryProtocol", 3), LocalizedAttributes.LocalizedDisplayName("strPropertyNamePuttySession"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionPuttySession"), - TypeConverter(typeof(Config.Putty.PuttySessionsManager.SessionList))] + TypeConverter(typeof(Config.Putty.PuttySessionsManager.SessionList)), + UsedInProtocol(ProtocolType.SSH1, ProtocolType.SSH2, ProtocolType.Telnet, + ProtocolType.RAW, ProtocolType.Rlogin)] public virtual string PuttySession { get => GetPropertyValue("PuttySession", _puttySession); @@ -213,7 +220,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryProtocol", 3), LocalizedAttributes.LocalizedDisplayName("strPropertyNameEncryptionStrength"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionEncryptionStrength"), - TypeConverter(typeof(MiscTools.EnumTypeConverter))] + TypeConverter(typeof(MiscTools.EnumTypeConverter)), + UsedInProtocol(ProtocolType.ICA)] public IcaProtocol.EncryptionStrength ICAEncryptionStrength { get => GetPropertyValue("ICAEncryptionStrength", _icaEncryption); @@ -223,7 +231,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryProtocol", 3), LocalizedAttributes.LocalizedDisplayName("strPropertyNameUseConsoleSession"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionUseConsoleSession"), - TypeConverter(typeof(MiscTools.YesNoTypeConverter))] + TypeConverter(typeof(MiscTools.YesNoTypeConverter)), + UsedInProtocol(ProtocolType.RDP)] public bool UseConsoleSession { get => GetPropertyValue("UseConsoleSession", _useConsoleSession); @@ -233,7 +242,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryProtocol", 3), LocalizedAttributes.LocalizedDisplayName("strPropertyNameAuthenticationLevel"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionAuthenticationLevel"), - TypeConverter(typeof(MiscTools.EnumTypeConverter))] + TypeConverter(typeof(MiscTools.EnumTypeConverter)), + UsedInProtocol(ProtocolType.RDP)] public RdpProtocol.AuthenticationLevel RDPAuthenticationLevel { get => GetPropertyValue("RDPAuthenticationLevel", _rdpAuthenticationLevel); @@ -242,7 +252,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryProtocol", 3), LocalizedAttributes.LocalizedDisplayName("strPropertyNameRDPMinutesToIdleTimeout"), - LocalizedAttributes.LocalizedDescription("strPropertyDescriptionRDPMinutesToIdleTimeout")] + LocalizedAttributes.LocalizedDescription("strPropertyDescriptionRDPMinutesToIdleTimeout"), + UsedInProtocol(ProtocolType.RDP)] public virtual int RDPMinutesToIdleTimeout { get => GetPropertyValue("RDPMinutesToIdleTimeout", _rdpMinutesToIdleTimeout); @@ -258,7 +269,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryProtocol", 3), LocalizedAttributes.LocalizedDisplayName("strPropertyNameRDPAlertIdleTimeout"), - LocalizedAttributes.LocalizedDescription("strPropertyDescriptionRDPAlertIdleTimeout")] + LocalizedAttributes.LocalizedDescription("strPropertyDescriptionRDPAlertIdleTimeout"), + UsedInProtocol(ProtocolType.RDP)] public bool RDPAlertIdleTimeout { get => GetPropertyValue("RDPAlertIdleTimeout", _rdpAlertIdleTimeout); @@ -267,7 +279,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryProtocol", 3), LocalizedAttributes.LocalizedDisplayName("strPropertyNameLoadBalanceInfo"), - LocalizedAttributes.LocalizedDescription("strPropertyDescriptionLoadBalanceInfo")] + LocalizedAttributes.LocalizedDescription("strPropertyDescriptionLoadBalanceInfo"), + UsedInProtocol(ProtocolType.RDP)] public string LoadBalanceInfo { get => GetPropertyValue("LoadBalanceInfo", _loadBalanceInfo).Trim(); @@ -277,7 +290,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryProtocol", 3), LocalizedAttributes.LocalizedDisplayName("strPropertyNameRenderingEngine"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionRenderingEngine"), - TypeConverter(typeof(MiscTools.EnumTypeConverter))] + TypeConverter(typeof(MiscTools.EnumTypeConverter)), + UsedInProtocol(ProtocolType.HTTP, ProtocolType.HTTPS)] public HTTPBase.RenderingEngine RenderingEngine { get => GetPropertyValue("RenderingEngine", _renderingEngine); @@ -287,7 +301,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryProtocol", 3), LocalizedAttributes.LocalizedDisplayName("strPropertyNameUseCredSsp"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionUseCredSsp"), - TypeConverter(typeof(MiscTools.YesNoTypeConverter))] + TypeConverter(typeof(MiscTools.YesNoTypeConverter)), + UsedInProtocol(ProtocolType.RDP)] public bool UseCredSsp { get => GetPropertyValue("UseCredSsp", _useCredSsp); @@ -301,7 +316,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryGateway", 4), LocalizedAttributes.LocalizedDisplayName("strPropertyNameRDGatewayUsageMethod"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionRDGatewayUsageMethod"), - TypeConverter(typeof(MiscTools.EnumTypeConverter))] + TypeConverter(typeof(MiscTools.EnumTypeConverter)), + UsedInProtocol(ProtocolType.RDP)] public RdpProtocol.RDGatewayUsageMethod RDGatewayUsageMethod { get => GetPropertyValue("RDGatewayUsageMethod", _rdGatewayUsageMethod); @@ -310,7 +326,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryGateway", 4), LocalizedAttributes.LocalizedDisplayName("strPropertyNameRDGatewayHostname"), - LocalizedAttributes.LocalizedDescription("strPropertyDescriptionRDGatewayHostname")] + LocalizedAttributes.LocalizedDescription("strPropertyDescriptionRDGatewayHostname"), + UsedInProtocol(ProtocolType.RDP)] public string RDGatewayHostname { get => GetPropertyValue("RDGatewayHostname", _rdGatewayHostname).Trim(); @@ -320,7 +337,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryGateway", 4), LocalizedAttributes.LocalizedDisplayName("strPropertyNameRDGatewayUseConnectionCredentials"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionRDGatewayUseConnectionCredentials"), - TypeConverter(typeof(MiscTools.EnumTypeConverter))] + TypeConverter(typeof(MiscTools.EnumTypeConverter)), + UsedInProtocol(ProtocolType.RDP)] public RdpProtocol.RDGatewayUseConnectionCredentials RDGatewayUseConnectionCredentials { get => GetPropertyValue("RDGatewayUseConnectionCredentials", _rdGatewayUseConnectionCredentials); @@ -329,7 +347,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryGateway", 4), LocalizedAttributes.LocalizedDisplayName("strPropertyNameRDGatewayUsername"), - LocalizedAttributes.LocalizedDescription("strPropertyDescriptionRDGatewayUsername")] + LocalizedAttributes.LocalizedDescription("strPropertyDescriptionRDGatewayUsername"), + UsedInProtocol(ProtocolType.RDP)] public string RDGatewayUsername { get => GetPropertyValue("RDGatewayUsername", _rdGatewayUsername).Trim(); @@ -339,7 +358,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryGateway", 4), LocalizedAttributes.LocalizedDisplayName("strPropertyNameRDGatewayPassword"), LocalizedAttributes.LocalizedDescription("strPropertyNameRDGatewayPassword"), - PasswordPropertyText(true)] + PasswordPropertyText(true), + UsedInProtocol(ProtocolType.RDP)] public string RDGatewayPassword { get => GetPropertyValue("RDGatewayPassword", _rdGatewayPassword); @@ -348,7 +368,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryGateway", 4), LocalizedAttributes.LocalizedDisplayName("strPropertyNameRDGatewayDomain"), - LocalizedAttributes.LocalizedDescription("strPropertyDescriptionRDGatewayDomain")] + LocalizedAttributes.LocalizedDescription("strPropertyDescriptionRDGatewayDomain"), + UsedInProtocol(ProtocolType.RDP)] public string RDGatewayDomain { get => GetPropertyValue("RDGatewayDomain", _rdGatewayDomain).Trim(); @@ -362,7 +383,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryAppearance", 5), LocalizedAttributes.LocalizedDisplayName("strPropertyNameResolution"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionResolution"), - TypeConverter(typeof(MiscTools.EnumTypeConverter))] + TypeConverter(typeof(MiscTools.EnumTypeConverter)), + UsedInProtocol(ProtocolType.RDP, ProtocolType.ICA)] public RdpProtocol.RDPResolutions Resolution { get => GetPropertyValue("Resolution", _resolution); @@ -372,7 +394,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryAppearance", 5), LocalizedAttributes.LocalizedDisplayName("strPropertyNameAutomaticResize"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionAutomaticResize"), - TypeConverter(typeof(MiscTools.YesNoTypeConverter))] + TypeConverter(typeof(MiscTools.YesNoTypeConverter)), + UsedInProtocol(ProtocolType.RDP)] public bool AutomaticResize { get => GetPropertyValue("AutomaticResize", _automaticResize); @@ -382,7 +405,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryAppearance", 5), LocalizedAttributes.LocalizedDisplayName("strPropertyNameColors"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionColors"), - TypeConverter(typeof(MiscTools.EnumTypeConverter))] + TypeConverter(typeof(MiscTools.EnumTypeConverter)), + UsedInProtocol(ProtocolType.RDP, ProtocolType.ICA)] public RdpProtocol.RDPColors Colors { get => GetPropertyValue("Colors", _colors); @@ -392,7 +416,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryAppearance", 5), LocalizedAttributes.LocalizedDisplayName("strPropertyNameCacheBitmaps"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionCacheBitmaps"), - TypeConverter(typeof(MiscTools.YesNoTypeConverter))] + TypeConverter(typeof(MiscTools.YesNoTypeConverter)), + UsedInProtocol(ProtocolType.RDP, ProtocolType.ICA)] public bool CacheBitmaps { get => GetPropertyValue("CacheBitmaps", _cacheBitmaps); @@ -402,7 +427,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryAppearance", 5), LocalizedAttributes.LocalizedDisplayName("strPropertyNameDisplayWallpaper"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionDisplayWallpaper"), - TypeConverter(typeof(MiscTools.YesNoTypeConverter))] + TypeConverter(typeof(MiscTools.YesNoTypeConverter)), + UsedInProtocol(ProtocolType.RDP)] public bool DisplayWallpaper { get => GetPropertyValue("DisplayWallpaper", _displayWallpaper); @@ -412,7 +438,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryAppearance", 5), LocalizedAttributes.LocalizedDisplayName("strPropertyNameDisplayThemes"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionDisplayThemes"), - TypeConverter(typeof(MiscTools.YesNoTypeConverter))] + TypeConverter(typeof(MiscTools.YesNoTypeConverter)), + UsedInProtocol(ProtocolType.RDP)] public bool DisplayThemes { get => GetPropertyValue("DisplayThemes", _displayThemes); @@ -422,7 +449,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryAppearance", 5), LocalizedAttributes.LocalizedDisplayName("strPropertyNameEnableFontSmoothing"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionEnableFontSmoothing"), - TypeConverter(typeof(MiscTools.YesNoTypeConverter))] + TypeConverter(typeof(MiscTools.YesNoTypeConverter)), + UsedInProtocol(ProtocolType.RDP)] public bool EnableFontSmoothing { get => GetPropertyValue("EnableFontSmoothing", _enableFontSmoothing); @@ -432,7 +460,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryAppearance", 5), LocalizedAttributes.LocalizedDisplayName("strPropertyNameEnableDesktopComposition"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionEnableDesktopComposition"), - TypeConverter(typeof(MiscTools.YesNoTypeConverter))] + TypeConverter(typeof(MiscTools.YesNoTypeConverter)), + UsedInProtocol(ProtocolType.RDP)] public bool EnableDesktopComposition { get => GetPropertyValue("EnableDesktopComposition", _enableDesktopComposition); @@ -446,7 +475,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryRedirect", 6), LocalizedAttributes.LocalizedDisplayName("strPropertyNameRedirectKeys"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionRedirectKeys"), - TypeConverter(typeof(MiscTools.YesNoTypeConverter))] + TypeConverter(typeof(MiscTools.YesNoTypeConverter)), + UsedInProtocol(ProtocolType.RDP)] public bool RedirectKeys { get => GetPropertyValue("RedirectKeys", _redirectKeys); @@ -456,7 +486,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryRedirect", 6), LocalizedAttributes.LocalizedDisplayName("strPropertyNameRedirectDrives"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionRedirectDrives"), - TypeConverter(typeof(MiscTools.YesNoTypeConverter))] + TypeConverter(typeof(MiscTools.YesNoTypeConverter)), + UsedInProtocol(ProtocolType.RDP)] public bool RedirectDiskDrives { get => GetPropertyValue("RedirectDiskDrives", _redirectDiskDrives); @@ -466,7 +497,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryRedirect", 6), LocalizedAttributes.LocalizedDisplayName("strPropertyNameRedirectPrinters"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionRedirectPrinters"), - TypeConverter(typeof(MiscTools.YesNoTypeConverter))] + TypeConverter(typeof(MiscTools.YesNoTypeConverter)), + UsedInProtocol(ProtocolType.RDP)] public bool RedirectPrinters { get => GetPropertyValue("RedirectPrinters", _redirectPrinters); @@ -476,7 +508,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryRedirect", 6), LocalizedAttributes.LocalizedDisplayName("strPropertyNameRedirectClipboard"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionRedirectClipboard"), - TypeConverter(typeof(MiscTools.YesNoTypeConverter))] + TypeConverter(typeof(MiscTools.YesNoTypeConverter)), + UsedInProtocol(ProtocolType.RDP)] public bool RedirectClipboard { get { return GetPropertyValue("RedirectClipboard", _redirectClipboard); } @@ -487,7 +520,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryRedirect", 6), LocalizedAttributes.LocalizedDisplayName("strPropertyNameRedirectPorts"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionRedirectPorts"), - TypeConverter(typeof(MiscTools.YesNoTypeConverter))] + TypeConverter(typeof(MiscTools.YesNoTypeConverter)), + UsedInProtocol(ProtocolType.RDP)] public bool RedirectPorts { get => GetPropertyValue("RedirectPorts", _redirectPorts); @@ -497,7 +531,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryRedirect", 6), LocalizedAttributes.LocalizedDisplayName("strPropertyNameRedirectSmartCards"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionRedirectSmartCards"), - TypeConverter(typeof(MiscTools.YesNoTypeConverter))] + TypeConverter(typeof(MiscTools.YesNoTypeConverter)), + UsedInProtocol(ProtocolType.RDP)] public bool RedirectSmartCards { get => GetPropertyValue("RedirectSmartCards", _redirectSmartCards); @@ -507,7 +542,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryRedirect", 6), LocalizedAttributes.LocalizedDisplayName("strPropertyNameRedirectSounds"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionRedirectSounds"), - TypeConverter(typeof(MiscTools.EnumTypeConverter))] + TypeConverter(typeof(MiscTools.EnumTypeConverter)), + UsedInProtocol(ProtocolType.RDP)] public RdpProtocol.RDPSounds RedirectSound { get => GetPropertyValue("RedirectSound", _redirectSound); @@ -517,7 +553,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryRedirect", 6), LocalizedAttributes.LocalizedDisplayName("strPropertyNameSoundQuality"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionSoundQuality"), - TypeConverter(typeof(MiscTools.EnumTypeConverter))] + TypeConverter(typeof(MiscTools.EnumTypeConverter)), + UsedInProtocol(ProtocolType.RDP)] public RdpProtocol.RDPSoundQuality SoundQuality { get => GetPropertyValue("SoundQuality", _soundQuality); @@ -527,18 +564,19 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryRedirect", 6), LocalizedAttributes.LocalizedDisplayName("strPropertyNameRedirectAudioCapture"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionRedirectAudioCapture"), - TypeConverter(typeof(MiscTools.YesNoTypeConverter))] + TypeConverter(typeof(MiscTools.YesNoTypeConverter)), + UsedInProtocol(ProtocolType.RDP)] public bool RedirectAudioCapture { - get { return GetPropertyValue("RedirectAudioCapture", _redirectAudioCapture); } - set { SetField(ref _redirectAudioCapture, value, "RedirectAudioCapture"); } + get => GetPropertyValue(nameof(RedirectAudioCapture), _redirectAudioCapture); + set => SetField(ref _redirectAudioCapture, value, nameof(RedirectAudioCapture)); } #endregion #region Misc - [Browsable(false)] public string ConstantID { get; /*set;*/ } + [Browsable(false)] public string ConstantID { get; } [LocalizedAttributes.LocalizedCategory("strCategoryMiscellaneous", 7), LocalizedAttributes.LocalizedDisplayName("strPropertyNameExternalToolBefore"), @@ -590,12 +628,14 @@ namespace mRemoteNG.Connection #endregion #region VNC - + // TODO: it seems all these VNC properties were added and serialized but + // never hooked up to the VNC protocol or shown to the user [LocalizedAttributes.LocalizedCategory("strCategoryAppearance", 5), - Browsable(false), LocalizedAttributes.LocalizedDisplayName("strPropertyNameCompression"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionCompression"), - TypeConverter(typeof(MiscTools.EnumTypeConverter))] + TypeConverter(typeof(MiscTools.EnumTypeConverter)), + UsedInProtocol(ProtocolType.VNC), + Browsable(false)] public ProtocolVNC.Compression VNCCompression { get => GetPropertyValue("VNCCompression", _vncCompression); @@ -603,10 +643,11 @@ namespace mRemoteNG.Connection } [LocalizedAttributes.LocalizedCategory("strCategoryAppearance", 5), - Browsable(false), LocalizedAttributes.LocalizedDisplayName("strPropertyNameEncoding"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionEncoding"), - TypeConverter(typeof(MiscTools.EnumTypeConverter))] + TypeConverter(typeof(MiscTools.EnumTypeConverter)), + UsedInProtocol(ProtocolType.VNC), + Browsable(false)] public ProtocolVNC.Encoding VNCEncoding { get => GetPropertyValue("VNCEncoding", _vncEncoding); @@ -614,10 +655,11 @@ namespace mRemoteNG.Connection } [LocalizedAttributes.LocalizedCategory("strCategoryConnection", 2), - Browsable(false), LocalizedAttributes.LocalizedDisplayName("strPropertyNameAuthenticationMode"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionAuthenticationMode"), - TypeConverter(typeof(MiscTools.EnumTypeConverter))] + TypeConverter(typeof(MiscTools.EnumTypeConverter)), + UsedInProtocol(ProtocolType.VNC), + Browsable(false)] public ProtocolVNC.AuthMode VNCAuthMode { get => GetPropertyValue("VNCAuthMode", _vncAuthMode); @@ -625,10 +667,11 @@ namespace mRemoteNG.Connection } [LocalizedAttributes.LocalizedCategory("strCategoryProxy", 7), - Browsable(false), LocalizedAttributes.LocalizedDisplayName("strPropertyNameVNCProxyType"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionVNCProxyType"), - TypeConverter(typeof(MiscTools.EnumTypeConverter))] + TypeConverter(typeof(MiscTools.EnumTypeConverter)), + UsedInProtocol(ProtocolType.VNC), + Browsable(false)] public ProtocolVNC.ProxyType VNCProxyType { get => GetPropertyValue("VNCProxyType", _vncProxyType); @@ -636,9 +679,10 @@ namespace mRemoteNG.Connection } [LocalizedAttributes.LocalizedCategory("strCategoryProxy", 7), - Browsable(false), LocalizedAttributes.LocalizedDisplayName("strPropertyNameVNCProxyAddress"), - LocalizedAttributes.LocalizedDescription("strPropertyDescriptionVNCProxyAddress")] + LocalizedAttributes.LocalizedDescription("strPropertyDescriptionVNCProxyAddress"), + UsedInProtocol(ProtocolType.VNC), + Browsable(false)] public string VNCProxyIP { get => GetPropertyValue("VNCProxyIP", _vncProxyIp); @@ -646,9 +690,10 @@ namespace mRemoteNG.Connection } [LocalizedAttributes.LocalizedCategory("strCategoryProxy", 7), - Browsable(false), LocalizedAttributes.LocalizedDisplayName("strPropertyNameVNCProxyPort"), - LocalizedAttributes.LocalizedDescription("strPropertyDescriptionVNCProxyPort")] + LocalizedAttributes.LocalizedDescription("strPropertyDescriptionVNCProxyPort"), + UsedInProtocol(ProtocolType.VNC), + Browsable(false)] public int VNCProxyPort { get => GetPropertyValue("VNCProxyPort", _vncProxyPort); @@ -656,9 +701,10 @@ namespace mRemoteNG.Connection } [LocalizedAttributes.LocalizedCategory("strCategoryProxy", 7), - Browsable(false), LocalizedAttributes.LocalizedDisplayName("strPropertyNameVNCProxyUsername"), - LocalizedAttributes.LocalizedDescription("strPropertyDescriptionVNCProxyUsername")] + LocalizedAttributes.LocalizedDescription("strPropertyDescriptionVNCProxyUsername"), + UsedInProtocol(ProtocolType.VNC), + Browsable(false)] public string VNCProxyUsername { get => GetPropertyValue("VNCProxyUsername", _vncProxyUsername); @@ -666,10 +712,11 @@ namespace mRemoteNG.Connection } [LocalizedAttributes.LocalizedCategory("strCategoryProxy", 7), - Browsable(false), LocalizedAttributes.LocalizedDisplayName("strPropertyNameVNCProxyPassword"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionVNCProxyPassword"), - PasswordPropertyText(true)] + PasswordPropertyText(true), + UsedInProtocol(ProtocolType.VNC), + Browsable(false)] public string VNCProxyPassword { get => GetPropertyValue("VNCProxyPassword", _vncProxyPassword); @@ -677,10 +724,11 @@ namespace mRemoteNG.Connection } [LocalizedAttributes.LocalizedCategory("strCategoryAppearance", 5), - Browsable(false), LocalizedAttributes.LocalizedDisplayName("strPropertyNameColors"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionColors"), - TypeConverter(typeof(MiscTools.EnumTypeConverter))] + TypeConverter(typeof(MiscTools.EnumTypeConverter)), + UsedInProtocol(ProtocolType.VNC), + Browsable(false)] public ProtocolVNC.Colors VNCColors { get => GetPropertyValue("VNCColors", _vncColors); @@ -690,7 +738,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryAppearance", 5), LocalizedAttributes.LocalizedDisplayName("strPropertyNameSmartSizeMode"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionSmartSizeMode"), - TypeConverter(typeof(MiscTools.EnumTypeConverter))] + TypeConverter(typeof(MiscTools.EnumTypeConverter)), + UsedInProtocol(ProtocolType.VNC)] public ProtocolVNC.SmartSizeMode VNCSmartSizeMode { get => GetPropertyValue("VNCSmartSizeMode", _vncSmartSizeMode); @@ -700,7 +749,8 @@ namespace mRemoteNG.Connection [LocalizedAttributes.LocalizedCategory("strCategoryAppearance", 5), LocalizedAttributes.LocalizedDisplayName("strPropertyNameViewOnly"), LocalizedAttributes.LocalizedDescription("strPropertyDescriptionViewOnly"), - TypeConverter(typeof(MiscTools.YesNoTypeConverter))] + TypeConverter(typeof(MiscTools.YesNoTypeConverter)), + UsedInProtocol(ProtocolType.VNC)] public bool VNCViewOnly { get => GetPropertyValue("VNCViewOnly", _vncViewOnly); diff --git a/mRemoteV1/Connection/ConnectionInfo.cs b/mRemoteV1/Connection/ConnectionInfo.cs index 8c8d51b50..aeca82a61 100644 --- a/mRemoteV1/Connection/ConnectionInfo.cs +++ b/mRemoteV1/Connection/ConnectionInfo.cs @@ -22,9 +22,18 @@ namespace mRemoteNG.Connection [DefaultProperty("Name")] public class ConnectionInfo : AbstractConnectionRecord, IHasParent, IInheritable { + private ConnectionInfoInheritance _inheritance; + #region Public Properties - [Browsable(false)] public ConnectionInfoInheritance Inheritance { get; set; } + [Browsable(false)] + public ConnectionInfoInheritance Inheritance + { + get => _inheritance; + set => _inheritance = _inheritance.Parent != this + ? _inheritance.Clone(this) + : value; + } [Browsable(false)] public ProtocolList OpenConnections { get; protected set; } @@ -72,11 +81,14 @@ namespace mRemoteNG.Connection { var newConnectionInfo = new ConnectionInfo(); newConnectionInfo.CopyFrom(this); - newConnectionInfo.Inheritance = Inheritance.Clone(); - newConnectionInfo.Inheritance.Parent = newConnectionInfo; return newConnectionInfo; } + /// + /// Copies all connection and inheritance values + /// from the given . + /// + /// public void CopyFrom(ConnectionInfo sourceConnectionInfo) { var properties = GetType().BaseType?.GetProperties().Where(prop => prop.CanRead && prop.CanWrite); @@ -88,8 +100,7 @@ namespace mRemoteNG.Connection property.SetValue(this, remotePropertyValue, null); } - var clonedInheritance = sourceConnectionInfo.Inheritance.Clone(); - clonedInheritance.Parent = this; + var clonedInheritance = sourceConnectionInfo.Inheritance.Clone(this); Inheritance = clonedInheritance; } @@ -388,7 +399,7 @@ namespace mRemoteNG.Connection private void SetNonBrowsablePropertiesDefaults() { - Inheritance = new ConnectionInfoInheritance(this); + _inheritance = new ConnectionInfoInheritance(this); SetNewOpenConnectionList(); //PositionID = 0; } diff --git a/mRemoteV1/Connection/ConnectionInfoInheritance.cs b/mRemoteV1/Connection/ConnectionInfoInheritance.cs index 4f1e64c22..08849dba1 100644 --- a/mRemoteV1/Connection/ConnectionInfoInheritance.cs +++ b/mRemoteV1/Connection/ConnectionInfoInheritance.cs @@ -391,12 +391,12 @@ namespace mRemoteNG.Connection TypeConverter(typeof(MiscTools.YesNoTypeConverter))]public bool VNCViewOnly {get; set;} #endregion - [Browsable(false)] public object Parent { get; set; } + [Browsable(false)] public ConnectionInfo Parent { get; private set; } #endregion - public ConnectionInfoInheritance(object parent, bool ignoreDefaultInheritance = false) + public ConnectionInfoInheritance(ConnectionInfo parent, bool ignoreDefaultInheritance = false) { Parent = parent; if (!ignoreDefaultInheritance) @@ -404,9 +404,10 @@ namespace mRemoteNG.Connection } - public ConnectionInfoInheritance Clone() + public ConnectionInfoInheritance Clone(ConnectionInfo parent) { var newInheritance = (ConnectionInfoInheritance)MemberwiseClone(); + newInheritance.Parent = parent; newInheritance._tempInheritanceStorage = null; return newInheritance; } @@ -431,7 +432,7 @@ namespace mRemoteNG.Connection private void StashInheritanceData() { - _tempInheritanceStorage = Clone(); + _tempInheritanceStorage = Clone(Parent); } public void TurnOnInheritanceCompletely() @@ -458,6 +459,19 @@ namespace mRemoteNG.Connection return filteredProperties; } + /// + /// Gets the name of all properties where inheritance is turned on + /// (set to True). + /// + /// + public IEnumerable GetEnabledInheritanceProperties() + { + return GetProperties() + .Where(property => (bool)property.GetValue(this)) + .Select(property => property.Name) + .ToList(); + } + private bool FilterProperty(PropertyInfo propertyInfo) { var exclusions = new[] {"EverythingInherited", "Parent"}; diff --git a/mRemoteV1/Connection/DefaultConnectionInfo.cs b/mRemoteV1/Connection/DefaultConnectionInfo.cs index 72a089b58..7ebea9d8c 100644 --- a/mRemoteV1/Connection/DefaultConnectionInfo.cs +++ b/mRemoteV1/Connection/DefaultConnectionInfo.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; using System.Configuration; using mRemoteNG.App; @@ -7,6 +8,7 @@ namespace mRemoteNG.Connection { public class DefaultConnectionInfo : ConnectionInfo { + [Browsable(false)] public static DefaultConnectionInfo Instance { get; } = new DefaultConnectionInfo(); private DefaultConnectionInfo() diff --git a/mRemoteV1/Connection/DefaultConnectionInheritance.cs b/mRemoteV1/Connection/DefaultConnectionInheritance.cs index 8e2d8e82b..82f2b0fd9 100644 --- a/mRemoteV1/Connection/DefaultConnectionInheritance.cs +++ b/mRemoteV1/Connection/DefaultConnectionInheritance.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; using mRemoteNG.App; @@ -6,6 +7,7 @@ namespace mRemoteNG.Connection { public class DefaultConnectionInheritance : ConnectionInfoInheritance { + [Browsable(false)] public static DefaultConnectionInheritance Instance { get; } = new DefaultConnectionInheritance(); private DefaultConnectionInheritance() : base(null, true) diff --git a/mRemoteV1/Container/ContainerInfo.cs b/mRemoteV1/Container/ContainerInfo.cs index 6795c2d3d..fa2e901c1 100644 --- a/mRemoteV1/Container/ContainerInfo.cs +++ b/mRemoteV1/Container/ContainerInfo.cs @@ -204,7 +204,7 @@ namespace mRemoteNG.Container var newContainer = new ContainerInfo(); newContainer.CopyFrom(this); newContainer.OpenConnections = new ProtocolList(); - newContainer.Inheritance = Inheritance.Clone(); + newContainer.Inheritance = Inheritance.Clone(newContainer); foreach (var child in Children.ToArray()) { var newChild = child.Clone(); diff --git a/mRemoteV1/Tools/Attributes/UsedInAllProtocolsExceptAttribute.cs b/mRemoteV1/Tools/Attributes/UsedInAllProtocolsExceptAttribute.cs new file mode 100644 index 000000000..e73099a9c --- /dev/null +++ b/mRemoteV1/Tools/Attributes/UsedInAllProtocolsExceptAttribute.cs @@ -0,0 +1,18 @@ +using System; +using System.Linq; +using mRemoteNG.Connection.Protocol; + +namespace mRemoteNG.Tools.Attributes +{ + public class UsedInAllProtocolsExceptAttribute : UsedInProtocolAttribute + { + public UsedInAllProtocolsExceptAttribute(params ProtocolType[] exceptions) + : base(Enum + .GetValues(typeof(ProtocolType)) + .Cast() + .Except(exceptions) + .ToArray()) + { + } + } +} diff --git a/mRemoteV1/Tools/Attributes/UsedInProtocolAttribute.cs b/mRemoteV1/Tools/Attributes/UsedInProtocolAttribute.cs new file mode 100644 index 000000000..1545a548f --- /dev/null +++ b/mRemoteV1/Tools/Attributes/UsedInProtocolAttribute.cs @@ -0,0 +1,16 @@ +using System; +using mRemoteNG.Connection.Protocol; + +namespace mRemoteNG.Tools.Attributes +{ + [AttributeUsage(AttributeTargets.Property)] + public class UsedInProtocolAttribute : Attribute + { + public ProtocolType[] SupportedProtocolTypes { get; } + + public UsedInProtocolAttribute(params ProtocolType[] supportedProtocolTypes) + { + SupportedProtocolTypes = supportedProtocolTypes; + } + } +} diff --git a/mRemoteV1/UI/Controls/ConnectionInfoPropertyGrid/ConnectionInfoPropertyGrid.Designer.cs b/mRemoteV1/UI/Controls/ConnectionInfoPropertyGrid/ConnectionInfoPropertyGrid.Designer.cs new file mode 100644 index 000000000..bfa24efe2 --- /dev/null +++ b/mRemoteV1/UI/Controls/ConnectionInfoPropertyGrid/ConnectionInfoPropertyGrid.Designer.cs @@ -0,0 +1,37 @@ +namespace mRemoteNG.UI.Controls.ConnectionInfoPropertyGrid +{ + partial class ConnectionInfoPropertyGrid + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + } + + #endregion + } +} diff --git a/mRemoteV1/UI/Controls/ConnectionInfoPropertyGrid/ConnectionInfoPropertyGrid.cs b/mRemoteV1/UI/Controls/ConnectionInfoPropertyGrid/ConnectionInfoPropertyGrid.cs new file mode 100644 index 000000000..edc135c8d --- /dev/null +++ b/mRemoteV1/UI/Controls/ConnectionInfoPropertyGrid/ConnectionInfoPropertyGrid.cs @@ -0,0 +1,350 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Windows.Forms; +using mRemoteNG.App; +using mRemoteNG.Connection; +using mRemoteNG.Connection.Protocol; +using mRemoteNG.Connection.Protocol.RDP; +using mRemoteNG.Connection.Protocol.VNC; +using mRemoteNG.Messages; +using mRemoteNG.Security; +using mRemoteNG.Tools; +using mRemoteNG.Tools.Attributes; +using mRemoteNG.Tree.Root; + +namespace mRemoteNG.UI.Controls.ConnectionInfoPropertyGrid +{ + public partial class ConnectionInfoPropertyGrid : FilteredPropertyGrid.FilteredPropertyGrid + { + private readonly Dictionary> _propertyCache = new Dictionary>(); + private ConnectionInfo _selectedConnectionInfo; + private PropertyMode _propertyMode; + + /// + /// The currently being shown by this + /// property grid. + /// + public ConnectionInfo SelectedConnectionInfo + { + get => _selectedConnectionInfo; + set + { + if (_selectedConnectionInfo == value) + return; + + _selectedConnectionInfo = value; + RootNodeSelected = SelectedConnectionInfo is RootNodeInfo; + SetGridObject(); + } + } + + /// + /// Determines which set of properties this grid will display. + /// + public PropertyMode PropertyMode + { + get => _propertyMode; + set + { + if (_propertyMode == value) + return; + _propertyMode = value; + SetGridObject(); + } + } + + /// + /// Is the property grid showing the selected connection's + /// inheritance info? If false, the connection's normal + /// properties are shown instead. + /// + public bool IsShowingInheritance => PropertyMode == PropertyMode.Inheritance || + PropertyMode == PropertyMode.DefaultInheritance; + + /// + /// This indicates whether the current + /// is a . + /// + public bool IsShowingDefaultProperties => PropertyMode == PropertyMode.DefaultConnection || + PropertyMode == PropertyMode.DefaultInheritance; + + /// + /// True when the is + /// of type . + /// + public bool RootNodeSelected { get; private set; } + + public ConnectionInfoPropertyGrid() + { + InitializeComponent(); + PropertyValueChanged += pGrid_PropertyValueChanged; + } + + private void SetGridObject() + { + ClearFilters(); + + switch (PropertyMode) + { + case PropertyMode.Connection: + default: + SelectedObject = SelectedConnectionInfo; + break; + case PropertyMode.Inheritance: + SelectedObject = SelectedConnectionInfo?.Inheritance; + break; + case PropertyMode.DefaultConnection: + SelectedObject = DefaultConnectionInfo.Instance; + break; + case PropertyMode.DefaultInheritance: + SelectedObject = DefaultConnectionInheritance.Instance; + break; + } + + if (SelectedObject != null) + ShowHideGridItems(); + } + + private void ShowHideGridItems() + { + try + { + if (SelectedConnectionInfo == null) + return; + + if (RootNodeSelected && PropertyMode == PropertyMode.Connection) + { + if (SelectedConnectionInfo is RootPuttySessionsNodeInfo) + { + BrowsableProperties = new[] + { + nameof(RootPuttySessionsNodeInfo.Name) + }; + } + else if (SelectedConnectionInfo is RootNodeInfo) + { + BrowsableProperties = new[] + { + nameof(RootNodeInfo.Name), + nameof(RootNodeInfo.Password) + }; + } + + Refresh(); + return; + } + + // set all browsable properties valid for this connection's protocol + BrowsableProperties = + GetPropertiesForGridObject(SelectedObject) + .Where(property => + IsValidForProtocol(property, SelectedConnectionInfo.Protocol, IsShowingInheritance)) + .Select(property => property.Name) + .ToArray(); + + var strHide = new List(); + + if (PropertyMode == PropertyMode.Connection) + { + // hide any inherited properties + strHide.AddRange(SelectedConnectionInfo.Inheritance.GetEnabledInheritanceProperties()); + + // ReSharper disable once SwitchStatementMissingSomeCases + switch (SelectedConnectionInfo.Protocol) + { + case ProtocolType.RDP: + strHide.AddRange(SpecialRdpExclusions()); + break; + case ProtocolType.VNC: + strHide.AddRange(SpecialVncExclusions()); + break; + } + + if (SelectedConnectionInfo.IsContainer) + strHide.Add(nameof(AbstractConnectionRecord.Hostname)); + + if (SelectedConnectionInfo is PuttySessionInfo) + strHide.Add(nameof(AbstractConnectionRecord.Favorite)); + } + else if (PropertyMode == PropertyMode.DefaultConnection) + { + strHide.Add(nameof(AbstractConnectionRecord.Hostname)); + strHide.Add(nameof(AbstractConnectionRecord.Name)); + } + + HiddenProperties = strHide.ToArray(); + Refresh(); + } + catch (Exception ex) + { + Runtime.MessageCollector.AddMessage( + MessageClass.ErrorMsg, + Language.strConfigPropertyGridHideItemsFailed + + Environment.NewLine + ex.Message, true); + } + } + + private IEnumerable GetPropertiesForGridObject(object currentGridObject) + { + if (_propertyCache.TryGetValue(currentGridObject.GetType(), out var properties)) + return properties; + + var type = currentGridObject.GetType(); + var props = type.GetProperties(); + _propertyCache.Add(type, props); + + return props; + } + + private bool IsValidForProtocol(PropertyInfo property, ProtocolType protocol, bool skipProtocolCheck) + { + return + property.GetCustomAttribute()?.Browsable != false && + (skipProtocolCheck || property.GetCustomAttribute()? + .SupportedProtocolTypes + .Contains(protocol) != false); + } + + /// + /// + /// + private List SpecialRdpExclusions() + { + var strHide = new List(); + + if (SelectedConnectionInfo.RDPMinutesToIdleTimeout <= 0) + { + strHide.Add(nameof(AbstractConnectionRecord.RDPAlertIdleTimeout)); + } + + if (SelectedConnectionInfo.RDGatewayUsageMethod == RdpProtocol.RDGatewayUsageMethod.Never) + { + strHide.Add(nameof(AbstractConnectionRecord.RDGatewayDomain)); + strHide.Add(nameof(AbstractConnectionRecord.RDGatewayHostname)); + strHide.Add(nameof(AbstractConnectionRecord.RDGatewayPassword)); + strHide.Add(nameof(AbstractConnectionRecord.RDGatewayUseConnectionCredentials)); + strHide.Add(nameof(AbstractConnectionRecord.RDGatewayUsername)); + } + else if (SelectedConnectionInfo.RDGatewayUseConnectionCredentials == + RdpProtocol.RDGatewayUseConnectionCredentials.Yes) + { + strHide.Add(nameof(AbstractConnectionRecord.RDGatewayDomain)); + strHide.Add(nameof(AbstractConnectionRecord.RDGatewayPassword)); + strHide.Add(nameof(AbstractConnectionRecord.RDGatewayUsername)); + } + + if (!(SelectedConnectionInfo.Resolution == RdpProtocol.RDPResolutions.FitToWindow || + SelectedConnectionInfo.Resolution == RdpProtocol.RDPResolutions.Fullscreen)) + { + strHide.Add(nameof(AbstractConnectionRecord.AutomaticResize)); + } + + if (SelectedConnectionInfo.RedirectSound != RdpProtocol.RDPSounds.BringToThisComputer) + { + strHide.Add(nameof(AbstractConnectionRecord.SoundQuality)); + } + + return strHide; + } + + private List SpecialVncExclusions() + { + var strHide = new List(); + if (SelectedConnectionInfo.VNCAuthMode == ProtocolVNC.AuthMode.AuthVNC) + { + strHide.Add(nameof(AbstractConnectionRecord.Username)); + strHide.Add(nameof(AbstractConnectionRecord.Domain)); + } + + if (SelectedConnectionInfo.VNCProxyType == ProtocolVNC.ProxyType.ProxyNone) + { + strHide.Add(nameof(AbstractConnectionRecord.VNCProxyIP)); + strHide.Add(nameof(AbstractConnectionRecord.VNCProxyPassword)); + strHide.Add(nameof(AbstractConnectionRecord.VNCProxyPort)); + strHide.Add(nameof(AbstractConnectionRecord.VNCProxyUsername)); + } + + return strHide; + } + + private void UpdateConnectionInfoNode(PropertyValueChangedEventArgs e) + { + if (IsShowingInheritance) + return; + + if (e.ChangedItem.Label == Language.strPropertyNameProtocol) + { + SelectedConnectionInfo.SetDefaultPort(); + } + else if (e.ChangedItem.Label == Language.strPropertyNameName) + { + if (Settings.Default.SetHostnameLikeDisplayName) + { + if (!string.IsNullOrEmpty(SelectedConnectionInfo.Name)) + SelectedConnectionInfo.Hostname = SelectedConnectionInfo.Name; + } + } + + if (IsShowingDefaultProperties) + DefaultConnectionInfo.Instance.SaveTo(Settings.Default, a => "ConDefault" + a); + } + + private void UpdateRootInfoNode(PropertyValueChangedEventArgs e) + { + if (!(SelectedObject is RootNodeInfo rootInfo)) + return; + + if (e.ChangedItem.PropertyDescriptor?.Name != "Password") + return; + + if (rootInfo.Password) + { + var passwordName = Settings.Default.UseSQLServer + ? Language.strSQLServer.TrimEnd(':') + : Path.GetFileName(Runtime.ConnectionsService.GetStartupConnectionFileName()); + + var password = MiscTools.PasswordDialog(passwordName); + + // operation cancelled, dont set a password + if (!password.Any() || password.First().Length == 0) + { + rootInfo.Password = false; + return; + } + + rootInfo.PasswordString = password.First().ConvertToUnsecureString(); + } + else + { + rootInfo.PasswordString = ""; + } + } + + private void UpdateInheritanceNode() + { + if (IsShowingDefaultProperties && IsShowingInheritance) + DefaultConnectionInheritance.Instance.SaveTo(Settings.Default, a => "InhDefault" + a); + } + + private void pGrid_PropertyValueChanged(object s, PropertyValueChangedEventArgs e) + { + try + { + UpdateConnectionInfoNode(e); + UpdateRootInfoNode(e); + UpdateInheritanceNode(); + ShowHideGridItems(); + } + catch (Exception ex) + { + Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, + Language.strConfigPropertyGridValueFailed + Environment.NewLine + + ex.Message, true); + } + } + } +} diff --git a/mRemoteV1/UI/Controls/ConnectionInfoPropertyGrid/PropertyMode.cs b/mRemoteV1/UI/Controls/ConnectionInfoPropertyGrid/PropertyMode.cs new file mode 100644 index 000000000..4654b5bd7 --- /dev/null +++ b/mRemoteV1/UI/Controls/ConnectionInfoPropertyGrid/PropertyMode.cs @@ -0,0 +1,10 @@ +namespace mRemoteNG.UI.Controls.ConnectionInfoPropertyGrid +{ + public enum PropertyMode + { + Connection, + Inheritance, + DefaultConnection, + DefaultInheritance, + } +} diff --git a/mRemoteV1/UI/Controls/FilteredPropertyGrid/FilteredPropertyGrid.cs b/mRemoteV1/UI/Controls/FilteredPropertyGrid/FilteredPropertyGrid.cs index 32b919cb3..80e3ae41f 100644 --- a/mRemoteV1/UI/Controls/FilteredPropertyGrid/FilteredPropertyGrid.cs +++ b/mRemoteV1/UI/Controls/FilteredPropertyGrid/FilteredPropertyGrid.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Windows.Forms; -using mRemoteNG.App; namespace mRemoteNG.UI.Controls.FilteredPropertyGrid { @@ -126,8 +125,8 @@ namespace mRemoteNG.UI.Controls.FilteredPropertyGrid } else if (_mWrapper.SelectedObject != value) { - var needrefresh = value.GetType() != _mWrapper.SelectedObject.GetType(); - _mWrapper.SelectedObject = value; + var needrefresh = value?.GetType() != _mWrapper.SelectedObject?.GetType(); + _mWrapper.SelectedObject = value ?? new object(); if (needrefresh) RefreshProperties(); } @@ -139,6 +138,159 @@ namespace mRemoteNG.UI.Controls.FilteredPropertyGrid } } + public List GetVisibleGridItems() + { + var gridRoot = SelectedGridItem; + while (gridRoot.GridItemType != GridItemType.Root) + { + gridRoot = gridRoot.Parent; + } + return GetVisibleGridItemsRecursive(gridRoot, new List()); + } + + private List GetVisibleGridItemsRecursive(GridItem item, List gridItems) + { + if (item.GridItemType == GridItemType.Property && !gridItems.Contains(item)) + gridItems.Add(item); + + if (item.Expandable && !item.Expanded) + return gridItems; + + foreach (GridItem child in item.GridItems) + { + GetVisibleGridItemsRecursive(child, gridItems); + } + + return gridItems; + } + + public GridItem FindPreviousGridItemProperty(GridItem startItem) + { + var gridItems = GetVisibleGridItems(); + + if (gridItems.Count == 0 || startItem == null) + return null; + + var startIndex = gridItems.IndexOf(startItem); + if (startItem.GridItemType == GridItemType.Property) + { + startIndex--; + if (startIndex < 0) + { + startIndex = gridItems.Count - 1; + } + } + + var previousIndex = 0; + var previousIndexValid = false; + for (var index = startIndex; index >= 0; index--) + { + if (gridItems[index].GridItemType != GridItemType.Property) continue; + previousIndex = index; + previousIndexValid = true; + break; + } + + if (previousIndexValid) + return gridItems[previousIndex]; + + for (var index = gridItems.Count - 1; index >= startIndex + 1; index--) + { + if (gridItems[index].GridItemType != GridItemType.Property) continue; + previousIndex = index; + previousIndexValid = true; + break; + } + + return !previousIndexValid ? null : gridItems[previousIndex]; + } + + public GridItem FindNextGridItemProperty(GridItem startItem) + { + var gridItems = GetVisibleGridItems(); + + if (gridItems.Count == 0 || startItem == null) + return null; + + var startIndex = gridItems.IndexOf(startItem); + if (startItem.GridItemType == GridItemType.Property) + { + startIndex++; + if (startIndex >= gridItems.Count) + { + startIndex = 0; + } + } + + var nextIndex = 0; + var nextIndexValid = false; + for (var index = startIndex; index <= gridItems.Count - 1; index++) + { + if (gridItems[index].GridItemType != GridItemType.Property) continue; + nextIndex = index; + nextIndexValid = true; + break; + } + + if (nextIndexValid) + return gridItems[nextIndex]; + + for (var index = 0; index <= startIndex - 1; index++) + { + if (gridItems[index].GridItemType != GridItemType.Property) continue; + nextIndex = index; + nextIndexValid = true; + break; + } + + return !nextIndexValid ? null : gridItems[nextIndex]; + } + + /// + /// Selects the next grid item in the property grid + /// using the currently selected grid item as a reference. + /// Does nothing if there is no next item. + /// + public void SelectNextGridItem() + { + var nextGridItem = FindNextGridItemProperty(SelectedGridItem); + if (nextGridItem != null) + SelectedGridItem = nextGridItem; + } + + /// + /// Selects the previous grid item in the property grid + /// using the currently selected grid item as a reference. + /// Does nothing if there is no previous item. + /// + public void SelectPreviousGridItem() + { + var previousGridItem = FindPreviousGridItemProperty(SelectedGridItem); + if (previousGridItem != null) + SelectedGridItem = previousGridItem; + } + + /// + /// Select the grid item whose backing property name + /// matches the given . + /// + /// + public void SelectGridItem(string propertyName) + { + var item = GetVisibleGridItems() + .FirstOrDefault(gridItem => gridItem.PropertyDescriptor?.Name == propertyName); + + if (item != null) + SelectedGridItem = item; + } + + public void ClearFilters() + { + _mBrowsableProperties = null; + _mHiddenProperties = null; + RefreshProperties(); + } + /// /// Build the list of the properties to be displayed in the PropertyGrid, following the filters defined the Browsable and Hidden properties. /// @@ -156,7 +308,24 @@ namespace mRemoteNG.UI.Controls.FilteredPropertyGrid foreach (Attribute attribute in _browsableAttributes) ShowAttribute(attribute); } - else + + // Display if necessary, some properties + if (_mBrowsableProperties != null && _mBrowsableProperties.Length > 0) + { + var allproperties = TypeDescriptor.GetProperties(_mWrapper.SelectedObject); + foreach (var propertyname in _mBrowsableProperties) + { + var property = allproperties[propertyname]; + + if (property == null) + throw new InvalidOperationException($"Property '{propertyname}' not found on object '{_mWrapper.GetClassName()}'"); + + ShowProperty(property); + } + } + + if ((_browsableAttributes == null || _browsableAttributes.Count == 0) && + (_mBrowsableProperties == null || _mBrowsableProperties.Length == 0)) { // Fill the collection with all the properties. var originalPropertyDescriptors = TypeDescriptor @@ -166,15 +335,12 @@ namespace mRemoteNG.UI.Controls.FilteredPropertyGrid foreach (PropertyDescriptor propertyDescriptor in originalPropertyDescriptors) _propertyDescriptors.Add(propertyDescriptor); - - // Remove from the list the attributes that mustn't be displayed. - if (_hiddenAttributes != null) - foreach (Attribute attribute in _hiddenAttributes) - HideAttribute(attribute); } - // Get all the properties of the SelectedObject - var allproperties = TypeDescriptor.GetProperties(_mWrapper.SelectedObject); + // Remove from the list the attributes that mustn't be displayed. + if (_hiddenAttributes != null) + foreach (Attribute attribute in _hiddenAttributes) + HideAttribute(attribute); // Hide if necessary, some properties if (_mHiddenProperties != null && _mHiddenProperties.Length > 0) @@ -182,33 +348,10 @@ namespace mRemoteNG.UI.Controls.FilteredPropertyGrid // Remove from the list the properties that mustn't be displayed. foreach (var propertyname in _mHiddenProperties) { - try - { - var property = allproperties[propertyname]; - // Remove from the list the property - HideProperty(property); - } - catch (Exception ex) - { - Runtime.MessageCollector.AddExceptionMessage("FilteredPropertyGrid: Could not hide Property.", - ex); - } - } - } + var property = _propertyDescriptors.FirstOrDefault(p => p.Name == propertyname); - // Display if necessary, some properties - if (_mBrowsableProperties != null && _mBrowsableProperties.Length > 0) - { - foreach (var propertyname in _mBrowsableProperties) - { - try - { - ShowProperty(allproperties[propertyname]); - } - catch (Exception ex) - { - Runtime.MessageCollector.AddExceptionMessage("FilteredPropertyGrid: Property not found", ex); - } + // Remove from the list the property + HideProperty(property); } } } diff --git a/mRemoteV1/UI/Window/ConfigWindow.cs b/mRemoteV1/UI/Window/ConfigWindow.cs index cc2114352..44a6e35f5 100644 --- a/mRemoteV1/UI/Window/ConfigWindow.cs +++ b/mRemoteV1/UI/Window/ConfigWindow.cs @@ -2,23 +2,16 @@ using System.Collections.Generic; using System.Diagnostics; using System.Drawing; -using System.IO; -using System.Linq; using System.Net.NetworkInformation; using System.Threading; using System.Windows.Forms; using mRemoteNG.App; using mRemoteNG.Connection; -using mRemoteNG.Connection.Protocol; -using mRemoteNG.Connection.Protocol.RDP; -using mRemoteNG.Connection.Protocol.VNC; using mRemoteNG.Container; using mRemoteNG.Messages; -using mRemoteNG.Security; using mRemoteNG.Themes; -using mRemoteNG.Tools; using mRemoteNG.Tree.Root; -using mRemoteNG.UI.Controls.FilteredPropertyGrid; +using mRemoteNG.UI.Controls.ConnectionInfoPropertyGrid; using WeifenLuo.WinFormsUI.Docking; @@ -40,18 +33,19 @@ namespace mRemoteNG.UI.Window private ToolStripMenuItem _propertyGridContextMenuShowHelpText; private ToolStripMenuItem _propertyGridContextMenuReset; private ToolStripSeparator _toolStripSeparator1; - private FilteredPropertyGrid _pGrid; + private ConnectionInfoPropertyGrid _pGrid; private ThemeManager _themeManager; - private AbstractConnectionRecord _selectedTreeNode; + private ConnectionInfo _selectedTreeNode; - public AbstractConnectionRecord SelectedTreeNode + public ConnectionInfo SelectedTreeNode { get => _selectedTreeNode; set { _selectedTreeNode = value; - SetPropertyGridObject(_selectedTreeNode); + _pGrid.SelectedConnectionInfo = value; + UpdateTopRow(); } } @@ -60,7 +54,7 @@ namespace mRemoteNG.UI.Window _components = new System.ComponentModel.Container(); Load += Config_Load; SystemColorsChanged += Config_SystemColorsChanged; - _pGrid = new FilteredPropertyGrid(); + _pGrid = new ConnectionInfoPropertyGrid(); _pGrid.PropertyValueChanged += pGrid_PropertyValueChanged; _pGrid.PropertySortChanged += pGrid_PropertySortChanged; PropertyGridContextMenu = new ContextMenuStrip(_components); @@ -209,57 +203,20 @@ namespace mRemoteNG.UI.Window #region Public Properties - public bool PropertiesVisible - { - get => _btnShowProperties.Checked; - set - { - _btnShowProperties.Checked = value; - if (!value) return; - _btnShowInheritance.Checked = false; - _btnShowDefaultInheritance.Checked = false; - _btnShowDefaultProperties.Checked = false; - } - } + public bool PropertiesVisible => _btnShowProperties.Checked; + public bool CanShowProperties => SelectedTreeNode != null; - public bool InheritanceVisible - { - get => _btnShowInheritance.Checked; - set - { - _btnShowInheritance.Checked = value; - if (!value) return; - _btnShowProperties.Checked = false; - _btnShowDefaultInheritance.Checked = false; - _btnShowDefaultProperties.Checked = false; - } - } + public bool InheritanceVisible => _btnShowInheritance.Checked; + public bool CanShowInheritance => !_pGrid.RootNodeSelected && + SelectedTreeNode != null && + _pGrid.SelectedConnectionInfo?.Parent != null && + !(_pGrid.SelectedConnectionInfo.Parent is RootNodeInfo); - public bool DefaultPropertiesVisible - { - get => _btnShowDefaultProperties.Checked; - set - { - _btnShowDefaultProperties.Checked = value; - if (!value) return; - _btnShowProperties.Checked = false; - _btnShowDefaultInheritance.Checked = false; - _btnShowInheritance.Checked = false; - } - } + public bool DefaultPropertiesVisible => _btnShowDefaultProperties.Checked; + public bool CanShowDefaultProperties => true; - public bool DefaultInheritanceVisible - { - get => _btnShowDefaultInheritance.Checked; - set - { - _btnShowDefaultInheritance.Checked = value; - if (!value) return; - _btnShowProperties.Checked = false; - _btnShowDefaultProperties.Checked = false; - _btnShowInheritance.Checked = false; - } - } + public bool DefaultInheritanceVisible => _btnShowDefaultInheritance.Checked; + public bool CanShowDefaultInheritance => true; /// /// A list of properties being shown for the current object. @@ -286,324 +243,53 @@ namespace mRemoteNG.UI.Window #region Public Methods + public void ShowConnectionProperties() + { + _pGrid.PropertyMode = PropertyMode.Connection; + UpdateTopRow(); + } + + public void ShowInheritanceProperties() + { + _pGrid.PropertyMode = PropertyMode.Inheritance; + UpdateTopRow(); + } + + public void ShowDefaultConnectionProperties() + { + _pGrid.PropertyMode = PropertyMode.DefaultConnection; + UpdateTopRow(); + } + + public void ShowDefaultInheritanceProperties() + { + _pGrid.PropertyMode = PropertyMode.DefaultInheritance; + UpdateTopRow(); + } + protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, Keys keyData) { // Main form handle command key events // Adapted from http://kiwigis.blogspot.com/2009/05/adding-tab-key-support-to-propertygrid.html - if ((keyData & Keys.KeyCode) != Keys.Tab) return base.ProcessCmdKey(ref msg, keyData); - var selectedItem = _pGrid.SelectedGridItem; - var gridRoot = selectedItem; - while (gridRoot.GridItemType != GridItemType.Root) - { - gridRoot = gridRoot.Parent; - } - - var gridItems = new List(); - FindChildGridItems(gridRoot, ref gridItems); - - if (!ContainsGridItemProperty(gridItems)) - return true; - - var newItem = selectedItem; + if ((keyData & Keys.KeyCode) != Keys.Tab) + return base.ProcessCmdKey(ref msg, keyData); // ReSharper disable once SwitchStatementMissingSomeCases switch (keyData) { case (Keys.Tab | Keys.Shift): - newItem = FindPreviousGridItemProperty(gridItems, selectedItem); + _pGrid.SelectNextGridItem(); break; case Keys.Tab: - newItem = FindNextGridItemProperty(gridItems, selectedItem); + _pGrid.SelectPreviousGridItem(); break; } - _pGrid.SelectedGridItem = newItem; - return true; // Handled } - - private void FindChildGridItems(GridItem item, ref List gridItems) - { - gridItems.Add(item); - - if (item.Expandable && !item.Expanded) return; - foreach (GridItem child in item.GridItems) - { - FindChildGridItems(child, ref gridItems); - } - } - - private bool ContainsGridItemProperty(IEnumerable gridItems) - { - return gridItems.Any(item => item.GridItemType == GridItemType.Property); - } - - private GridItem FindPreviousGridItemProperty(IList gridItems, GridItem startItem) - { - if (gridItems.Count == 0 || startItem == null) - return null; - - var startIndex = gridItems.IndexOf(startItem); - if (startItem.GridItemType == GridItemType.Property) - { - startIndex--; - if (startIndex < 0) - { - startIndex = gridItems.Count - 1; - } - } - - var previousIndex = 0; - var previousIndexValid = false; - for (var index = startIndex; index >= 0; index--) - { - if (gridItems[index].GridItemType != GridItemType.Property) continue; - previousIndex = index; - previousIndexValid = true; - break; - } - - if (previousIndexValid) - return gridItems[previousIndex]; - - for (var index = gridItems.Count - 1; index >= startIndex + 1; index--) - { - if (gridItems[index].GridItemType != GridItemType.Property) continue; - previousIndex = index; - previousIndexValid = true; - break; - } - - return !previousIndexValid ? null : gridItems[previousIndex]; - } - - private GridItem FindNextGridItemProperty(IList gridItems, GridItem startItem) - { - if (gridItems.Count == 0 || startItem == null) - return null; - - var startIndex = gridItems.IndexOf(startItem); - if (startItem.GridItemType == GridItemType.Property) - { - startIndex++; - if (startIndex >= gridItems.Count) - { - startIndex = 0; - } - } - - var nextIndex = 0; - var nextIndexValid = false; - for (var index = startIndex; index <= gridItems.Count - 1; index++) - { - if (gridItems[index].GridItemType != GridItemType.Property) continue; - nextIndex = index; - nextIndexValid = true; - break; - } - - if (nextIndexValid) - return gridItems[nextIndex]; - - for (var index = 0; index <= startIndex - 1; index++) - { - if (gridItems[index].GridItemType != GridItemType.Property) continue; - nextIndex = index; - nextIndexValid = true; - break; - } - - return !nextIndexValid ? null : gridItems[nextIndex]; - } - - private void SetPropertyGridObject(object propertyGridObject) - { - try - { - _btnShowProperties.Enabled = false; - _btnShowInheritance.Enabled = false; - _btnShowDefaultProperties.Enabled = false; - _btnShowDefaultInheritance.Enabled = false; - _btnIcon.Enabled = false; - _btnHostStatus.Enabled = false; - - _btnIcon.Image = null; - - if (propertyGridObject is ConnectionInfo gridObjectAsConnectionInfo) //CONNECTION INFO - { - if (propertyGridObject is ContainerInfo gridObjectAsContainerInfo) //CONTAINER - { - if (propertyGridObject is RootNodeInfo gridObjectAsRootNodeInfo) // ROOT - { - // ReSharper disable once SwitchStatementMissingSomeCases - switch (gridObjectAsRootNodeInfo.Type) - { - case RootNodeType.Connection: - PropertiesVisible = true; - DefaultPropertiesVisible = false; - _btnShowProperties.Enabled = true; - _btnShowInheritance.Enabled = false; - _btnShowDefaultProperties.Enabled = true; - _btnShowDefaultInheritance.Enabled = true; - _btnIcon.Enabled = false; - _btnHostStatus.Enabled = false; - break; - case RootNodeType.PuttySessions: - PropertiesVisible = true; - DefaultPropertiesVisible = false; - _btnShowProperties.Enabled = true; - _btnShowInheritance.Enabled = false; - _btnShowDefaultProperties.Enabled = false; - _btnShowDefaultInheritance.Enabled = false; - _btnIcon.Enabled = false; - _btnHostStatus.Enabled = false; - break; - } - - _pGrid.SelectedObject = propertyGridObject; - } - else - { - _pGrid.SelectedObject = propertyGridObject; - - _btnShowProperties.Enabled = true; - _btnShowInheritance.Enabled = - gridObjectAsContainerInfo.Parent != null && - !(gridObjectAsContainerInfo.Parent is RootNodeInfo); - _btnShowDefaultProperties.Enabled = false; - _btnShowDefaultInheritance.Enabled = false; - _btnIcon.Enabled = true; - _btnHostStatus.Enabled = false; - - PropertiesVisible = true; - } - } - else //NO CONTAINER - { - if (PropertiesVisible) //Properties selected - { - _pGrid.SelectedObject = propertyGridObject; - - _btnShowProperties.Enabled = true; - _btnShowInheritance.Enabled = - !(gridObjectAsConnectionInfo is PuttySessionInfo) && - gridObjectAsConnectionInfo.Parent != null && - !(gridObjectAsConnectionInfo.Parent is RootNodeInfo); - _btnShowDefaultProperties.Enabled = false; - _btnShowDefaultInheritance.Enabled = false; - _btnIcon.Enabled = true; - _btnHostStatus.Enabled = true; - } - else if (DefaultPropertiesVisible) //Defaults selected - { - _pGrid.SelectedObject = propertyGridObject; - - if (propertyGridObject is DefaultConnectionInfo) //Is the default connection - { - _btnShowProperties.Enabled = true; - _btnShowInheritance.Enabled = false; - _btnShowDefaultProperties.Enabled = true; - _btnShowDefaultInheritance.Enabled = true; - _btnIcon.Enabled = true; - _btnHostStatus.Enabled = false; - } - else //is not the default connection - { - _btnShowProperties.Enabled = true; - _btnShowInheritance.Enabled = true; - _btnShowDefaultProperties.Enabled = false; - _btnShowDefaultInheritance.Enabled = false; - _btnIcon.Enabled = true; - _btnHostStatus.Enabled = true; - - PropertiesVisible = true; - } - } - else if (InheritanceVisible) //Inheritance selected - { - _pGrid.SelectedObject = gridObjectAsConnectionInfo.Inheritance; - - _btnShowProperties.Enabled = true; - _btnShowInheritance.Enabled = true; - _btnShowDefaultProperties.Enabled = false; - _btnShowDefaultInheritance.Enabled = false; - _btnIcon.Enabled = true; - _btnHostStatus.Enabled = true; - } - else if (DefaultInheritanceVisible) //Default Inhertiance selected - { - _pGrid.SelectedObject = propertyGridObject; - - _btnShowProperties.Enabled = true; - _btnShowInheritance.Enabled = true; - _btnShowDefaultProperties.Enabled = false; - _btnShowDefaultInheritance.Enabled = false; - _btnIcon.Enabled = true; - _btnHostStatus.Enabled = true; - - PropertiesVisible = true; - } - } - - var conIcon = ConnectionIcon.FromString(Convert.ToString(gridObjectAsConnectionInfo.Icon)); - if (conIcon != null) - { - _btnIcon.Image = conIcon.ToBitmap(); - } - } - else if (propertyGridObject is ConnectionInfoInheritance) //INHERITANCE - { - _pGrid.SelectedObject = propertyGridObject; - - if (InheritanceVisible) - { - InheritanceVisible = true; - _btnShowProperties.Enabled = true; - _btnShowInheritance.Enabled = true; - _btnShowDefaultProperties.Enabled = false; - _btnShowDefaultInheritance.Enabled = false; - _btnIcon.Enabled = true; - _btnHostStatus.Enabled = - !((ConnectionInfo)((ConnectionInfoInheritance)propertyGridObject).Parent).IsContainer; - InheritanceVisible = true; - var conIcon = ConnectionIcon.FromString(Convert.ToString( - ((ConnectionInfo) - ((ConnectionInfoInheritance) - propertyGridObject).Parent) - .Icon)); - if (conIcon != null) - { - _btnIcon.Image = conIcon.ToBitmap(); - } - } - else if (DefaultInheritanceVisible) - { - _btnShowProperties.Enabled = true; - _btnShowInheritance.Enabled = false; - _btnShowDefaultProperties.Enabled = true; - _btnShowDefaultInheritance.Enabled = true; - _btnIcon.Enabled = false; - _btnHostStatus.Enabled = false; - - DefaultInheritanceVisible = true; - } - } - - ShowHideGridItems(); - SetHostStatus(propertyGridObject); - } - catch (Exception ex) - { - Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, - Language.strConfigPropertyGridObjectFailed + Environment.NewLine + - ex.Message, true); - } - } - #endregion #region Private Methods - private void ApplyLanguage() { _btnShowInheritance.Text = Language.strButtonInheritance; @@ -636,6 +322,86 @@ namespace mRemoteNG.UI.Window _themeManager.ActiveTheme.ExtendedPalette.getColor("List_Item_Disabled_Foreground"); } + private void UpdateTopRow() + { + try + { + // if we are on the show inheritance tab but it isn't a + // valid choice, switch to the properties tab + if (_pGrid.PropertyMode == PropertyMode.Inheritance && !CanShowInheritance) + { + ShowConnectionProperties(); + return; + } + + UpdatePropertiesButton(); + UpdateShowInheritanceButton(); + UpdateShowDefaultPropertiesButton(); + UpdateShowDefaultInheritanceButton(); + UpdateHostStatusButton(); + UpdateIconButton(); + } + catch (Exception ex) + { + Runtime.MessageCollector.AddMessage( + MessageClass.ErrorMsg, + Language.strConfigPropertyGridObjectFailed + Environment.NewLine + + ex.Message, true); + } + } + + private void UpdatePropertiesButton() + { + _btnShowProperties.Enabled = CanShowProperties; + _btnShowProperties.Checked = + _pGrid.PropertyMode == PropertyMode.Connection; + } + + private void UpdateShowInheritanceButton() + { + _btnShowInheritance.Enabled = CanShowInheritance; + _btnShowInheritance.Checked = + _pGrid.PropertyMode == PropertyMode.Inheritance; + } + + private void UpdateShowDefaultPropertiesButton() + { + _btnShowDefaultProperties.Enabled = CanShowDefaultProperties; + _btnShowDefaultProperties.Checked = + _pGrid.PropertyMode == PropertyMode.DefaultConnection; + } + + private void UpdateShowDefaultInheritanceButton() + { + _btnShowDefaultInheritance.Enabled = CanShowDefaultInheritance; + _btnShowDefaultInheritance.Checked = + _pGrid.PropertyMode == PropertyMode.DefaultInheritance; + } + + private void UpdateHostStatusButton() + { + _btnHostStatus.Enabled = + !_pGrid.RootNodeSelected && + !_pGrid.IsShowingDefaultProperties && + !(_pGrid.SelectedConnectionInfo is ContainerInfo); + + SetHostStatus(_pGrid.SelectedObject); + } + + private void UpdateIconButton() + { + _btnIcon.Enabled = + _pGrid.SelectedConnectionInfo != null && + !_pGrid.IsShowingDefaultProperties && + !_pGrid.RootNodeSelected; + + _btnIcon.Image = _btnIcon.Enabled + ? ConnectionIcon + .FromString(_pGrid.SelectedConnectionInfo?.Icon)? + .ToBitmap() + : null; + } + private void AddToolStripItems() { try @@ -709,10 +475,16 @@ namespace mRemoteNG.UI.Window { try { - UpdateConnectionInfoNode(e); - UpdateRootInfoNode(e); - UpdateInheritanceNode(); - ShowHideGridItems(); + if (e.ChangedItem.Label == Language.strPropertyNameIcon) + { + var conIcon = ConnectionIcon.FromString(_pGrid.SelectedConnectionInfo.Icon); + if (conIcon != null) + _btnIcon.Image = conIcon.ToBitmap(); + } + else if (e.ChangedItem.Label == Language.strPropertyNameAddress) + { + SetHostStatus(_pGrid.SelectedConnectionInfo); + } } catch (Exception ex) { @@ -722,829 +494,30 @@ namespace mRemoteNG.UI.Window } } - private void UpdateConnectionInfoNode(PropertyValueChangedEventArgs e) - { - Debug.WriteLine("update config"); - if (!(_pGrid.SelectedObject is ConnectionInfo selectedGridObject)) return; - if (e.ChangedItem.Label == Language.strPropertyNameProtocol) - { - selectedGridObject.SetDefaultPort(); - } - else if (e.ChangedItem.Label == Language.strPropertyNameName) - { - if (Settings.Default.SetHostnameLikeDisplayName) - { - var connectionInfo = selectedGridObject; - if (!string.IsNullOrEmpty(connectionInfo.Name)) - connectionInfo.Hostname = connectionInfo.Name; - } - } - else if (e.ChangedItem.Label == Language.strPropertyNameIcon) - { - var conIcon = ConnectionIcon.FromString(Convert.ToString(selectedGridObject.Icon)); - if (conIcon != null) - _btnIcon.Image = conIcon.ToBitmap(); - } - else if (e.ChangedItem.Label == Language.strPropertyNameAddress) - { - SetHostStatus(selectedGridObject); - } - - if (selectedGridObject is DefaultConnectionInfo) - DefaultConnectionInfo.Instance.SaveTo(Settings.Default, a => "ConDefault" + a); - } - - private void UpdateRootInfoNode(PropertyValueChangedEventArgs e) - { - if (!(_pGrid.SelectedObject is RootNodeInfo rootInfo)) - return; - - if (e.ChangedItem.PropertyDescriptor?.Name != "Password") - return; - - if (rootInfo.Password) - { - var passwordName = Settings.Default.UseSQLServer - ? Language.strSQLServer.TrimEnd(':') - : Path.GetFileName(Runtime.ConnectionsService.GetStartupConnectionFileName()); - - var password = MiscTools.PasswordDialog(passwordName); - - // operation cancelled, dont set a password - if (!password.Any() || password.First().Length == 0) - { - rootInfo.Password = false; - return; - } - - rootInfo.PasswordString = password.First().ConvertToUnsecureString(); - } - else - { - rootInfo.PasswordString = ""; - } - } - - private void UpdateInheritanceNode() - { - if (!(_pGrid.SelectedObject is DefaultConnectionInheritance)) return; - DefaultConnectionInheritance.Instance.SaveTo(Settings.Default, a => "InhDefault" + a); - } - private void pGrid_PropertySortChanged(object sender, EventArgs e) { if (_pGrid.PropertySort == PropertySort.CategorizedAlphabetical) _pGrid.PropertySort = PropertySort.Categorized; } - private void ShowHideGridItems() - { - try - { - var strHide = new List(); - if (_pGrid.SelectedObject is RootNodeInfo o) - { - var rootInfo = o; - if (rootInfo.Type == RootNodeType.PuttySessions) - { - strHide.Add("Password"); - } - - strHide.Add("CacheBitmaps"); - strHide.Add("Colors"); - strHide.Add("DisplayThemes"); - strHide.Add("DisplayWallpaper"); - strHide.Add("EnableFontSmoothing"); - strHide.Add("EnableDesktopComposition"); - strHide.Add("Domain"); - strHide.Add("ExtApp"); - strHide.Add("ICAEncryptionStrength"); - strHide.Add("RDGatewayDomain"); - strHide.Add("RDGatewayHostname"); - strHide.Add("RDGatewayPassword"); - strHide.Add("RDGatewayUsageMethod"); - strHide.Add("RDGatewayUseConnectionCredentials"); - strHide.Add("RDGatewayUsername"); - strHide.Add("RDPAuthenticationLevel"); - strHide.Add("RDPMinutesToIdleTimeout"); - strHide.Add("RDPAlertIdleTimeout"); - strHide.Add("LoadBalanceInfo"); - strHide.Add("RedirectDiskDrives"); - strHide.Add("RedirectKeys"); - strHide.Add("RedirectPorts"); - strHide.Add("RedirectPrinters"); - strHide.Add("RedirectClipboard"); - strHide.Add("RedirectSmartCards"); - strHide.Add("RedirectSound"); - strHide.Add("RedirectAudioCapture"); - strHide.Add("RenderingEngine"); - strHide.Add("Resolution"); - strHide.Add("AutomaticResize"); - strHide.Add("UseConsoleSession"); - strHide.Add("UseCredSsp"); - strHide.Add("VNCAuthMode"); - strHide.Add("VNCColors"); - strHide.Add("VNCCompression"); - strHide.Add("VNCEncoding"); - strHide.Add("VNCProxyIP"); - strHide.Add("VNCProxyPassword"); - strHide.Add("VNCProxyPort"); - strHide.Add("VNCProxyType"); - strHide.Add("VNCProxyUsername"); - strHide.Add("VNCSmartSizeMode"); - strHide.Add("VNCViewOnly"); - strHide.Add("Icon"); - strHide.Add("Panel"); - strHide.Add("Hostname"); - strHide.Add("Username"); - strHide.Add("Protocol"); - strHide.Add("Port"); - strHide.Add("PuttySession"); - strHide.Add("PreExtApp"); - strHide.Add("PostExtApp"); - strHide.Add("MacAddress"); - strHide.Add("UserField"); - strHide.Add("Favorite"); - strHide.Add("Description"); - strHide.Add("SoundQuality"); - strHide.Add("CredentialRecord"); - } - else if (_pGrid.SelectedObject is ConnectionInfo conI) - { - // ReSharper disable once SwitchStatementMissingSomeCases - switch (conI.Protocol) - { - case ProtocolType.RDP: - strHide.Add("ExtApp"); - strHide.Add("ICAEncryptionStrength"); - strHide.Add("PuttySession"); - strHide.Add("RenderingEngine"); - strHide.Add("VNCAuthMode"); - strHide.Add("VNCColors"); - strHide.Add("VNCCompression"); - strHide.Add("VNCEncoding"); - strHide.Add("VNCProxyIP"); - strHide.Add("VNCProxyPassword"); - strHide.Add("VNCProxyPort"); - strHide.Add("VNCProxyType"); - strHide.Add("VNCProxyUsername"); - strHide.Add("VNCSmartSizeMode"); - strHide.Add("VNCViewOnly"); - if (conI.RDPMinutesToIdleTimeout <= 0) - { - strHide.Add("RDPAlertIdleTimeout"); - } - - if (conI.RDGatewayUsageMethod == RdpProtocol.RDGatewayUsageMethod.Never) - { - strHide.Add("RDGatewayDomain"); - strHide.Add("RDGatewayHostname"); - strHide.Add("RDGatewayPassword"); - strHide.Add("RDGatewayUseConnectionCredentials"); - strHide.Add("RDGatewayUsername"); - } - else if (conI.RDGatewayUseConnectionCredentials == - RdpProtocol.RDGatewayUseConnectionCredentials.Yes) - { - strHide.Add("RDGatewayDomain"); - strHide.Add("RDGatewayPassword"); - strHide.Add("RDGatewayUsername"); - } - - if (!(conI.Resolution == RdpProtocol.RDPResolutions.FitToWindow || - conI.Resolution == RdpProtocol.RDPResolutions.Fullscreen)) - { - strHide.Add("AutomaticResize"); - } - - if (conI.RedirectSound != RdpProtocol.RDPSounds.BringToThisComputer) - { - strHide.Add("SoundQuality"); - } - - break; - case ProtocolType.VNC: - strHide.Add("CacheBitmaps"); - strHide.Add("Colors"); - strHide.Add("DisplayThemes"); - strHide.Add("DisplayWallpaper"); - strHide.Add("EnableFontSmoothing"); - strHide.Add("EnableDesktopComposition"); - strHide.Add("ExtApp"); - strHide.Add("ICAEncryptionStrength"); - strHide.Add("PuttySession"); - strHide.Add("RDGatewayDomain"); - strHide.Add("RDGatewayHostname"); - strHide.Add("RDGatewayPassword"); - strHide.Add("RDGatewayUsageMethod"); - strHide.Add("RDGatewayUseConnectionCredentials"); - strHide.Add("RDGatewayUsername"); - strHide.Add("RDPAuthenticationLevel"); - strHide.Add("RDPMinutesToIdleTimeout"); - strHide.Add("RDPAlertIdleTimeout"); - strHide.Add("LoadBalanceInfo"); - strHide.Add("RedirectDiskDrives"); - strHide.Add("RedirectKeys"); - strHide.Add("RedirectPorts"); - strHide.Add("RedirectPrinters"); - strHide.Add("RedirectClipboard"); - strHide.Add("RedirectSmartCards"); - strHide.Add("RedirectSound"); - strHide.Add("RedirectAudioCapture"); - strHide.Add("RenderingEngine"); - strHide.Add("Resolution"); - strHide.Add("AutomaticResize"); - strHide.Add("UseConsoleSession"); - strHide.Add("UseCredSsp"); - if (conI.VNCAuthMode == ProtocolVNC.AuthMode.AuthVNC) - { - strHide.Add("Username"); - strHide.Add("Domain"); - } - - if (conI.VNCProxyType == ProtocolVNC.ProxyType.ProxyNone) - { - strHide.Add("VNCProxyIP"); - strHide.Add("VNCProxyPassword"); - strHide.Add("VNCProxyPort"); - strHide.Add("VNCProxyUsername"); - } - - strHide.Add("SoundQuality"); - break; - case ProtocolType.SSH1: - strHide.Add("CacheBitmaps"); - strHide.Add("Colors"); - strHide.Add("DisplayThemes"); - strHide.Add("DisplayWallpaper"); - strHide.Add("EnableFontSmoothing"); - strHide.Add("EnableDesktopComposition"); - strHide.Add("Domain"); - strHide.Add("ExtApp"); - strHide.Add("ICAEncryptionStrength"); - strHide.Add("RDGatewayDomain"); - strHide.Add("RDGatewayHostname"); - strHide.Add("RDGatewayPassword"); - strHide.Add("RDGatewayUsageMethod"); - strHide.Add("RDGatewayUseConnectionCredentials"); - strHide.Add("RDGatewayUsername"); - strHide.Add("RDPAuthenticationLevel"); - strHide.Add("RDPMinutesToIdleTimeout"); - strHide.Add("RDPAlertIdleTimeout"); - strHide.Add("LoadBalanceInfo"); - strHide.Add("RedirectDiskDrives"); - strHide.Add("RedirectKeys"); - strHide.Add("RedirectPorts"); - strHide.Add("RedirectPrinters"); - strHide.Add("RedirectClipboard"); - strHide.Add("RedirectSmartCards"); - strHide.Add("RedirectSound"); - strHide.Add("RedirectAudioCapture"); - strHide.Add("RenderingEngine"); - strHide.Add("Resolution"); - strHide.Add("AutomaticResize"); - strHide.Add("UseConsoleSession"); - strHide.Add("UseCredSsp"); - strHide.Add("VNCAuthMode"); - strHide.Add("VNCColors"); - strHide.Add("VNCCompression"); - strHide.Add("VNCEncoding"); - strHide.Add("VNCProxyIP"); - strHide.Add("VNCProxyPassword"); - strHide.Add("VNCProxyPort"); - strHide.Add("VNCProxyType"); - strHide.Add("VNCProxyUsername"); - strHide.Add("VNCSmartSizeMode"); - strHide.Add("VNCViewOnly"); - strHide.Add("SoundQuality"); - break; - case ProtocolType.SSH2: - strHide.Add("CacheBitmaps"); - strHide.Add("Colors"); - strHide.Add("DisplayThemes"); - strHide.Add("DisplayWallpaper"); - strHide.Add("EnableFontSmoothing"); - strHide.Add("EnableDesktopComposition"); - strHide.Add("Domain"); - strHide.Add("ExtApp"); - strHide.Add("ICAEncryptionStrength"); - strHide.Add("RDGatewayDomain"); - strHide.Add("RDGatewayHostname"); - strHide.Add("RDGatewayPassword"); - strHide.Add("RDGatewayUsageMethod"); - strHide.Add("RDGatewayUseConnectionCredentials"); - strHide.Add("RDGatewayUsername"); - strHide.Add("RDPAuthenticationLevel"); - strHide.Add("RDPMinutesToIdleTimeout"); - strHide.Add("RDPAlertIdleTimeout"); - strHide.Add("LoadBalanceInfo"); - strHide.Add("RedirectDiskDrives"); - strHide.Add("RedirectKeys"); - strHide.Add("RedirectPorts"); - strHide.Add("RedirectPrinters"); - strHide.Add("RedirectClipboard"); - strHide.Add("RedirectSmartCards"); - strHide.Add("RedirectSound"); - strHide.Add("RedirectAudioCapture"); - strHide.Add("RenderingEngine"); - strHide.Add("Resolution"); - strHide.Add("AutomaticResize"); - strHide.Add("UseConsoleSession"); - strHide.Add("UseCredSsp"); - strHide.Add("VNCAuthMode"); - strHide.Add("VNCColors"); - strHide.Add("VNCCompression"); - strHide.Add("VNCEncoding"); - strHide.Add("VNCProxyIP"); - strHide.Add("VNCProxyPassword"); - strHide.Add("VNCProxyPort"); - strHide.Add("VNCProxyType"); - strHide.Add("VNCProxyUsername"); - strHide.Add("VNCSmartSizeMode"); - strHide.Add("VNCViewOnly"); - strHide.Add("SoundQuality"); - break; - case ProtocolType.Telnet: - strHide.Add("CacheBitmaps"); - strHide.Add("Colors"); - strHide.Add("DisplayThemes"); - strHide.Add("DisplayWallpaper"); - strHide.Add("EnableFontSmoothing"); - strHide.Add("EnableDesktopComposition"); - strHide.Add("Domain"); - strHide.Add("ExtApp"); - strHide.Add("ICAEncryptionStrength"); - strHide.Add("Password"); - strHide.Add("RDGatewayDomain"); - strHide.Add("RDGatewayHostname"); - strHide.Add("RDGatewayPassword"); - strHide.Add("RDGatewayUsageMethod"); - strHide.Add("RDGatewayUseConnectionCredentials"); - strHide.Add("RDGatewayUsername"); - strHide.Add("RDPAuthenticationLevel"); - strHide.Add("RDPMinutesToIdleTimeout"); - strHide.Add("RDPAlertIdleTimeout"); - strHide.Add("LoadBalanceInfo"); - strHide.Add("RedirectDiskDrives"); - strHide.Add("RedirectKeys"); - strHide.Add("RedirectPorts"); - strHide.Add("RedirectPrinters"); - strHide.Add("RedirectClipboard"); - strHide.Add("RedirectSmartCards"); - strHide.Add("RedirectSound"); - strHide.Add("RedirectAudioCapture"); - strHide.Add("RenderingEngine"); - strHide.Add("Resolution"); - strHide.Add("AutomaticResize"); - strHide.Add("UseConsoleSession"); - strHide.Add("UseCredSsp"); - strHide.Add("Username"); - strHide.Add("VNCAuthMode"); - strHide.Add("VNCColors"); - strHide.Add("VNCCompression"); - strHide.Add("VNCEncoding"); - strHide.Add("VNCProxyIP"); - strHide.Add("VNCProxyPassword"); - strHide.Add("VNCProxyPort"); - strHide.Add("VNCProxyType"); - strHide.Add("VNCProxyUsername"); - strHide.Add("VNCSmartSizeMode"); - strHide.Add("VNCViewOnly"); - strHide.Add("SoundQuality"); - break; - case ProtocolType.Rlogin: - strHide.Add("CacheBitmaps"); - strHide.Add("Colors"); - strHide.Add("DisplayThemes"); - strHide.Add("DisplayWallpaper"); - strHide.Add("EnableFontSmoothing"); - strHide.Add("EnableDesktopComposition"); - strHide.Add("Domain"); - strHide.Add("ExtApp"); - strHide.Add("ICAEncryptionStrength"); - strHide.Add("Password"); - strHide.Add("RDGatewayDomain"); - strHide.Add("RDGatewayHostname"); - strHide.Add("RDGatewayPassword"); - strHide.Add("RDGatewayUsageMethod"); - strHide.Add("RDGatewayUseConnectionCredentials"); - strHide.Add("RDGatewayUsername"); - strHide.Add("RDPAuthenticationLevel"); - strHide.Add("RDPMinutesToIdleTimeout"); - strHide.Add("RDPAlertIdleTimeout"); - strHide.Add("LoadBalanceInfo"); - strHide.Add("RedirectDiskDrives"); - strHide.Add("RedirectKeys"); - strHide.Add("RedirectPorts"); - strHide.Add("RedirectPrinters"); - strHide.Add("RedirectClipboard"); - strHide.Add("RedirectSmartCards"); - strHide.Add("RedirectSound"); - strHide.Add("RedirectAudioCapture"); - strHide.Add("RenderingEngine"); - strHide.Add("Resolution"); - strHide.Add("AutomaticResize"); - strHide.Add("UseConsoleSession"); - strHide.Add("UseCredSsp"); - strHide.Add("Username"); - strHide.Add("VNCAuthMode"); - strHide.Add("VNCColors"); - strHide.Add("VNCCompression"); - strHide.Add("VNCEncoding"); - strHide.Add("VNCProxyIP"); - strHide.Add("VNCProxyPassword"); - strHide.Add("VNCProxyPort"); - strHide.Add("VNCProxyType"); - strHide.Add("VNCProxyUsername"); - strHide.Add("VNCSmartSizeMode"); - strHide.Add("VNCViewOnly"); - strHide.Add("SoundQuality"); - break; - case ProtocolType.RAW: - strHide.Add("CacheBitmaps"); - strHide.Add("Colors"); - strHide.Add("DisplayThemes"); - strHide.Add("DisplayWallpaper"); - strHide.Add("EnableFontSmoothing"); - strHide.Add("EnableDesktopComposition"); - strHide.Add("Domain"); - strHide.Add("ExtApp"); - strHide.Add("ICAEncryptionStrength"); - strHide.Add("Password"); - strHide.Add("RDGatewayDomain"); - strHide.Add("RDGatewayHostname"); - strHide.Add("RDGatewayPassword"); - strHide.Add("RDGatewayUsageMethod"); - strHide.Add("RDGatewayUseConnectionCredentials"); - strHide.Add("RDGatewayUsername"); - strHide.Add("RDPAuthenticationLevel"); - strHide.Add("RDPMinutesToIdleTimeout"); - strHide.Add("RDPAlertIdleTimeout"); - strHide.Add("LoadBalanceInfo"); - strHide.Add("RedirectDiskDrives"); - strHide.Add("RedirectKeys"); - strHide.Add("RedirectPorts"); - strHide.Add("RedirectPrinters"); - strHide.Add("RedirectClipboard"); - strHide.Add("RedirectSmartCards"); - strHide.Add("RedirectSound"); - strHide.Add("RedirectAudioCapture"); - strHide.Add("RenderingEngine"); - strHide.Add("Resolution"); - strHide.Add("AutomaticResize"); - strHide.Add("UseConsoleSession"); - strHide.Add("UseCredSsp"); - strHide.Add("Username"); - strHide.Add("VNCAuthMode"); - strHide.Add("VNCColors"); - strHide.Add("VNCCompression"); - strHide.Add("VNCEncoding"); - strHide.Add("VNCProxyIP"); - strHide.Add("VNCProxyPassword"); - strHide.Add("VNCProxyPort"); - strHide.Add("VNCProxyType"); - strHide.Add("VNCProxyUsername"); - strHide.Add("VNCSmartSizeMode"); - strHide.Add("VNCViewOnly"); - strHide.Add("SoundQuality"); - break; - case ProtocolType.HTTP: - case ProtocolType.HTTPS: - strHide.Add("CacheBitmaps"); - strHide.Add("Colors"); - strHide.Add("DisplayThemes"); - strHide.Add("DisplayWallpaper"); - strHide.Add("EnableFontSmoothing"); - strHide.Add("EnableDesktopComposition"); - strHide.Add("Domain"); - strHide.Add("ExtApp"); - strHide.Add("ICAEncryptionStrength"); - strHide.Add("PuttySession"); - strHide.Add("RDGatewayDomain"); - strHide.Add("RDGatewayHostname"); - strHide.Add("RDGatewayPassword"); - strHide.Add("RDGatewayUsageMethod"); - strHide.Add("RDGatewayUseConnectionCredentials"); - strHide.Add("RDGatewayUsername"); - strHide.Add("RDPAuthenticationLevel"); - strHide.Add("RDPMinutesToIdleTimeout"); - strHide.Add("RDPAlertIdleTimeout"); - strHide.Add("LoadBalanceInfo"); - strHide.Add("RedirectDiskDrives"); - strHide.Add("RedirectKeys"); - strHide.Add("RedirectPorts"); - strHide.Add("RedirectPrinters"); - strHide.Add("RedirectClipboard"); - strHide.Add("RedirectSmartCards"); - strHide.Add("RedirectSound"); - strHide.Add("RedirectAudioCapture"); - strHide.Add("Resolution"); - strHide.Add("AutomaticResize"); - strHide.Add("UseConsoleSession"); - strHide.Add("UseCredSsp"); - strHide.Add("VNCAuthMode"); - strHide.Add("VNCColors"); - strHide.Add("VNCCompression"); - strHide.Add("VNCEncoding"); - strHide.Add("VNCProxyIP"); - strHide.Add("VNCProxyPassword"); - strHide.Add("VNCProxyPort"); - strHide.Add("VNCProxyType"); - strHide.Add("VNCProxyUsername"); - strHide.Add("VNCSmartSizeMode"); - strHide.Add("VNCViewOnly"); - strHide.Add("SoundQuality"); - break; - case ProtocolType.ICA: - strHide.Add("DisplayThemes"); - strHide.Add("DisplayWallpaper"); - strHide.Add("EnableFontSmoothing"); - strHide.Add("EnableDesktopComposition"); - strHide.Add("ExtApp"); - strHide.Add("Port"); - strHide.Add("PuttySession"); - strHide.Add("RDGatewayDomain"); - strHide.Add("RDGatewayHostname"); - strHide.Add("RDGatewayPassword"); - strHide.Add("RDGatewayUsageMethod"); - strHide.Add("RDGatewayUseConnectionCredentials"); - strHide.Add("RDGatewayUsername"); - strHide.Add("RDPAuthenticationLevel"); - strHide.Add("RDPMinutesToIdleTimeout"); - strHide.Add("RDPAlertIdleTimeout"); - strHide.Add("LoadBalanceInfo"); - strHide.Add("RedirectDiskDrives"); - strHide.Add("RedirectKeys"); - strHide.Add("RedirectPorts"); - strHide.Add("RedirectPrinters"); - strHide.Add("RedirectClipboard"); - strHide.Add("RedirectSmartCards"); - strHide.Add("RedirectSound"); - strHide.Add("RedirectAudioCapture"); - strHide.Add("RenderingEngine"); - strHide.Add("AutomaticResize"); - strHide.Add("UseConsoleSession"); - strHide.Add("UseCredSsp"); - strHide.Add("VNCAuthMode"); - strHide.Add("VNCColors"); - strHide.Add("VNCCompression"); - strHide.Add("VNCEncoding"); - strHide.Add("VNCProxyIP"); - strHide.Add("VNCProxyPassword"); - strHide.Add("VNCProxyPort"); - strHide.Add("VNCProxyType"); - strHide.Add("VNCProxyUsername"); - strHide.Add("VNCSmartSizeMode"); - strHide.Add("VNCViewOnly"); - strHide.Add("SoundQuality"); - break; - case ProtocolType.IntApp: - strHide.Add("CacheBitmaps"); - strHide.Add("Colors"); - strHide.Add("DisplayThemes"); - strHide.Add("DisplayWallpaper"); - strHide.Add("EnableFontSmoothing"); - strHide.Add("EnableDesktopComposition"); - strHide.Add("ICAEncryptionStrength"); - strHide.Add("PuttySession"); - strHide.Add("RDGatewayDomain"); - strHide.Add("RDGatewayHostname"); - strHide.Add("RDGatewayPassword"); - strHide.Add("RDGatewayUsageMethod"); - strHide.Add("RDGatewayUseConnectionCredentials"); - strHide.Add("RDGatewayUsername"); - strHide.Add("RDPAuthenticationLevel"); - strHide.Add("RDPMinutesToIdleTimeout"); - strHide.Add("RDPAlertIdleTimeout"); - strHide.Add("LoadBalanceInfo"); - strHide.Add("RedirectDiskDrives"); - strHide.Add("RedirectKeys"); - strHide.Add("RedirectPorts"); - strHide.Add("RedirectPrinters"); - strHide.Add("RedirectClipboard"); - strHide.Add("RedirectSmartCards"); - strHide.Add("RedirectSound"); - strHide.Add("RedirectAudioCapture"); - strHide.Add("RenderingEngine"); - strHide.Add("Resolution"); - strHide.Add("AutomaticResize"); - strHide.Add("UseConsoleSession"); - strHide.Add("UseCredSsp"); - strHide.Add("VNCAuthMode"); - strHide.Add("VNCColors"); - strHide.Add("VNCCompression"); - strHide.Add("VNCEncoding"); - strHide.Add("VNCProxyIP"); - strHide.Add("VNCProxyPassword"); - strHide.Add("VNCProxyPort"); - strHide.Add("VNCProxyType"); - strHide.Add("VNCProxyUsername"); - strHide.Add("VNCSmartSizeMode"); - strHide.Add("VNCViewOnly"); - strHide.Add("SoundQuality"); - break; - } - - if (!(conI is DefaultConnectionInfo)) - { - if (conI.Inheritance.CacheBitmaps) - strHide.Add("CacheBitmaps"); - if (conI.Inheritance.Colors) - strHide.Add("Colors"); - if (conI.Inheritance.Description) - strHide.Add("Description"); - if (conI.Inheritance.DisplayThemes) - strHide.Add("DisplayThemes"); - if (conI.Inheritance.DisplayWallpaper) - strHide.Add("DisplayWallpaper"); - if (conI.Inheritance.EnableFontSmoothing) - strHide.Add("EnableFontSmoothing"); - if (conI.Inheritance.EnableDesktopComposition) - strHide.Add("EnableDesktopComposition"); - if (conI.Inheritance.Domain) - strHide.Add("Domain"); - if (conI.Inheritance.Icon) - strHide.Add("Icon"); - if (conI.Inheritance.Password) - strHide.Add("Password"); - if (conI.Inheritance.Port) - strHide.Add("Port"); - if (conI.Inheritance.Protocol) - strHide.Add("Protocol"); - if (conI.Inheritance.PuttySession) - strHide.Add("PuttySession"); - if (conI.Inheritance.RedirectDiskDrives) - strHide.Add("RedirectDiskDrives"); - if (conI.Inheritance.RedirectKeys) - strHide.Add("RedirectKeys"); - if (conI.Inheritance.RedirectPorts) - strHide.Add("RedirectPorts"); - if (conI.Inheritance.RedirectPrinters) - strHide.Add("RedirectPrinters"); - if (conI.Inheritance.RedirectClipboard) - strHide.Add("RedirectClipboard"); - if (conI.Inheritance.RedirectSmartCards) - strHide.Add("RedirectSmartCards"); - if (conI.Inheritance.RedirectSound) - strHide.Add("RedirectSound"); - if (conI.Inheritance.RedirectAudioCapture) - strHide.Add("RedirectAudioCapture"); - if (conI.Inheritance.Resolution) - strHide.Add("Resolution"); - if (conI.Inheritance.AutomaticResize) - strHide.Add("AutomaticResize"); - if (conI.Inheritance.UseConsoleSession) - strHide.Add("UseConsoleSession"); - if (conI.Inheritance.UseCredSsp) - strHide.Add("UseCredSsp"); - if (conI.Inheritance.RenderingEngine) - strHide.Add("RenderingEngine"); - if (conI.Inheritance.ICAEncryptionStrength) - strHide.Add("ICAEncryptionStrength"); - if (conI.Inheritance.RDPAuthenticationLevel) - strHide.Add("RDPAuthenticationLevel"); - if (conI.Inheritance.RDPMinutesToIdleTimeout) - strHide.Add("RDPMinutesToIdleTimeout"); - if (conI.Inheritance.RDPAlertIdleTimeout) - strHide.Add("RDPAlertIdleTimeout"); - if (conI.Inheritance.LoadBalanceInfo) - strHide.Add("LoadBalanceInfo"); - if (conI.Inheritance.Username) - strHide.Add("Username"); - if (conI.Inheritance.Panel) - strHide.Add("Panel"); - if (conI.IsContainer) - strHide.Add("Hostname"); - if (conI.Inheritance.PreExtApp) - strHide.Add("PreExtApp"); - if (conI.Inheritance.PostExtApp) - strHide.Add("PostExtApp"); - if (conI.Inheritance.MacAddress) - strHide.Add("MacAddress"); - if (conI.Inheritance.UserField) - strHide.Add("UserField"); - if (conI.Inheritance.Favorite) - strHide.Add("Favorite"); - if (conI.Inheritance.VNCAuthMode) - strHide.Add("VNCAuthMode"); - if (conI.Inheritance.VNCColors) - strHide.Add("VNCColors"); - if (conI.Inheritance.VNCCompression) - strHide.Add("VNCCompression"); - if (conI.Inheritance.VNCEncoding) - strHide.Add("VNCEncoding"); - if (conI.Inheritance.VNCProxyIP) - strHide.Add("VNCProxyIP"); - if (conI.Inheritance.VNCProxyPassword) - strHide.Add("VNCProxyPassword"); - if (conI.Inheritance.VNCProxyPort) - strHide.Add("VNCProxyPort"); - if (conI.Inheritance.VNCProxyType) - strHide.Add("VNCProxyType"); - if (conI.Inheritance.VNCProxyUsername) - strHide.Add("VNCProxyUsername"); - if (conI.Inheritance.VNCViewOnly) - strHide.Add("VNCViewOnly"); - if (conI.Inheritance.VNCSmartSizeMode) - strHide.Add("VNCSmartSizeMode"); - if (conI.Inheritance.ExtApp) - strHide.Add("ExtApp"); - if (conI.Inheritance.RDGatewayUsageMethod) - strHide.Add("RDGatewayUsageMethod"); - if (conI.Inheritance.RDGatewayHostname) - strHide.Add("RDGatewayHostname"); - if (conI.Inheritance.RDGatewayUsername) - strHide.Add("RDGatewayUsername"); - if (conI.Inheritance.RDGatewayPassword) - strHide.Add("RDGatewayPassword"); - if (conI.Inheritance.RDGatewayDomain) - strHide.Add("RDGatewayDomain"); - if (conI.Inheritance.RDGatewayUseConnectionCredentials) - strHide.Add("RDGatewayUseConnectionCredentials"); - if (conI.Inheritance.RDGatewayHostname) - strHide.Add("RDGatewayHostname"); - if (conI.Inheritance.SoundQuality) - strHide.Add("SoundQuality"); - } - else - { - strHide.Add("Hostname"); - strHide.Add("Name"); - } - } - - _pGrid.HiddenProperties = strHide.ToArray(); - _pGrid.Refresh(); - } - catch (Exception ex) - { - Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, - Language.strConfigPropertyGridHideItemsFailed + - Environment.NewLine + ex.Message, true); - } - } - private void btnShowProperties_Click(object sender, EventArgs e) { - if (_pGrid.SelectedObject is ConnectionInfoInheritance o) - { - if (_pGrid.SelectedObject is DefaultConnectionInheritance) - { - PropertiesVisible = true; - InheritanceVisible = false; - DefaultPropertiesVisible = false; - DefaultInheritanceVisible = false; - SetPropertyGridObject((RootNodeInfo)_selectedTreeNode); - } - else - { - PropertiesVisible = true; - InheritanceVisible = false; - DefaultPropertiesVisible = false; - DefaultInheritanceVisible = false; - SetPropertyGridObject(o.Parent); - } - } - else if (_pGrid.SelectedObject is ConnectionInfo) - { - if (!((ConnectionInfo)_pGrid.SelectedObject).IsDefault) return; - PropertiesVisible = true; - InheritanceVisible = false; - DefaultPropertiesVisible = false; - DefaultInheritanceVisible = false; - SetPropertyGridObject((RootNodeInfo)_selectedTreeNode); - } - } - - private void btnShowDefaultProperties_Click(object sender, EventArgs e) - { - if (!(_pGrid.SelectedObject is RootNodeInfo) && - !(_pGrid.SelectedObject is ConnectionInfoInheritance)) return; - PropertiesVisible = false; - InheritanceVisible = false; - DefaultPropertiesVisible = true; - DefaultInheritanceVisible = false; - SetPropertyGridObject(DefaultConnectionInfo.Instance); + ShowConnectionProperties(); } private void btnShowInheritance_Click(object sender, EventArgs e) { - if (!(_pGrid.SelectedObject is ConnectionInfo)) return; - PropertiesVisible = false; - InheritanceVisible = true; - DefaultPropertiesVisible = false; - DefaultInheritanceVisible = false; - SetPropertyGridObject(((ConnectionInfo)_pGrid.SelectedObject).Inheritance); + ShowInheritanceProperties(); + } + + private void btnShowDefaultProperties_Click(object sender, EventArgs e) + { + ShowDefaultConnectionProperties(); } private void btnShowDefaultInheritance_Click(object sender, EventArgs e) { - if (!(_pGrid.SelectedObject is RootNodeInfo) && !(_pGrid.SelectedObject is ConnectionInfo)) return; - PropertiesVisible = false; - InheritanceVisible = false; - DefaultPropertiesVisible = false; - DefaultInheritanceVisible = true; - SetPropertyGridObject(DefaultConnectionInheritance.Instance); + ShowDefaultInheritanceProperties(); } private void btnHostStatus_Click(object sender, EventArgs e) diff --git a/mRemoteV1/mRemoteV1.csproj b/mRemoteV1/mRemoteV1.csproj index 90515366b..ff8228f84 100644 --- a/mRemoteV1/mRemoteV1.csproj +++ b/mRemoteV1/mRemoteV1.csproj @@ -284,6 +284,7 @@ Component + @@ -350,6 +351,7 @@ + @@ -415,6 +417,13 @@ Component + + Component + + + ConnectionInfoPropertyGrid.cs + + Component @@ -1104,16 +1113,16 @@ - Always + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest @@ -1247,13 +1256,13 @@ - Always + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest