private void AddNewKey()
 {
     var inputKeyName = new InputKeyName();
     inputKeyName.ShowDialog(this);
     if (inputKeyName.DialogResult == DialogResult.OK && !string.IsNullOrEmpty(inputKeyName.KeyName.Text))
     {
         if (KeyManager.Keys.Exists(k => k.Name.Equals(inputKeyName.KeyName.Text, StringComparison.CurrentCultureIgnoreCase)))
         {
             MessageBox.Show(Texts.KeyNameAlreadyExists);
         }
         else
         {
             var configureKeyDialog = new MapKey();
             var newKey = configureKeyDialog.ShowDialog(this, inputKeyName.KeyName.Text, true);
             newKey.InfoWindowsKeys = inputKeyName.WindowsKeysDescription.Text;
             if (newKey != null)
             {
                 KeyManager.Keys.Add(newKey);
                 AddKeyNode(newKey);
             }
         }
     }
 }
        private void UpdateKeyCommand_Click(object sender, EventArgs e)
        {
            if (treeKeys.SelectedNode == null || treeKeys.SelectedNode.Level != 0)
            {
                EnableKeyButtons();
                return;
            }

            var configureKeyDialog = new MapKey();
            var newKey = configureKeyDialog.ShowDialog(this, treeKeys.SelectedNode.Name, false);
            if (newKey != null)
            {
                int index = KeyManager.Keys.IndexOf(KeyManager.Keys.Single(k => k.Name.Equals(treeKeys.SelectedNode.Name)));

                newKey.InfoWindowsKeys = KeyManager.Keys[index].InfoWindowsKeys;
                KeyManager.Keys.RemoveAt(index);
                KeyManager.Keys.Insert(index, newKey);
                UpdateKeyNode(newKey, newKey.Name);
            }

        }