Skip to content

Commit

Permalink
Implement terminal column header style
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonardo-Cosmos committed Jul 3, 2023
1 parent 6510217 commit 1c80640
Show file tree
Hide file tree
Showing 18 changed files with 1,094 additions and 204 deletions.
39 changes: 39 additions & 0 deletions Models/ColumnHeaderStyle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* 2023/2/3 */
using System;
using System.Windows;
using System.Windows.Media;

namespace TerminalMonitor.Models
{
public class ColumnHeaderStyle : ICloneable
{
public static ColumnHeaderStyle Empty => new()
{
};

public Color? Foreground { get; set; }

public Color? Background { get; set; }

public Color? CellBackground { get; set; }

public HorizontalAlignment? HorizontalAlignment { get; set; }

public VerticalAlignment? VerticalAlignment { get; set; }

public TextAlignment? TextAlignment { get; set; }

public object Clone()
{
return new ColumnHeaderStyle()
{
Foreground = this.Foreground,
Background = this.Background,
CellBackground = this.CellBackground,
HorizontalAlignment = this.HorizontalAlignment,
VerticalAlignment = this.VerticalAlignment,
TextAlignment = this.TextAlignment,
};
}
}
}
16 changes: 14 additions & 2 deletions Models/FieldDisplayDetail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ public class FieldDisplayDetail : ICloneable

public string FieldKey { get; set; }

public bool Hidden { get; set; }

public string HeaderName { get; set; }

public bool CustomizeHeader { get; set; }

public ColumnHeaderStyle HeaderStyle { get; set; }

public bool CustomizeStyle { get; set; }

public TextStyle Style { get; set; }
Expand All @@ -23,9 +31,13 @@ public object Clone()
{
Id = Guid.NewGuid().ToString(),
FieldKey = this.FieldKey,
Hidden = this.Hidden,
HeaderName = this.HeaderName,
CustomizeHeader = this.CustomizeHeader,
HeaderStyle = (ColumnHeaderStyle)this.HeaderStyle?.Clone(),
CustomizeStyle = this.CustomizeStyle,
Style = (TextStyle)this.Style.Clone(),
Conditions = this.Conditions.Select(condition => (TextStyleCondition)condition.Clone()),
Style = (TextStyle)this.Style?.Clone(),
Conditions = this.Conditions?.Select(condition => (TextStyleCondition)condition.Clone()),
};
}
}
Expand Down
51 changes: 51 additions & 0 deletions Settings/Models/ColumnHeaderStyleSetting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* 2023/4/18 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TerminalMonitor.Models;

namespace TerminalMonitor.Settings.Models
{
record ColumnHeaderStyleSetting(ColorSetting Foreground, ColorSetting Background, ColorSetting CellBackground,
string HorizontalAlignment, string VerticalAlignment, string TextAlignment);

static class ColumnHeaderStyleSettings
{
public static ColumnHeaderStyleSetting Save(ColumnHeaderStyle obj)
{
if (obj == null)
{
return null;
}

return new ColumnHeaderStyleSetting(
Foreground: ColorSettings.Save(obj.Foreground),
Background: ColorSettings.Save(obj.Background),
CellBackground: ColorSettings.Save(obj.CellBackground),
HorizontalAlignment: HorizontalAlignmentSettings.Save(obj.HorizontalAlignment),
VerticalAlignment: VerticalAlignmentSettings.Save(obj.VerticalAlignment),
TextAlignment: TextAlignmentSettings.Save(obj.TextAlignment)
);
}

public static ColumnHeaderStyle Load(ColumnHeaderStyleSetting setting)
{
if (setting == null)
{
return null;
}

return new ColumnHeaderStyle()
{
Foreground = ColorSettings.Load(setting.Foreground),
Background = ColorSettings.Load(setting.Background),
CellBackground = ColorSettings.Load(setting.CellBackground),
HorizontalAlignment = HorizontalAlignmentSettings.Load(setting.HorizontalAlignment),
VerticalAlignment = VerticalAlignmentSettings.Load(setting.VerticalAlignment),
TextAlignment = TextAlignmentSettings.Load(setting.TextAlignment),
};
}
}
}
13 changes: 11 additions & 2 deletions Settings/Models/FieldDisplayDetailSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

namespace TerminalMonitor.Settings.Models
{
record FieldDisplayDetailSetting(string Id, string FieldKey, bool CustomizeStyle,
TextStyleSetting Style, List<TextStyleConditionSetting> Conditions);
record FieldDisplayDetailSetting(string Id, string FieldKey, bool Hidden,
string HeaderName, bool CustomizeHeader, ColumnHeaderStyleSetting HeaderStyle,
bool CustomizeStyle, TextStyleSetting Style, List<TextStyleConditionSetting> Conditions);

static class FieldDisplayDetailSettings
{
Expand All @@ -21,6 +22,10 @@ public static FieldDisplayDetailSetting Save(FieldDisplayDetail obj)
return new FieldDisplayDetailSetting(
Id: obj.Id,
FieldKey: obj.FieldKey,
Hidden: obj.Hidden,
HeaderName: obj.HeaderName,
CustomizeHeader: obj.CustomizeHeader,
HeaderStyle: ColumnHeaderStyleSettings.Save(obj.HeaderStyle),
CustomizeStyle: obj.CustomizeStyle,
Style: TextStyleSettings.Save(obj.Style),
Conditions: obj.Conditions?
Expand All @@ -39,6 +44,10 @@ public static FieldDisplayDetail Load(FieldDisplayDetailSetting setting)
{
Id = setting.Id ?? Guid.NewGuid().ToString(),
FieldKey = setting.FieldKey,
Hidden = setting.Hidden,
HeaderName = setting.HeaderName,
CustomizeHeader = setting.CustomizeHeader,
HeaderStyle = ColumnHeaderStyleSettings.Load(setting.HeaderStyle),
CustomizeStyle = setting.CustomizeStyle,
Style = TextStyleSettings.Load(setting.Style),
Conditions = setting.Conditions?
Expand Down
1 change: 1 addition & 0 deletions TerminalMonitor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<VersionPrefix>1.3.0</VersionPrefix>
<UseWPF>true</UseWPF>
<ApplicationIcon>TerminalMonitor.ico</ApplicationIcon>
</PropertyGroup>
Expand Down
98 changes: 98 additions & 0 deletions Windows/Controls/ColorDialogHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* 2023/3/3 */
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;

namespace TerminalMonitor.Windows.Controls
{
static class ColorDialogHelper
{
public static SolidColorBrush ShowColorDialog(SolidColorBrush brush)
{
var color = brush.Color;
System.Windows.Forms.ColorDialog colorDialog = new();


colorDialog.CustomColors = GetCustomColorsSetting();
colorDialog.Color = System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B);

SolidColorBrush solidColorBrush = null;
if (colorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
var selectedColor = colorDialog.Color;
color = Color.FromArgb(selectedColor.A,
selectedColor.R, selectedColor.G, selectedColor.B);
solidColorBrush = new SolidColorBrush(color);

SaveSelectedColor(colorDialog);
SetCustomColorsSetting(colorDialog.CustomColors);
}

return solidColorBrush;
}

private static void SaveSelectedColor(System.Windows.Forms.ColorDialog colorDialog)
{
var color = colorDialog.Color;
var selectedColor = color.R | (color.G << 8) | (color.B << 16);

if (!colorDialog.CustomColors.Contains(selectedColor))
{
var customColors = colorDialog.CustomColors;

bool added = false;
for (int i = 0; i < customColors.Length; i++)
{
if (customColors[i] == 0xffffff)
{
customColors[i] = selectedColor;
added = true;
break;
}
}

if (!added)
{
customColors = customColors.Skip(1)
.Concat(new int[] { selectedColor }).ToArray();
}

colorDialog.CustomColors = customColors;
}
}

private static int[] GetCustomColorsSetting()
{
var customColors = Properties.WindowSettings.Default.CustomColors ??= new();
var colors = new string[customColors.Count];
customColors.CopyTo(colors, 0);

return colors.Select(colorStr => ConvertToInt32(colorStr)).ToArray();
}

private static int ConvertToInt32(string value)
{
try
{
return Convert.ToInt32(value, 16);
}
catch (Exception ex)
{
Debug.Print(ex.Message);
return 0;
}
}

private static void SetCustomColorsSetting(int[] customColors)
{
var colors = customColors.Select(colorInt => Convert.ToString(colorInt, 16)).ToArray();

Properties.WindowSettings.Default.CustomColors.Clear();
Properties.WindowSettings.Default.CustomColors.AddRange(colors);
}
}
}
106 changes: 106 additions & 0 deletions Windows/Controls/ColumnHeaderStyleView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<UserControl x:Class="TerminalMonitor.Windows.Controls.ColumnHeaderStyleView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:TerminalMonitor.Windows.Controls"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=local:ColumnHeaderStyleViewDataContextVO}"
d:DesignHeight="150" d:DesignWidth="600">
<WrapPanel Name="pnl" Orientation="Horizontal">
<WrapPanel.Resources>
<ResourceDictionary>
<Style TargetType="CheckBox">
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
<Style TargetType="Label">
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
<Style TargetType="Rectangle">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Margin" Value="4, 0, 0, 0" />
</Style>
<Style TargetType="WrapPanel">
<Setter Property="Margin" Value="0, 4, 0, 4" />
</Style>
<Style TargetType="StackPanel">
<Setter Property="Margin" Value="4, 0, 8, 0" />
</Style>
</ResourceDictionary>
</WrapPanel.Resources>

<GroupBox Header="Color">
<WrapPanel Name="wrpPnlColor" Orientation="Horizontal">
<StackPanel Orientation="Horizontal">
<CheckBox Name="chkBxForeground" IsChecked="{Binding EnableForeground}"/>
<Label Name="lblForeground" Content="Foreground" IsEnabled="{Binding EnableForeground}" />
<Rectangle Name="rctForegroundColor" Width="10" Height="10"
Stroke="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}"
Fill="{Binding ForegroundColor}" MouseDown="RctForegroundColor_MouseDown">
</Rectangle>
</StackPanel>

<StackPanel Orientation="Horizontal">
<CheckBox Name="chkBxBackground" IsChecked="{Binding EnableBackground}" />
<Label Name="lblBackground" Content="Background" IsEnabled="{Binding EnableBackground}" />
<Rectangle Name="rctBackgroundColor" Width="10" Height="10"
Stroke="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}"
Fill="{Binding BackgroundColor}" MouseDown="RctBackgroundColor_MouseDown">
</Rectangle>
</StackPanel>

<StackPanel Orientation="Horizontal">
<CheckBox Name="chkBxCellBackground" IsChecked="{Binding EnableCellBackground}" />
<Label Name="lblCellBackground" Content="Cell background" IsEnabled="{Binding EnableCellBackground}" />
<Rectangle Name="rctCellBackgroundColor" Width="10" Height="10"
Stroke="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}"
Fill="{Binding CellBackgroundColor}" MouseDown="RctCellBackgroundColor_MouseDown">
</Rectangle>
</StackPanel>
</WrapPanel>
</GroupBox>

<GroupBox Header="Alignment">
<WrapPanel Orientation="Horizontal">
<StackPanel Orientation="Horizontal">
<CheckBox Name="chkBoHorizontalAlignment" IsChecked="{Binding EnableHorizontalAlignment}" />
<Label Name="lblHorizontalAlignment" Content="Horizontal alignment" IsEnabled="{Binding EnableHorizontalAlignment}" />
<ComboBox Name="cmbBxHorizontalAlignment" IsEnabled="{Binding EnableHorizontalAlignment}"
ItemsSource="{StaticResource HorizontalAlignmentValues}" SelectedValue="{Binding HorizontalAlignment}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource HorizontalAlignmentToStringConverter}}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>

<StackPanel Orientation="Horizontal">
<CheckBox Name="chkBoVerticalAlignment" IsChecked="{Binding EnableVerticalAlignment}" />
<Label Name="lblVerticalAlignment" Content="Vertical alignment" IsEnabled="{Binding EnableVerticalAlignment}" />
<ComboBox Name="cmbBxVerticalAlignment" IsEnabled="{Binding EnableVerticalAlignment}"
ItemsSource="{StaticResource VerticalAlignmentValues}" SelectedValue="{Binding VerticalAlignment}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource VerticalAlignmentToStringConverter}}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>

<StackPanel Orientation="Horizontal">
<CheckBox Name="chkBoTextAlignment" IsChecked="{Binding EnableTextAlignment}" />
<Label Name="lblTextAlignment" Content="Text alignment" IsEnabled="{Binding EnableTextAlignment}" />
<ComboBox Name="cmbBxTextAlignment" IsEnabled="{Binding EnableTextAlignment}"
ItemsSource="{StaticResource TextAlignmentValues}" SelectedValue="{Binding TextAlignment}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource TextAlignmentToStringConverter}}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
</WrapPanel>
</GroupBox>
</WrapPanel>
</UserControl>
Loading

0 comments on commit 1c80640

Please sign in to comment.