-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathIedWorkspaceActionsCardBehavior.cs
More file actions
61 lines (53 loc) · 2.4 KB
/
Copy pathIedWorkspaceActionsCardBehavior.cs
File metadata and controls
61 lines (53 loc) · 2.4 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
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
namespace ArIED61850Tester;
/// <summary>
/// Promotes the existing card-local edit action into the reusable IED Actions entry point
/// without duplicating the task chooser in XAML. The class handler runs before the legacy
/// instance Click handler, so the old direct signal-editor path is suppressed only for the
/// identified IED-card button. All other buttons keep their existing behavior.
/// </summary>
internal static class IedWorkspaceActionsCardBehavior
{
private const string LegacyToolTip = "Configure Signals";
private const string ActionsToolTip = "IED Actions — Static DataSet, Select Signals, RCB Engineering, COMTRADE, Browse Offline";
[ModuleInitializer]
internal static void Initialize()
{
EventManager.RegisterClassHandler(
typeof(Button),
FrameworkElement.LoadedEvent,
new RoutedEventHandler(OnButtonLoaded));
EventManager.RegisterClassHandler(
typeof(Button),
ButtonBase.ClickEvent,
new RoutedEventHandler(OnButtonClick));
}
private static void OnButtonLoaded(object sender, RoutedEventArgs args)
{
if (sender is not Button button || !HasLegacyOrActionsToolTip(button))
return;
// Keep the existing compact pencil/edit visual, but make its expanded purpose
// explicit. The card stays the stable entry point even after Quick Start is closed.
button.ToolTip = ActionsToolTip;
}
private static void OnButtonClick(object sender, RoutedEventArgs args)
{
if (sender is not Button button || !HasLegacyOrActionsToolTip(button))
return;
if (Window.GetWindow(button) is not MainWindow mainWindow)
return;
// Class handlers precede the XAML instance handler. Marking the routed Click handled
// prevents IedConfigureSignals_Click from opening the manual wizard directly.
args.Handled = true;
_ = mainWindow.OpenIedWorkspaceActionsFromCardAsync(button);
}
private static bool HasLegacyOrActionsToolTip(Button button)
{
var text = button.ToolTip?.ToString()?.Trim() ?? string.Empty;
return text.Equals(LegacyToolTip, StringComparison.Ordinal) ||
text.Equals(ActionsToolTip, StringComparison.Ordinal);
}
}