private void buttonEditKey_Click(object sender, EventArgs e)
 {
     Key key = (Key)listBoxKeys.SelectedItem;
     KeyDialog keyd = new KeyDialog(objects, key);
     DialogResult result = keyd.ShowDialog();
     if (result == DialogResult.OK)
     {
         // update the key
         selectedType.keys.Remove(key);
         key.KeyType.keys.Add(key);
         key.Save();
         PopulateTypes();
         SelectAndExpand(key.KeyType);
     }
     keyd.Dispose();
 }
        private void buttonKeyTabEditKey_Click(object sender, EventArgs e)
        {
            Key key = objects.getKeyBySerial((string)listBoxKeyTabKeys.SelectedItem);
            if (key != null)
            {
                KeyDialog kd = new KeyDialog(objects, key);
                DialogResult result = kd.ShowDialog();
                if (result == DialogResult.OK)
                {
                    // update OOP.
                    foreach (KeyType type in objects.keytypes)
                    {
                        type.keys.Remove(key);
                    }
                    foreach (KeyRing ring in objects.keyrings)
                    {
                        ring.keys.Remove(key);
                    }
                    key.KeyType.keys.Add(key);
                    if (key.KeyRing != null)
                    {
                        key.KeyRing.keys.Add(key);
                    }

                    // update the database
                    key.Save();

                    // update the ui
                    initializeKeyTab();
                    setKeytabKeytype(key.KeyType);
                    listBoxKeyTabKeys.SelectedItem = key.Serial;
                }
            }
        }
 private void buttonCreateCopy_Click(object sender, EventArgs e)
 {
     // open a form to create a key
     KeyDialog keyd = new KeyDialog(objects);
     DialogResult result = keyd.ShowDialog();
     if (result == DialogResult.OK)
     {
         // create the key
         Key key = keyd.key;
         key.KeyType.keys.Add(key);
         objects.keys.Add(key);
         key.Save();
         PopulateTypes();
         SelectAndExpand(key.KeyType);
     }
     keyd.Dispose();
 }
        private void buttonKeyTabNewKey_Click(object sender, EventArgs e)
        {
            Key key = null;
            KeyType type = objects.getKeyTypeByName((string)comboBoxKeyTabKeyType.SelectedItem);
            if (type != null)
            {
                key = new Key(-1, "", false, false);
                key.KeyType = type;
            }

            KeyDialog kd = new KeyDialog(objects, key);
            DialogResult result = kd.ShowDialog();
            if (result == DialogResult.OK)
            {
                key = kd.key;
                // update the OOP
                objects.keys.Add(key);
                key.KeyType.keys.Add(key);
                if (key.KeyRing != null)
                {
                    key.KeyRing.keys.Add(key);
                }

                // update the database
                key.Save();

                // update the UI
                comboBoxKeyTabKey.Items.Add(key.Serial);
                setKeytabKeytype(key.KeyType);
                listBoxKeyTabKeys.SelectedItem = key.Serial;
            }
        }