-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathIoListTestingWindow.WorkspaceModeSwitch.cs
More file actions
119 lines (103 loc) · 4.16 KB
/
Copy pathIoListTestingWindow.WorkspaceModeSwitch.cs
File metadata and controls
119 lines (103 loc) · 4.16 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
// Copyright 2026 Ari Sulistiono
// SPDX-License-Identifier: Apache-2.0
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace ArIED61850Tester;
public partial class IoListTestingWindow
{
private const string FatWorkspaceModeTag = "ARSAS_FAT_WORKSPACE_MODE";
private static readonly bool FatWorkspaceModeRegistered = RegisterFatWorkspaceMode();
private bool _fatWorkspaceModeInstalled;
private static bool RegisterFatWorkspaceMode()
{
EventManager.RegisterClassHandler(
typeof(IoListTestingWindow),
FrameworkElement.LoadedEvent,
new RoutedEventHandler(FatWorkspaceMode_Loaded));
return true;
}
private static void FatWorkspaceMode_Loaded(object sender, RoutedEventArgs e)
{
if (sender is IoListTestingWindow window)
window.InstallFatWorkspaceModeSwitch();
}
private void InstallFatWorkspaceModeSwitch()
{
if (_fatWorkspaceModeInstalled)
{
if (Owner is MainWindow existingOwner)
existingOwner.RegisterLoadedIoFatWindow(this);
return;
}
var originalEngineeringButton = VisualDescendants<Button>(this)
.FirstOrDefault(button => string.Equals(button.Content?.ToString(), "Engineering", StringComparison.Ordinal));
if (originalEngineeringButton?.Parent is not WrapPanel actions)
return;
var originalIndex = actions.Children.IndexOf(originalEngineeringButton);
var engineeringButton = new Button
{
Content = "Engineering Workspace",
Style = originalEngineeringButton.Style,
Padding = originalEngineeringButton.Padding,
Margin = new Thickness(0),
FontSize = originalEngineeringButton.FontSize,
FontWeight = originalEngineeringButton.FontWeight,
ToolTip = "Return to Engineering without unloading this FAT project",
VerticalAlignment = originalEngineeringButton.VerticalAlignment,
HorizontalAlignment = originalEngineeringButton.HorizontalAlignment
};
engineeringButton.Click += EngineeringWorkspaceMode_Click;
actions.Children.Remove(originalEngineeringButton);
var selectedMode = new Border
{
Tag = FatWorkspaceModeTag,
Background = TryFindResource("Accent") as Brush ?? FatWorkspaceBrush("#2563EB"),
CornerRadius = new CornerRadius(13),
Padding = new Thickness(11, 7, 11, 7),
Margin = new Thickness(0, 0, 6, 0),
VerticalAlignment = VerticalAlignment.Center,
Child = new TextBlock
{
Text = "IO LIST FAT · LOADED",
Foreground = Brushes.White,
FontSize = 10.5,
FontWeight = FontWeights.Bold,
VerticalAlignment = VerticalAlignment.Center
}
};
actions.Children.Insert(Math.Max(0, originalIndex), selectedMode);
actions.Children.Insert(Math.Max(0, originalIndex + 1), engineeringButton);
_fatWorkspaceModeInstalled = true;
if (Owner is MainWindow owner)
owner.RegisterLoadedIoFatWindow(this);
}
private void EngineeringWorkspaceMode_Click(object sender, RoutedEventArgs e)
{
if (Owner is MainWindow owner)
{
owner.ShowEngineeringWorkspaceFromFat(this);
return;
}
Storage?.ScheduleSave();
Hide();
}
private static IEnumerable<T> VisualDescendants<T>(DependencyObject root) where T : DependencyObject
{
var count = VisualTreeHelper.GetChildrenCount(root);
for (var index = 0; index < count; index++)
{
var child = VisualTreeHelper.GetChild(root, index);
if (child is T match)
yield return match;
foreach (var descendant in VisualDescendants<T>(child))
yield return descendant;
}
}
private static SolidColorBrush FatWorkspaceBrush(string hex)
{
var brush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(hex));
brush.Freeze();
return brush;
}
}