-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathIoListTestingWindow.P2CompactHeader.cs
More file actions
175 lines (148 loc) · 6.56 KB
/
Copy pathIoListTestingWindow.P2CompactHeader.cs
File metadata and controls
175 lines (148 loc) · 6.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Threading;
namespace ArIED61850Tester;
/// <summary>
/// P2 bench-facing header compaction.
///
/// P0 already separates operational actions from evidence/status actions. P2 only tightens
/// that existing hierarchy so the FAT header remains readable on normal engineering laptop
/// widths. Full evidence detail stays in the existing tooltips; protocol, evidence and grid
/// behavior are intentionally untouched.
/// </summary>
public partial class IoListTestingWindow
{
private void ConfigureP2CompactHeader()
{
if (_p0PrimaryHeaderActions == null || _p0SecondaryHeaderActions == null)
return;
_p0PrimaryHeaderActions.Margin = new Thickness(0);
_p0SecondaryHeaderActions.Margin = new Thickness(0, 3, 0, 0);
foreach (var button in _p0PrimaryHeaderActions.Children.OfType<Button>())
ApplyP2CompactButtonMetrics(button, secondary: false);
foreach (var button in _p0SecondaryHeaderActions.Children.OfType<Button>())
ApplyP2CompactButtonMetrics(button, secondary: true);
WorkspacePreviewToggle.Content = "Preview";
if (_cleanSessionButton != null)
_cleanSessionButton.Content = "Clean FAT";
ApplyP2CompactStatusMetrics(_clockSyncGlobalStatusText, 118, FontWeights.Medium);
ApplyP2CompactStatusMetrics(_clockSyncEvidenceText, 188, FontWeights.Normal);
// The selected-IED subtitle used to render the verbose LiveStatusText and was
// routinely clipped by the operational buttons. Rebind only this presentation line
// to a compact status; keep the complete legacy summary as its tooltip.
Dispatcher.BeginInvoke(
DispatcherPriority.Loaded,
new Action(ConfigureP2SelectedIedSubtitle));
}
private void ConfigureP2SelectedIedSubtitle()
{
var text = FindBoundTextBlock(this, nameof(SelectedIedSummary));
if (text == null)
return;
var compact = new MultiBinding
{
Mode = BindingMode.OneWay,
Converter = CompactSelectedIedSummaryConverter.Instance
};
compact.Bindings.Add(new Binding("SelectedIed.IpAddress") { Mode = BindingMode.OneWay });
compact.Bindings.Add(new Binding("SelectedIed.EnabledCount") { Mode = BindingMode.OneWay });
compact.Bindings.Add(new Binding("SelectedIed.LiveStatusText") { Mode = BindingMode.OneWay });
BindingOperations.SetBinding(text, TextBlock.TextProperty, compact);
BindingOperations.SetBinding(
text,
FrameworkElement.ToolTipProperty,
new Binding(nameof(SelectedIedSummary)) { Mode = BindingMode.OneWay });
text.FontSize = 10.2;
text.TextWrapping = TextWrapping.NoWrap;
text.TextTrimming = TextTrimming.CharacterEllipsis;
text.MaxWidth = 330;
}
private static TextBlock? FindBoundTextBlock(DependencyObject root, string bindingPath)
{
var count = VisualTreeHelper.GetChildrenCount(root);
for (var index = 0; index < count; index++)
{
var child = VisualTreeHelper.GetChild(root, index);
if (child is TextBlock text)
{
var binding = BindingOperations.GetBinding(text, TextBlock.TextProperty);
if (string.Equals(binding?.Path?.Path, bindingPath, StringComparison.Ordinal))
return text;
}
var nested = FindBoundTextBlock(child, bindingPath);
if (nested != null)
return nested;
}
return null;
}
private static void ApplyP2CompactButtonMetrics(Button button, bool secondary)
{
button.Padding = secondary
? new Thickness(8, 5, 8, 5)
: new Thickness(9, 6, 9, 6);
button.Margin = new Thickness(0, 0, 5, 0);
button.MinWidth = 0;
button.MinHeight = secondary ? 27 : 29;
if (secondary)
{
button.FontSize = 10.4;
button.FontWeight = FontWeights.Medium;
}
}
private static void ApplyP2CompactStatusMetrics(
TextBlock? text,
double maxWidth,
FontWeight fontWeight)
{
if (text == null)
return;
text.MaxWidth = maxWidth;
text.TextWrapping = TextWrapping.NoWrap;
text.TextTrimming = TextTrimming.CharacterEllipsis;
text.FontWeight = fontWeight;
text.FontSize = 10.2;
}
private sealed class CompactSelectedIedSummaryConverter : IMultiValueConverter
{
public static readonly CompactSelectedIedSummaryConverter Instance = new();
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
var ip = Value(values, 0);
var count = Value(values, 1);
var status = CompactLiveStatus(Value(values, 2));
if (string.IsNullOrWhiteSpace(ip))
return "Select an imported IED";
return $"{ip} · {count} pts · {status}";
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
=> throw new NotSupportedException();
private static string Value(object[] values, int index)
=> index < values.Length && values[index] != DependencyProperty.UnsetValue
? values[index]?.ToString()?.Trim() ?? string.Empty
: string.Empty;
private static string CompactLiveStatus(string value)
{
if (string.IsNullOrWhiteSpace(value))
return "OFFLINE";
if (value.Contains("Monitoring", StringComparison.OrdinalIgnoreCase))
{
if (value.Contains("Static", StringComparison.OrdinalIgnoreCase))
return "MON · Static DS";
if (value.Contains("Report", StringComparison.OrdinalIgnoreCase))
return "MON · Report";
return "MON";
}
if (value.Contains("Reconnect", StringComparison.OrdinalIgnoreCase))
return "RECONNECT";
if (value.Contains("Offline", StringComparison.OrdinalIgnoreCase) ||
value.Contains("Disconnect", StringComparison.OrdinalIgnoreCase))
return "OFFLINE";
if (value.Contains("Connected", StringComparison.OrdinalIgnoreCase))
return "CONNECTED";
return value.Length <= 18 ? value : value[..18] + "…";
}
}
}