private void LoadPresetsMenus(object sender, RoutedEventArgs e)
{
//grab serialized presets from current workspace
var PresetSet = dynamoViewModel.Model.CurrentWorkspace.Presets;
// now grab all the states off the set and create a menu item for each one
var statesMenu = (sender as MenuItem);
var senderItems = statesMenu.Items.OfType<MenuItem>().Select(x => x.Tag).ToList();
//only update the states menus if the states have been updated or the user
// has switched workspace contexts, can check if stateItems List is different
//from the presets on the current workspace
if (!PresetSet.SequenceEqual(senderItems))
{
//dispose all state items in the menu
statesMenu.Items.Clear();
foreach (var state in PresetSet)
{
//create a new menu item for each state in the options set
//when any of this buttons are clicked we'll call the SetWorkSpaceToStateCommand(state)
var stateItem = new MenuItem
{
Header = state.Name,
Tag = state
};
//if the sender was the restoremenu then add restore delegates
if (sender == RestorePresetMenu)
{
stateItem.Click += RestoreState_Click;
}
else
{
//else the sender was the delete menu
stateItem.Click += DeleteState_Click;
}
stateItem.ToolTip = state.Description;
((MenuItem)sender).Items.Add(stateItem);
}
}
}