-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMenuAutoTabsHandlers.cs
More file actions
110 lines (97 loc) · 3.6 KB
/
MenuAutoTabsHandlers.cs
File metadata and controls
110 lines (97 loc) · 3.6 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
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
namespace X4LogWatcher
{
/// <summary>
/// Interaction logic for MenuAutoTabs_Click handler
/// </summary>
public partial class MainWindow
{
private void MenuAutoTabs_Click(object sender, RoutedEventArgs e)
{
// Clear existing items except for the header
while (menuAutoTabs.Items.Count > 0)
{
menuAutoTabs.Items.RemoveAt(0);
}
// Add all existing configs as menu items
if (autoTabConfigs.Count > 0)
{
// Add the configs to the menu
foreach (var config in autoTabConfigs)
{ // Create a display name that includes regex pattern details
string configName = config.PatternRegex;
if (configName.Length > 80)
{
configName = string.Concat(configName.AsSpan(0, 77), "...");
}
var configMenuItem = new MenuItem { Header = configName, Tag = config };
configMenuItem.IsChecked = config.IsEnabled;
// Add edit and remove as sub-items
var editItem = new MenuItem { Header = "Edit", Tag = config };
editItem.Click += (s, args) =>
{
if (s is MenuItem item && item.Tag is AutoTabConfig selectedConfig)
{
var dialog = new AutoTabConfigDialog(selectedConfig) { Owner = this };
if (dialog.ShowDialog() == true)
{
// Re-populate the menu to reflect any changes
MenuAutoTabs_Click(this, new RoutedEventArgs());
}
}
};
var removeItem = new MenuItem { Header = "Remove", Tag = config };
removeItem.Click += (s, args) =>
{
if (s is MenuItem item && item.Tag is AutoTabConfig selectedConfig)
{
var result = MessageBox.Show(
"Are you sure you want to remove this auto tab configuration?",
"Confirm Removal",
MessageBoxButton.YesNo,
MessageBoxImage.Question
);
if (result == MessageBoxResult.Yes)
{
autoTabConfigs.Remove(selectedConfig);
// Re-populate the menu to reflect the removal
MenuAutoTabs_Click(this, new RoutedEventArgs());
}
}
};
var toggleItem = new MenuItem { Header = config.IsEnabled ? "Disable" : "Enable", Tag = config };
toggleItem.Click += (s, args) =>
{
if (s is MenuItem item && item.Tag is AutoTabConfig selectedConfig)
{
selectedConfig.IsEnabled = !selectedConfig.IsEnabled;
// Re-populate the menu to reflect the change
MenuAutoTabs_Click(this, new RoutedEventArgs());
}
};
configMenuItem.Items.Add(toggleItem);
configMenuItem.Items.Add(editItem);
configMenuItem.Items.Add(removeItem);
menuAutoTabs.Items.Add(configMenuItem);
}
menuAutoTabs.Items.Add(new Separator());
}
// Add "Add New Auto Tab" item at the bottom
var addNewItem = new MenuItem { Header = "Add New Auto Tab..." };
addNewItem.Click += (s, args) =>
{
var dialog = new AutoTabConfigDialog { Owner = this };
if (dialog.ShowDialog() == true)
{
autoTabConfigs.Add(dialog.AutoTabConfig);
// Re-populate the menu to show the new config
MenuAutoTabs_Click(this, new RoutedEventArgs());
}
};
menuAutoTabs.Items.Add(addNewItem);
}
}
}