Add TabColor property to connection info and implement tab coloring

Co-authored-by: Kvarkas <3611964+Kvarkas@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-10-07 19:49:32 +00:00
parent 0f819ade56
commit 3c6a485647
7 changed files with 60 additions and 2 deletions

View File

@@ -42,6 +42,7 @@ namespace mRemoteNG.Config.Serializers.ConnectionSerializers.Xml
element.Add(new XAttribute("Descr", connectionInfo.Description));
element.Add(new XAttribute("Icon", connectionInfo.Icon));
element.Add(new XAttribute("Panel", connectionInfo.Panel));
element.Add(new XAttribute("TabColor", connectionInfo.TabColor));
element.Add(new XAttribute("Id", connectionInfo.ConstantID));
if (!Runtime.UseCredentialManager)
@@ -187,6 +188,8 @@ namespace mRemoteNG.Config.Serializers.ConnectionSerializers.Xml
element.Add(new XAttribute("InheritIcon", inheritance.Icon.ToString().ToLowerInvariant()));
if (inheritance.Panel)
element.Add(new XAttribute("InheritPanel", inheritance.Panel.ToString().ToLowerInvariant()));
if (inheritance.TabColor)
element.Add(new XAttribute("InheritTabColor", inheritance.TabColor.ToString().ToLowerInvariant()));
if (inheritance.Password)
element.Add(new XAttribute("InheritPassword", inheritance.Password.ToString().ToLowerInvariant()));
if (inheritance.Port)

View File

@@ -328,6 +328,7 @@ namespace mRemoteNG.Config.Serializers.ConnectionSerializers.Xml
connectionInfo.Inheritance.DisplayWallpaper = xmlnode.GetAttributeAsBool("InheritDisplayWallpaper");
connectionInfo.Inheritance.Icon = xmlnode.GetAttributeAsBool("InheritIcon");
connectionInfo.Inheritance.Panel = xmlnode.GetAttributeAsBool("InheritPanel");
connectionInfo.Inheritance.TabColor = xmlnode.GetAttributeAsBool("InheritTabColor");
connectionInfo.Inheritance.Port = xmlnode.GetAttributeAsBool("InheritPort");
connectionInfo.Inheritance.Protocol = xmlnode.GetAttributeAsBool("InheritProtocol");
connectionInfo.Inheritance.PuttySession = xmlnode.GetAttributeAsBool("InheritPuttySession");
@@ -350,6 +351,7 @@ namespace mRemoteNG.Config.Serializers.ConnectionSerializers.Xml
connectionInfo.Icon = xmlnode.GetAttributeAsString("Icon");
connectionInfo.Panel = xmlnode.GetAttributeAsString("Panel");
connectionInfo.TabColor = xmlnode.GetAttributeAsString("TabColor");
}
else
{

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using mRemoteNG.Connection.Protocol;
using mRemoteNG.Connection.Protocol.Http;
using mRemoteNG.Connection.Protocol.RDP;
@@ -22,6 +23,7 @@ namespace mRemoteNG.Connection
private string _description;
private string _icon;
private string _panel;
private string _tabColor;
private string _hostname;
private ExternalAddressProvider _externalAddressProvider;
@@ -153,6 +155,16 @@ namespace mRemoteNG.Connection
set => SetField(ref _panel, value, "Panel");
}
[LocalizedAttributes.LocalizedCategory(nameof(Language.Display)),
LocalizedAttributes.LocalizedDisplayName(nameof(Language.TabColor)),
LocalizedAttributes.LocalizedDescription(nameof(Language.PropertyDescriptionTabColor)),
TypeConverter(typeof(ColorConverter))]
public virtual string TabColor
{
get => GetPropertyValue("TabColor", _tabColor);
set => SetField(ref _tabColor, value, "TabColor");
}
#endregion
#region Connection

View File

@@ -289,6 +289,7 @@ namespace mRemoteNG.Connection
Description = Settings.Default.ConDefaultDescription;
Icon = Settings.Default.ConDefaultIcon;
Panel = Language.General;
TabColor = "";
}
private void SetConnectionDefaults()

View File

@@ -50,6 +50,12 @@ namespace mRemoteNG.Connection
TypeConverter(typeof(MiscTools.YesNoTypeConverter))]
public bool Panel { get; set; }
[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; }
#endregion
#region Connection

View File

@@ -1020,6 +1020,9 @@ If you run into such an error, please create a new connection file!</value>
<data name="PropertyDescriptionPanel" xml:space="preserve">
<value>Sets the panel in which the connection will open.</value>
</data>
<data name="PropertyDescriptionTabColor" xml:space="preserve">
<value>Sets the color of the connection tab. Leave empty for default theme color.</value>
</data>
<data name="PropertyDescriptionPassword" xml:space="preserve">
<value>Enter your password.</value>
</data>
@@ -1182,6 +1185,9 @@ If you run into such an error, please create a new connection file!</value>
<data name="Panel" xml:space="preserve">
<value>Panel</value>
</data>
<data name="TabColor" xml:space="preserve">
<value>Tab Color</value>
</data>
<data name="Password" xml:space="preserve">
<value>Password</value>
</data>

View File

@@ -991,8 +991,11 @@ namespace mRemoteNG.UI.Tabs
rectText = DrawHelper.RtlTransform(this, rectText);
rectIcon = DrawHelper.RtlTransform(this, rectIcon);
Color activeColor = DockPane.DockPanel.Theme.ColorPalette.TabSelectedActive.Background;
Color lostFocusColor = DockPane.DockPanel.Theme.ColorPalette.TabSelectedInactive.Background;
// Get custom tab color if available
Color? customTabColor = GetCustomTabColor(tab.Content);
Color activeColor = customTabColor ?? DockPane.DockPanel.Theme.ColorPalette.TabSelectedActive.Background;
Color lostFocusColor = customTabColor ?? DockPane.DockPanel.Theme.ColorPalette.TabSelectedInactive.Background;
Color inactiveColor = DockPane.DockPanel.Theme.ColorPalette.MainWindowActive.Background;
Color mouseHoverColor = DockPane.DockPanel.Theme.ColorPalette.TabUnselectedHovered.Background;
@@ -1056,6 +1059,31 @@ namespace mRemoteNG.UI.Tabs
g.DrawIcon(tab.Content.DockHandler.Icon, rectIcon);
}
private Color? GetCustomTabColor(IDockContent content)
{
try
{
if (content is ConnectionTab connectionTab)
{
InterfaceControl interfaceControl = InterfaceControl.FindInterfaceControl(connectionTab);
if (interfaceControl?.Info != null)
{
string tabColorStr = interfaceControl.Info.TabColor;
if (!string.IsNullOrEmpty(tabColorStr))
{
ColorConverter converter = new ColorConverter();
return (Color)converter.ConvertFromString(tabColorStr);
}
}
}
}
catch
{
// If there's any error parsing the color, just return null to use default
}
return null;
}
private bool m_isMouseDown;
protected bool IsMouseDown