/// <summary> /// Add new Hotkey to Xml /// </summary> /// <param name="hotkey"></param> public void AddHotkey(HotkeyConfiguration hotkey) { var configXml = new XmlDocument(); configXml.Load(_xmlConfigurationPath.Value); var configParent = configXml.SelectSingleNode("/HotkeyConfigurations"); if (configParent == null) { return; } var configXmlNode = configXml.CreateElement("HotkeyConfiguration"); var idAttribute = configXml.CreateAttribute("Id"); idAttribute.Value = hotkey.Id.ToString(); var keyAttribute = configXml.CreateAttribute("Key"); keyAttribute.Value = ((int)hotkey.Key).ToString(); var modifierAttribute = configXml.CreateAttribute("Modifier"); modifierAttribute.Value = hotkey.Modifier.ToString(); var pluginNameAttribute = configXml.CreateAttribute("PluginName"); pluginNameAttribute.Value = hotkey.PluginName; configXmlNode.Attributes.Append(idAttribute); configXmlNode.Attributes.Append(keyAttribute); configXmlNode.Attributes.Append(modifierAttribute); configXmlNode.Attributes.Append(pluginNameAttribute); configParent.AppendChild(configXmlNode); configXml.Save(_xmlConfigurationPath.Value); }
/// <summary> /// Handler for AddHotkey Button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnClickAddHotkeyButton(object sender, RoutedEventArgs e) { var selectedModifier = (ComboBoxItem) ModifierDropDown.SelectedItem; var selectedPluginName = (string) PluginsDropDown.SelectedItem; if (selectedModifier == null || selectedPluginName == null || PressedKeyIdentifier.Text == "" || PressedKeyIdentifier.Text == PressAnyKeyText) { MessageBox.Show("Select Modifier, Key and Plugin"); return; } var hotkeyConfig = new HotkeyConfiguration(Guid.NewGuid(), (int) selectedModifier.Tag, _lastPressedKey, selectedPluginName); _xmlConfiguredHotkeys.AddHotkey(hotkeyConfig); ConfiguredHotkeys.Add(hotkeyConfig); ModifierDropDown.SelectedItem = null; PluginsDropDown.SelectedItem = null; PressedKeyIdentifier.Text = ""; }