mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
Add Color property to connections and folders with inheritance support
Co-authored-by: Kvarkas <3611964+Kvarkas@users.noreply.github.com>
This commit is contained in:
@@ -22,6 +22,7 @@ namespace mRemoteNG.Connection
|
||||
private string _description;
|
||||
private string _icon;
|
||||
private string _panel;
|
||||
private string _color;
|
||||
|
||||
private string _hostname;
|
||||
private ExternalAddressProvider _externalAddressProvider;
|
||||
@@ -153,6 +154,17 @@ namespace mRemoteNG.Connection
|
||||
set => SetField(ref _panel, value, "Panel");
|
||||
}
|
||||
|
||||
[LocalizedAttributes.LocalizedCategory(nameof(Language.Display)),
|
||||
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))]
|
||||
public virtual string Color
|
||||
{
|
||||
get => GetPropertyValue("Color", _color);
|
||||
set => SetField(ref _color, value, "Color");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Connection
|
||||
|
||||
@@ -289,6 +289,7 @@ namespace mRemoteNG.Connection
|
||||
Description = Settings.Default.ConDefaultDescription;
|
||||
Icon = Settings.Default.ConDefaultIcon;
|
||||
Panel = Language.General;
|
||||
Color = string.Empty;
|
||||
}
|
||||
|
||||
private void SetConnectionDefaults()
|
||||
|
||||
@@ -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.Color)),
|
||||
LocalizedAttributes.LocalizedDescriptionInherit(nameof(Language.PropertyDescriptionColor)),
|
||||
TypeConverter(typeof(MiscTools.YesNoTypeConverter))]
|
||||
public bool Color { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Connection
|
||||
|
||||
@@ -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="PropertyDescriptionColor" xml:space="preserve">
|
||||
<value>Sets the color for the connection or folder in the connections tree. Connections inherit this color from their parent folder.</value>
|
||||
</data>
|
||||
<data name="PropertyDescriptionPassword" xml:space="preserve">
|
||||
<value>Enter your password.</value>
|
||||
</data>
|
||||
@@ -1137,6 +1140,9 @@ If you run into such an error, please create a new connection file!</value>
|
||||
<data name="CacheBitmaps" xml:space="preserve">
|
||||
<value>Cache Bitmaps</value>
|
||||
</data>
|
||||
<data name="Color" xml:space="preserve">
|
||||
<value>Color</value>
|
||||
</data>
|
||||
<data name="Colors" xml:space="preserve">
|
||||
<value>Colors</value>
|
||||
</data>
|
||||
|
||||
@@ -166,6 +166,7 @@ namespace mRemoteNG.UI.Controls.ConnectionTree
|
||||
ModelDropped += _dragAndDropHandler.HandleEvent_ModelDropped;
|
||||
BeforeLabelEdit += OnBeforeLabelEdit;
|
||||
AfterLabelEdit += OnAfterLabelEdit;
|
||||
FormatCell += ConnectionTree_FormatCell;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -512,6 +513,27 @@ namespace mRemoteNG.UI.Controls.ConnectionTree
|
||||
_contextMenu.DisableShortcutKeys();
|
||||
}
|
||||
|
||||
private void ConnectionTree_FormatCell(object sender, FormatCellEventArgs e)
|
||||
{
|
||||
if (e.Model is not ConnectionInfo connectionInfo)
|
||||
return;
|
||||
|
||||
string colorString = connectionInfo.Color;
|
||||
if (string.IsNullOrEmpty(colorString))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
System.Drawing.ColorConverter converter = new();
|
||||
System.Drawing.Color color = (System.Drawing.Color)converter.ConvertFromString(colorString);
|
||||
e.SubItem.ForeColor = color;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// If color parsing fails, just ignore and use default color
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAfterLabelEdit(object sender, LabelEditEventArgs e)
|
||||
{
|
||||
if (!_nodeInEditMode)
|
||||
|
||||
Reference in New Issue
Block a user