-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement terminal column header style
- Loading branch information
1 parent
6510217
commit 1c80640
Showing
18 changed files
with
1,094 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.