Skip to content

Commit

Permalink
Merge f2ba33b into 84c8f8e
Browse files Browse the repository at this point in the history
  • Loading branch information
Greybird committed Oct 2, 2020
2 parents 84c8f8e + f2ba33b commit d3be126
Show file tree
Hide file tree
Showing 10 changed files with 534 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Common/Helpers/ConfigurationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ static MainSettings GetMainSettingsUsingConfiguration(TwoFilesConfiguration conf
resultProperties.ProxyBypassList = configuration.GetStringValue(ConfigurationParameters.ProxyBypassList, string.Empty);
resultProperties.ProxyUserName = configuration.GetStringValue(ConfigurationParameters.ProxyUserName, string.Empty);
resultProperties.ProxyPassword = configuration.GetStringValue(ConfigurationParameters.ProxyPassword, string.Empty);
resultProperties.NodesColors = NodeColorInfo.ParseAll(configuration.GetStringValue(ConfigurationParameters.NodesColors, string.Empty));

return resultProperties;
}
Expand Down
1 change: 1 addition & 0 deletions src/Common/Helpers/ConfigurationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public static class ConfigurationParameters
public const string ProxyUseDefaultCredentials = "Proxy.UseDefaultCredentials";
public const string ProxyUserName = "Proxy.UserName";
public const string ProxyPassword = "Proxy.Password";
public const string NodesColors = "Colors.Nodes";

#endregion

Expand Down
10 changes: 10 additions & 0 deletions src/Common/Helpers/MainSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

namespace ServiceBusExplorer.Helpers
{
using Utilities.Helpers;

public class MainSettings
{
#region Internal constants
Expand Down Expand Up @@ -75,6 +77,8 @@ public class MainSettings
public string ProxyUserName { get; set; }
public string ProxyPassword { get; set; }

public List<NodeColorInfo> NodesColors { get; set; } = new List<NodeColorInfo>();

#endregion

#region Public Static Methods
Expand Down Expand Up @@ -132,6 +136,8 @@ public void SetDefault()
ProxyBypassList = string.Empty;
ProxyUserName = string.Empty;
ProxyPassword = string.Empty;

NodesColors = new List<NodeColorInfo>();
}

public override bool Equals(object other)
Expand Down Expand Up @@ -177,6 +183,7 @@ public override bool Equals(object other)
if (ProxyBypassList != otherProperties.ProxyBypassList) return false;
if (ProxyUserName != otherProperties.ProxyUserName) return false;
if (ProxyPassword != otherProperties.ProxyPassword) return false;
if (NodesColors.SequenceEqual(otherProperties.NodesColors)) return false;

return true;
}
Expand Down Expand Up @@ -300,6 +307,9 @@ public object GetValue(string setting)

case ConfigurationParameters.ProxyPassword:
return ProxyPassword;

case ConfigurationParameters.NodesColors:
return NodesColors;
}

throw new InvalidOperationException(String.Format("Unexpected value for setting: {0}", setting));
Expand Down
212 changes: 212 additions & 0 deletions src/ServiceBusExplorer/Controls/DataGridViewColorPickerColumn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
using System;
using System.Windows.Forms;

namespace ServiceBusExplorer.Controls
{
using System.ComponentModel;
using System.Drawing;

public class DataGridViewColorPickerColumn : DataGridViewColumn
{
public DataGridViewColorPickerColumn()
: base(new ColorCell())
{
}

public override DataGridViewCell CellTemplate
{
get => base.CellTemplate;
set
{
if (value != null &&
!value.GetType().IsAssignableFrom(typeof(ColorCell)))
{
throw new InvalidCastException("Must be a ColorCell");
}
base.CellTemplate = value;
}
}
}

public class ColorCell : DataGridViewTextBoxCell
{
public override void InitializeEditingControl(int rowIndex, object
initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
{
base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle);
if (!(DataGridView.EditingControl is ColorEditingControl colorPicker))
{
return;
}
colorPicker.Value = (Color)Value;
}

public override object ParseFormattedValue(object formattedValue, DataGridViewCellStyle cellStyle, TypeConverter formattedValueTypeConverter, TypeConverter valueTypeConverter)
{
return formattedValue;
}

public override Type EditType => typeof(ColorEditingControl);

public override Type ValueType => typeof(Color);

public override object DefaultNewRowValue => Color.Empty;

protected override void Paint(Graphics graphics,
Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
DataGridViewElementStates elementState, object value,
object formattedValue, string errorText,
DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts)
{
paintParts &= ~DataGridViewPaintParts.Focus;
var actualColor = GetActualColor(value);
var colorText = actualColor?.Name ?? string.Empty;
var actualCellStyle = actualColor == null
? cellStyle
: new DataGridViewCellStyle(cellStyle)
{
BackColor = actualColor.Value,
SelectionBackColor = actualColor.Value
};
base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, colorText, errorText, actualCellStyle, advancedBorderStyle, paintParts);
}

private static Color? GetActualColor(object value)
{
Color? actualColor;
try
{
actualColor = value.Equals(Color.Empty) ? (Color?) null : (Color) value;
}
catch (Exception)
{
actualColor = null;
}
return actualColor;
}
}

class ColorEditingControl : Button, IDataGridViewEditingControl
{
public Color Value
{
get => BackColor;
set
{
var actualColor = value.Equals(Color.Empty) ? (Color?) null : (Color)value;
if (actualColor.HasValue)
{
BackColor = actualColor.Value;
Text = actualColor.Value.Name;
}
}
}

public ColorEditingControl()
{
TextAlign = ContentAlignment.MiddleLeft;
Click += ColorEditingControl_Click;
}

void ColorEditingControl_Click(object sender, EventArgs e)
{
var colorDialog = new ColorDialog();
if (colorDialog.ShowDialog() == DialogResult.OK)
{
if (Value != colorDialog.Color)
{
Value = colorDialog.Color;
EditingControlValueChanged = true;
EditingControlDataGridView.NotifyCurrentCellDirty(true);
EditingControlDataGridView.EndEdit();
}
}
}

#region Public Methods

// Implements the IDataGridViewEditingControl.EditingControlFormattedValue
// property.
public object EditingControlFormattedValue
{
get => Value;
set
{
if (value != null)
{
Value = (Color) value;
}
}
}

// Implements the
// IDataGridViewEditingControl.GetEditingControlFormattedValue method.
public object GetEditingControlFormattedValue(DataGridViewDataErrorContexts context)
{
return EditingControlFormattedValue;
}

// Implements the
// IDataGridViewEditingControl.ApplyCellStyleToEditingControl method.
public void ApplyCellStyleToEditingControl(DataGridViewCellStyle dataGridViewCellStyle)
{
Font = dataGridViewCellStyle.Font;
}

// Implements the IDataGridViewEditingControl.EditingControlWantsInputKey
// method.
public bool EditingControlWantsInputKey(Keys key, bool dataGridViewWantsInputKey)
{
// Let the ColorPicker handle the keys listed.
switch (key & Keys.KeyCode)
{
case Keys.Left:
case Keys.Up:
case Keys.Down:
case Keys.Right:
case Keys.Home:
case Keys.End:
case Keys.PageDown:
case Keys.PageUp:
return true;
default:
return !dataGridViewWantsInputKey;
}
}

// Implements the IDataGridViewEditingControl.PrepareEditingControlForEdit
// method.
public void PrepareEditingControlForEdit(bool selectAll)
{
// No preparation needs to be done.
}

#endregion

#region Public Properties

// Implements the IDataGridViewEditingControl.EditingControlRowIndex
// property.
public int EditingControlRowIndex { get; set; }

// Implements the IDataGridViewEditingControl
// .RepositionEditingControlOnValueChange property.
public bool RepositionEditingControlOnValueChange => false;

// Implements the IDataGridViewEditingControl
// .EditingControlDataGridView property.
public DataGridView EditingControlDataGridView { get; set; }

// Implements the IDataGridViewEditingControl
// .EditingControlValueChanged property.
public bool EditingControlValueChanged { get; set; }

// Implements the IDataGridViewEditingControl
// .EditingPanelCursor property.
public Cursor EditingPanelCursor => base.Cursor;

#endregion
}
}
Loading

0 comments on commit d3be126

Please sign in to comment.