/// <summary> /// Load in and register keyboard shortcuts from a file. A KeyActionList is needed to map the shortcuts to their actions. /// </summary> /// <param name="file">The file to load from.</param> /// <param name="methodList">The list of actions available for keyboard shortcuts, to use for mapping.</param> /// <exception cref="System.IO.FileNotFoundException">Thrown if the file cannot be found.</exception> /// <remarks> /// If there is a shortcut in the file that references an action not in the <paramref name="methodList"/>, that shortcut is skipped. /// Also, if a shortcut in the file has the same keyboard combination and key as a shortcut already registed, that shortcut is skipped. /// </remarks> public void LoadShortcutsFromFile(string file, KeyActionList methodList) { var list = KeyboardShortcutsIo.LoadFromFile(file, methodList); foreach (KeyboardShortcut item in list) { try { KeyRegistry.RegisterKeyShortcut(item); } catch (ArgumentException) { // thrown if there's already a shortcut registered with this particular keyboard combination and key // skip the particular shortcut } } }
/// <summary> /// Write the currently registered keyboard shortcuts to a file, which can be loaded in later. /// </summary> /// <param name="file"></param> /// <returns></returns> public async Task WriteShortcutsToFileAsync(string file) { await KeyboardShortcutsIo.WriteToFile(KeyRegistry, file); }