|
|
|
|
@ -13,7 +13,7 @@ namespace MultiTerm.Wpf.Controls; |
|
|
|
|
public class SingleSelectSubMenu : MenuItem |
|
|
|
|
{ |
|
|
|
|
#region Static Properties |
|
|
|
|
public static Dictionary<MenuItem, SingleSelectSubMenu> RegisteredSubItemsAndParent = new Dictionary<MenuItem, SingleSelectSubMenu>(); |
|
|
|
|
private static readonly Dictionary<MenuItem, SingleSelectSubMenu> RegisteredSubItemsAndParent = new(); |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#region Dependency Properties |
|
|
|
|
@ -72,11 +72,9 @@ public class SingleSelectSubMenu : MenuItem |
|
|
|
|
private static void OnSelectedMenuItemPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
|
|
|
|
{ |
|
|
|
|
// extract instance and guard null |
|
|
|
|
var sssm = d as SingleSelectSubMenu; |
|
|
|
|
if (sssm == null) { return; } |
|
|
|
|
if (d is not SingleSelectSubMenu sssm) { return; } |
|
|
|
|
// extract instance of new Value and guard null |
|
|
|
|
var menuItem = e.NewValue as MenuItem; |
|
|
|
|
if (menuItem == null) { return; } |
|
|
|
|
if (e.NewValue is not MenuItem menuItem) { return; } |
|
|
|
|
|
|
|
|
|
// get associated menu items (same group) |
|
|
|
|
var associatedMenuitems = GetAssociatedMenuItems(sssm); |
|
|
|
|
@ -100,11 +98,7 @@ public class SingleSelectSubMenu : MenuItem |
|
|
|
|
private static void OnTitleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
|
|
|
|
{ |
|
|
|
|
// extract instance and guard null |
|
|
|
|
var sssm = d as SingleSelectSubMenu; |
|
|
|
|
if (sssm == null) |
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (d is not SingleSelectSubMenu sssm) { return; } |
|
|
|
|
|
|
|
|
|
sssm.Visibility = Visibility.Collapsed; |
|
|
|
|
sssm.Header = sssm.Title; |
|
|
|
|
@ -119,11 +113,9 @@ public class SingleSelectSubMenu : MenuItem |
|
|
|
|
private static void OnOptionsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
|
|
|
|
{ |
|
|
|
|
// extract instance and guard null |
|
|
|
|
var sssm = d as SingleSelectSubMenu; |
|
|
|
|
if (sssm == null) { return; } |
|
|
|
|
if (d is not SingleSelectSubMenu sssm) { return; } |
|
|
|
|
// extract parent instance of SSSM and guard null |
|
|
|
|
var parent = sssm.Parent as MenuItem; |
|
|
|
|
if (parent == null) { return; } |
|
|
|
|
if (sssm.Parent is not MenuItem parent) { return; } |
|
|
|
|
|
|
|
|
|
// IMRPOVEMENT Delete currently associated values (using e.OldValue) from RegisteredSubItemsAndParent |
|
|
|
|
// create and add title menu item |
|
|
|
|
@ -159,8 +151,7 @@ public class SingleSelectSubMenu : MenuItem |
|
|
|
|
private static void OnAnyItemChecked(object sender, RoutedEventArgs e) |
|
|
|
|
{ |
|
|
|
|
// extract sender menuItem and guard null |
|
|
|
|
var menuItem = sender as MenuItem; |
|
|
|
|
if (menuItem == null) { return; } |
|
|
|
|
if (sender is not MenuItem menuItem) { return; } |
|
|
|
|
|
|
|
|
|
// get associated menu items |
|
|
|
|
var associatedMenuitems = GetAssociatedMenuItems(menuItem); |
|
|
|
|
|