Merge pull request #2869 from mRemoteNG/copilot/fix-color-selection-for-panel-tabs

Fix Color property converter and add missing Display category attributes for TabColor
This commit is contained in:
Dimitrij
2025-10-07 22:31:30 +01:00
committed by GitHub
4 changed files with 122 additions and 5 deletions

View File

@@ -160,15 +160,18 @@ 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.LocalizedDisplayName(nameof(Language.TabColor)),
LocalizedAttributes.LocalizedDescription(nameof(Language.PropertyDescriptionTabColor)),
TypeConverter(typeof(MiscTools.TabColorConverter))]
[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
{
get => GetPropertyValue("TabColor", _tabColor);

View File

@@ -55,7 +55,9 @@ namespace mRemoteNG.Connection
LocalizedAttributes.LocalizedDescriptionInherit(nameof(Language.PropertyDescriptionColor)),
TypeConverter(typeof(MiscTools.YesNoTypeConverter))]
public bool Color { get; set; }
[LocalizedAttributes.LocalizedDisplayNameInherit(nameof(Language.TabColor)),
[LocalizedAttributes.LocalizedCategory(nameof(Language.Display), 2),
LocalizedAttributes.LocalizedDisplayNameInherit(nameof(Language.TabColor)),
LocalizedAttributes.LocalizedDescriptionInherit(nameof(Language.PropertyDescriptionTabColor)),
TypeConverter(typeof(MiscTools.YesNoTypeConverter))]
public bool TabColor { get; set; }

View File

@@ -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");
}
}
}

View File

@@ -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"));
}
}
}