private FinderForm finderForm; //查找窗口 public SettingForm(Dictionary <string, string> shortNameAndCommands) { InitializeComponent(); StartPosition = FormStartPosition.CenterScreen; KeyPreview = true; //使窗口支持快捷键 commandTableHandler = new ShortCommandTableHandler(shortNameAndCommands); }
/// <summary> /// <para>Imports the config file.</para> /// </summary> /// <param name="commandTableHandler">The command table handler.</param> public static void ImportConfig(ShortCommandTableHandler commandTableHandler) { string filePath = FileAndDirectoryHelper.OpenXmlFileDialog(); Dictionary <string, string> importCommandConfig = CommandConfigHandler.ReadCommandConfigFile(filePath); if (importCommandConfig == null || importCommandConfig.Count <= 0) { return; } List <CurrentAndImportCommand> sharedCommands = new List <CurrentAndImportCommand>(); Dictionary <string, string> nameAndCommandCopy = new Dictionary <string, string>(commandTableHandler.UpdateNameAndCommandFromTable()); foreach (var importPair in importCommandConfig) { string importCommand = importPair.Value; if (FileAndDirectoryHelper.IsInvalidPath(importCommand)) { continue; } string name = importPair.Key; if (nameAndCommandCopy.TryGetValue(name, out var currentCommand)) { if (currentCommand.Equals(importCommand)) { continue; } sharedCommands.Add(new CurrentAndImportCommand(name, currentCommand, importCommand)); } else { nameAndCommandCopy[name] = importCommand; } } //有相同的快捷命令冲突 if (sharedCommands.Count > 0) { ShowCommandCompareForm(sharedCommands, nameAndCommandCopy, commandTableHandler); } else if (!nameAndCommandCopy.SequenceEqual(commandTableHandler.ShortNameAndCommands)) { commandTableHandler.UpdateShortNameAndCommands(nameAndCommandCopy); } }
private static void ShowCommandCompareForm(List <CurrentAndImportCommand> sharedCommands, Dictionary <string, string> shortNameAndCommands, ShortCommandTableHandler commandTableHandler) { CommandCompareForm commandCompareForm = new CommandCompareForm(sharedCommands, shortNameAndCommands) { StartPosition = FormStartPosition.CenterScreen, UpdateNameAndCommandAction = commandTableHandler.UpdateShortNameAndCommands }; commandCompareForm.ShowDialog(); }