private ShortcutDictionary GetShortcutDictionaryForCurrentState() { var dictionary = ShortcutDictionary.Create(); foreach (var globalCommand in CommandManager.GlobalCommands) { dictionary.GlobalCommandShortcutInfo.Add(GlobalCommandShortcutInformation.CreateFromGlobalCommand(globalCommand)); } foreach (var staticPanelDefinition in PanelManager.StaticPanelDefinitions) { dictionary.StaticPanelShortcutInfo.Add(StaticPanelShortcutInformation.CreateFromDefinition(staticPanelDefinition)); } return(dictionary); }
public void LoadShortcuts() { AssertShortcuts(); DefaultShortcuts = GetShortcutDictionaryForCurrentState(); if (!File.Exists(ShortcutSerializationFile)) { return; } ShortcutDictionary shortcutDictionary = null; var serializer = new XmlSerializer(typeof(ShortcutDictionary)); using (var reader = new StreamReader(ShortcutSerializationFile)) { shortcutDictionary = (ShortcutDictionary)serializer.Deserialize(reader); } using (LoadingScope.BeginScope()) { foreach (var globalCommand in CommandManager.GlobalCommands) { var shortcutInfo = shortcutDictionary.GlobalCommandShortcutInfo.SingleOrDefault(o => o.Matches(globalCommand)); if (shortcutInfo == null) { continue; } if (!shortcutInfo.IsDefault) { if (shortcutInfo.HasShortcut) { SetShortcut(globalCommand, shortcutInfo.ModifierKeys, shortcutInfo.Key); } else { ClearShortcut(globalCommand); } } } foreach (var staticPanelDefinition in PanelManager.StaticPanelDefinitions) { var shortcutInfo = shortcutDictionary.StaticPanelShortcutInfo.SingleOrDefault(o => o.Matches(staticPanelDefinition)); if (shortcutInfo == null) { continue; } bool hasShortcutByDefault = staticPanelDefinition.OfType <BringIntoViewOnKeyShortcut>().Any(); if (!shortcutInfo.IsDefault) { if (shortcutInfo.HasShortcut) { SetShortcut(staticPanelDefinition, shortcutInfo.ModifierKeys, shortcutInfo.Key); } else { ClearShortcut(staticPanelDefinition); } } } } AssertShortcuts(); }