diff --git a/mRemoteNG/Connection/AbstractConnectionRecord.cs b/mRemoteNG/Connection/AbstractConnectionRecord.cs index c354a553d..5e35d375a 100644 --- a/mRemoteNG/Connection/AbstractConnectionRecord.cs +++ b/mRemoteNG/Connection/AbstractConnectionRecord.cs @@ -160,13 +160,17 @@ namespace mRemoteNG.Connection LocalizedAttributes.LocalizedDisplayName(nameof(Language.Color)), LocalizedAttributes.LocalizedDescription(nameof(Language.PropertyDescriptionColor)), Editor(typeof(System.Drawing.Design.ColorEditor), typeof(System.Drawing.Design.UITypeEditor)), - TypeConverter(typeof(System.Drawing.ColorConverter))] + TypeConverter(typeof(MiscTools.TabColorConverter))] public virtual string Color { get => GetPropertyValue("Color", _color); set => SetField(ref _color, value, "Color"); + } + + [LocalizedAttributes.LocalizedCategory(nameof(Language.Display)), LocalizedAttributes.LocalizedDisplayName(nameof(Language.TabColor)), LocalizedAttributes.LocalizedDescription(nameof(Language.PropertyDescriptionTabColor)), + Editor(typeof(System.Drawing.Design.ColorEditor), typeof(System.Drawing.Design.UITypeEditor)), TypeConverter(typeof(MiscTools.TabColorConverter))] public virtual string TabColor { diff --git a/mRemoteNG/Connection/ConnectionInfoInheritance.cs b/mRemoteNG/Connection/ConnectionInfoInheritance.cs index 1e0a28485..278531520 100644 --- a/mRemoteNG/Connection/ConnectionInfoInheritance.cs +++ b/mRemoteNG/Connection/ConnectionInfoInheritance.cs @@ -55,6 +55,8 @@ namespace mRemoteNG.Connection LocalizedAttributes.LocalizedDescriptionInherit(nameof(Language.PropertyDescriptionColor)), TypeConverter(typeof(MiscTools.YesNoTypeConverter))] public bool Color { get; set; } + + [LocalizedAttributes.LocalizedCategory(nameof(Language.Display), 2), LocalizedAttributes.LocalizedDisplayNameInherit(nameof(Language.TabColor)), LocalizedAttributes.LocalizedDescriptionInherit(nameof(Language.PropertyDescriptionTabColor)), TypeConverter(typeof(MiscTools.YesNoTypeConverter))] diff --git a/mRemoteNGTests/Connection/ColorPropertyAttributeTests.cs b/mRemoteNGTests/Connection/ColorPropertyAttributeTests.cs new file mode 100644 index 000000000..320dc2021 --- /dev/null +++ b/mRemoteNGTests/Connection/ColorPropertyAttributeTests.cs @@ -0,0 +1,94 @@ +using System; +using System.ComponentModel; +using System.Linq; +using System.Reflection; +using mRemoteNG.Connection; +using mRemoteNG.Tools; +using NUnit.Framework; + +namespace mRemoteNGTests.Connection +{ + [TestFixture] + public class ColorPropertyAttributeTests + { + [Test] + public void ColorPropertyHasTabColorConverter() + { + // Get the Color property + var propertyInfo = typeof(ConnectionInfo).GetProperty("Color"); + Assert.That(propertyInfo, Is.Not.Null, "Color property should exist"); + + // Get the TypeConverter attribute + var typeConverterAttr = propertyInfo.GetCustomAttributes(typeof(TypeConverterAttribute), true) + .FirstOrDefault() as TypeConverterAttribute; + + Assert.That(typeConverterAttr, Is.Not.Null, "Color property should have TypeConverter attribute"); + Assert.That(typeConverterAttr.ConverterTypeName, Does.Contain("TabColorConverter"), + "Color property should use TabColorConverter"); + } + + [Test] + public void TabColorPropertyHasTabColorConverter() + { + // Get the TabColor property + var propertyInfo = typeof(ConnectionInfo).GetProperty("TabColor"); + Assert.That(propertyInfo, Is.Not.Null, "TabColor property should exist"); + + // Get the TypeConverter attribute + var typeConverterAttr = propertyInfo.GetCustomAttributes(typeof(TypeConverterAttribute), true) + .FirstOrDefault() as TypeConverterAttribute; + + Assert.That(typeConverterAttr, Is.Not.Null, "TabColor property should have TypeConverter attribute"); + Assert.That(typeConverterAttr.ConverterTypeName, Does.Contain("TabColorConverter"), + "TabColor property should use TabColorConverter"); + } + + [Test] + public void ColorPropertyHasCategoryAttribute() + { + var propertyInfo = typeof(ConnectionInfo).GetProperty("Color"); + Assert.That(propertyInfo, Is.Not.Null); + + var categoryAttr = propertyInfo.GetCustomAttributes(typeof(CategoryAttribute), true) + .FirstOrDefault() as CategoryAttribute; + + Assert.That(categoryAttr, Is.Not.Null, "Color property should have Category attribute"); + } + + [Test] + public void TabColorPropertyHasCategoryAttribute() + { + var propertyInfo = typeof(ConnectionInfo).GetProperty("TabColor"); + Assert.That(propertyInfo, Is.Not.Null); + + var categoryAttr = propertyInfo.GetCustomAttributes(typeof(CategoryAttribute), true) + .FirstOrDefault() as CategoryAttribute; + + Assert.That(categoryAttr, Is.Not.Null, "TabColor property should have Category attribute"); + } + + [Test] + public void ColorInheritancePropertyHasCategoryAttribute() + { + var propertyInfo = typeof(ConnectionInfoInheritance).GetProperty("Color"); + Assert.That(propertyInfo, Is.Not.Null); + + var categoryAttr = propertyInfo.GetCustomAttributes(typeof(CategoryAttribute), true) + .FirstOrDefault() as CategoryAttribute; + + Assert.That(categoryAttr, Is.Not.Null, "Color inheritance property should have Category attribute"); + } + + [Test] + public void TabColorInheritancePropertyHasCategoryAttribute() + { + var propertyInfo = typeof(ConnectionInfoInheritance).GetProperty("TabColor"); + Assert.That(propertyInfo, Is.Not.Null); + + var categoryAttr = propertyInfo.GetCustomAttributes(typeof(CategoryAttribute), true) + .FirstOrDefault() as CategoryAttribute; + + Assert.That(categoryAttr, Is.Not.Null, "TabColor inheritance property should have Category attribute"); + } + } +} diff --git a/mRemoteNGTests/Tools/TabColorConverterTests.cs b/mRemoteNGTests/Tools/TabColorConverterTests.cs index 36c089d5e..40a1ecec0 100644 --- a/mRemoteNGTests/Tools/TabColorConverterTests.cs +++ b/mRemoteNGTests/Tools/TabColorConverterTests.cs @@ -144,5 +144,23 @@ namespace mRemoteNGTests.Tools var result = _converter.GetStandardValuesExclusive(null); Assert.That(result, Is.False); } + + [Test] + public void ConvertFromColorObjectDoesNotThrowException() + { + // This test verifies the fix for the "Object of type 'System.Drawing.Color' cannot be converted to type 'System.String'" error + var color = Color.FromArgb(255, 100, 150, 200); + Assert.DoesNotThrow(() => _converter.ConvertFrom(color)); + } + + [Test] + public void ColorPropertyUsesTabColorConverter() + { + // This test verifies that the Color property can properly handle Color objects + // by using TabColorConverter instead of System.Drawing.ColorConverter + var color = Color.Blue; + var result = _converter.ConvertFrom(color); + Assert.That(result, Is.EqualTo("Blue")); + } } }