private void EditHotkey(Hotkey hk) { using (var qf = new QuickForm("Enter New Hotkey") .Item(new HotkeyQuickFormItem("Hotkey", hk.HotkeyString)) .OkCancel()) { if (qf.ShowDialog() != DialogResult.OK) { return; } var key = qf.String("Hotkey"); if (String.IsNullOrWhiteSpace(key)) { return; } var conflict = _hotkeys.FirstOrDefault(x => x.HotkeyString == key && x != hk); if (conflict != null) { if (MessageBox.Show(key + " is already assigned to \"" + Hotkeys.GetHotkeyDefinition(conflict.ID) + "\".\n" + "Continue anyway?", "Conflict Detected", MessageBoxButtons.YesNo) == DialogResult.No) { return; } } hk.HotkeyString = key; UpdateHotkeyList(); } }
private void HotkeyAddButtonClicked(object sender, EventArgs e) { var key = HotkeyCombination.Text; if (HotkeyActionList.SelectedIndex <= 0 || String.IsNullOrWhiteSpace(key)) { return; } var conflict = _hotkeys.FirstOrDefault(x => x.HotkeyString == key); if (conflict != null) { if (MessageBox.Show(key + " is already assigned to \"" + Hotkeys.GetHotkeyDefinition(conflict.ID) + "\".\n" + "Continue anyway?", "Conflict Detected", MessageBoxButtons.YesNo) == DialogResult.No) { return; } } var def = (HotkeyDefinition)HotkeyActionList.SelectedItem; var blank = _hotkeys.FirstOrDefault(x => x.ID == def.ID && String.IsNullOrWhiteSpace(x.HotkeyString)); if (blank == null) { _hotkeys.Add(new Hotkey { ID = def.ID, HotkeyString = key }); } else { blank.HotkeyString = key; } HotkeyCombination.Text = ""; UpdateHotkeyList(); }
private void UpdateHotkeyList() { HotkeyList.BeginUpdate(); var idx = HotkeyList.SelectedIndices.Count == 0 ? 0 : HotkeyList.SelectedIndices[0]; HotkeyList.Items.Clear(); foreach (var hotkey in _hotkeys.OrderBy(x => x.ID)) { var def = Hotkeys.GetHotkeyDefinition(hotkey.ID); HotkeyList.Items.Add(new ListViewItem(new[] { def.Name, def.Description, String.IsNullOrWhiteSpace(hotkey.HotkeyString) ? "<unassigned>" : hotkey.HotkeyString }) { Tag = hotkey }); } HotkeyList.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); if (idx >= 0 && idx < HotkeyList.Items.Count) { HotkeyList.Items[idx].Selected = true; } HotkeyList.EndUpdate(); HotkeyActionList.BeginUpdate(); idx = HotkeyActionList.SelectedIndex; HotkeyActionList.Items.Clear(); foreach (var def in Hotkeys.GetHotkeyDefinitions().OrderBy(x => x.ID)) { HotkeyActionList.Items.Add(def); } if (idx < 0 || idx >= HotkeyActionList.Items.Count) { idx = 0; } HotkeyActionList.SelectedIndex = idx; HotkeyActionList.EndUpdate(); }