private void listView1_SelectedIndexChanged(object sender, EventArgs e) { if (listView1.SelectedItems.Count == 0) { btnEdit.Enabled = false; current_edit_id = -1; return; } btnEdit.Enabled = true; btnRemove.Enabled = true; int item = listView1.SelectedItems[0].Index; current_edit_id = item; ArrayList arr = Model.LoadData(); HotkeyItem a = (HotkeyItem)arr[item]; chkCtr.Checked = a.Ctr; chkAlt.Checked = a.Alt; chkShift.Checked = a.Shift; cbKey.Text = a.Key; txtDescription.Text = a.Description; current_audio_file = a.AudioFile; if (Audio.playSound(0, a.AudioFile) == "true") { Audio.disposeWave(); btnPlay.Enabled = true; } else { btnPlay.Enabled = false; } }
private String ValidateHotkeyItem(HotkeyItem a) { List <string> restrict_key = new List <string>() { "Q", "W", "E", "R", "Y", "U", "A", "S", "D", "G", "1", "2", "3", "4", "5" }; if (!a.Ctr && !a.Alt && !a.Shift) { if (restrict_key.Contains(a.Key)) { return("You can not only this key."); } } if (!list_hotkey.Contains(a.Key)) { return("Hotkey is not in HotkeyList."); } if (a.Description == "") { return("Please fill Description field."); } String test_sound = Audio.playSound(Form1.AudioDevice, a.AudioFile); if (test_sound == "true") { Audio.disposeWave(); } return(test_sound); }
public static void Edit(int index, HotkeyItem a) { if (index < 0) { Add(a); return; } arrList[index] = a; SaveData(); }
public static bool Add(HotkeyItem a) { if (CheckDuplicate(a)) { return(false); } arrList.Add(a); SaveData(); return(true); }
private HotkeyItem getHotkeyItemInForm() { HotkeyItem a = new HotkeyItem(); a.Ctr = chkCtr.Checked; a.Alt = chkAlt.Checked; a.Shift = chkShift.Checked; a.Key = cbKey.Text; a.Description = txtDescription.Text; a.AudioFile = current_audio_file; return(a); }
public static bool CheckDuplicate(HotkeyItem a) { if (arrList == null) { return(false); } foreach (HotkeyItem b in arrList) { if (a.Ctr == b.Ctr && a.Alt == b.Alt && a.Shift == b.Shift && a.Key == b.Key) { return(true); } } return(false); }
public void ShowListView() { listView1.Items.Clear(); ArrayList arr = Model.LoadData(); for (int i = 0; i < arr.Count; i++) { HotkeyItem a = (HotkeyItem)arr[i]; listView1.Items.Add(i.ToString()); int j = listView1.Items.Count - 1; listView1.Items[j].SubItems.Add(a.getHotkey()); listView1.Items[j].SubItems.Add(a.Description); listView1.Items[j].SubItems.Add(a.AudioFile.Substring(a.AudioFile.LastIndexOf('\\') + 1)); } }
public static void SingleStepAddHotkey(int i, ArrayList arr) { if (i == arr.Count) { return; } HotkeyItem a = (HotkeyItem)arr[i]; Hotkey hk = createHotkey(a.Ctr, a.Alt, a.Shift, a.Key); hk.Pressed += delegate { Audio.playSound(AudioDevice, a.AudioFile); }; hk.Register(f1); arrHotkeyRegistered.Add(hk); i++; SingleStepAddHotkey(i, arr); }
private void btnEdit_Click(object sender, EventArgs e) { if (current_edit_id < 0) { btnAdd_Click(sender, e); return; } HotkeyItem a = getHotkeyItemInForm(); String test_item = ValidateHotkeyItem(a); if (test_item != "true") { Form1.ShowMessage(test_item); return; } Model.Edit(current_edit_id, a); current_edit_id = -1; ShowListView(); clearInputData(); }
private void btnAdd_Click(object sender, EventArgs e) { HotkeyItem a = getHotkeyItemInForm(); String validate_hotkey = ValidateHotkeyItem(a); if (validate_hotkey != "true") { Form1.ShowMessage(validate_hotkey); } else if (Model.Add(a)) { ShowListView(); btnEdit.Enabled = false; btnRemove.Enabled = false; } else { Form1.ShowMessage("Hotkey " + a.getHotkey() + " is already exist"); } }