// "Add" Button private void AddBtn_Click(object sender, EventArgs e) { MapNoteItem newMapNoteItem = new MapNoteItem() { KeyName = "New Note Map", TriggerNoteNumber = 60, // C4 OutputBytesStringOn = "", OutputBytesStringOff = "" }; bool complete = false; while (!complete) { MapNoteDetailsUI dlg = new MapNoteDetailsUI(newMapNoteItem); if (dlg.ShowDialog(this) == DialogResult.OK) { // Check if the NoteMap already exists, and prompt for replacement if (_plugin.NoteMap.Contains(dlg.TempMapNoteItem.TriggerNoteNumber)) { if (MessageBox.Show(this, String.Format("A mapping with Note# {0} already exists. Replace?", dlg.TempMapNoteItem.TriggerNoteNumber), "Add a Note Map Item.", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { // Remove the old entry Could use the ChangeItemKey Method here, but let's start simple. _plugin.NoteMap.Remove(dlg.TempMapNoteItem.TriggerNoteNumber); } else { newMapNoteItem = dlg.TempMapNoteItem; // This is a bit wonky, but persists the note item for the next iteration. continue; // Show the dialog again } } // if // Add new entry _plugin.NoteMap.Add(dlg.TempMapNoteItem); complete = true; // Successfully added } else { complete = true; // Successfully cancelled } } // while FillList(); }
// "Edit" Button private void EditBtn_Click(object sender, EventArgs e) { // Exit if nothing selected if (MapListVw.SelectedItems.Count == 0) { return; } byte oldTriggerNoteNum = Byte.Parse(MapListVw.SelectedItems[0].Name); // .Name was filled in by FillList if (_plugin.NoteMap.Contains(oldTriggerNoteNum)) { MapNoteItem tempItem = new MapNoteItem { KeyName = _plugin.NoteMap[oldTriggerNoteNum].KeyName, TriggerNoteNumber = oldTriggerNoteNum, OutputBytesStringOn = _plugin.NoteMap[oldTriggerNoteNum].OutputBytesStringOn, OutputBytesStringOff = _plugin.NoteMap[oldTriggerNoteNum].OutputBytesStringOff }; MapNoteDetailsUI dlg = new MapNoteDetailsUI(tempItem); bool complete = false; while (!complete) { if (dlg.ShowDialog(this) == DialogResult.OK) { // Check if the NoteMap changed, but already exists in the list if ((dlg.TempMapNoteItem.TriggerNoteNumber != oldTriggerNoteNum) && (_plugin.NoteMap.Contains(dlg.TempMapNoteItem.TriggerNoteNumber))) { MessageBox.Show(this, String.Format("A mapping with Note# {0} already exists.", dlg.TempMapNoteItem.TriggerNoteNumber), "Edit a Note Map Item."); continue; // Show dialog again } // Remove the old entry Could use the ChangeItemKey Method here, but let's keep it simple. if (_plugin.NoteMap.Remove(oldTriggerNoteNum)) { // Add new entry _plugin.NoteMap.Add(dlg.TempMapNoteItem); complete = true; // Successfully replaced } else { MessageBox.Show("(Edit) Logic Error: Remove Failed! oldTriggerNoteNum=" + oldTriggerNoteNum); break; } } else { complete = true; // Successfully cancelled } } // while FillList(); } else { MessageBox.Show("(Edit) Logic Error: oldTriggerNoteNum=" + oldTriggerNoteNum + " is in table but was not found in list."); } }
// "Edit" Button private void EditBtn_Click(object sender, EventArgs e) { // Exit if nothing selected if (MapListVw.SelectedItems.Count == 0) return; byte oldTriggerNoteNum = Byte.Parse(MapListVw.SelectedItems[0].Name); // .Name was filled in by FillList if (_plugin.NoteMap.Contains(oldTriggerNoteNum)) { MapNoteItem tempItem = new MapNoteItem { KeyName = _plugin.NoteMap[oldTriggerNoteNum].KeyName, TriggerNoteNumber = oldTriggerNoteNum, OutputBytesStringOn = _plugin.NoteMap[oldTriggerNoteNum].OutputBytesStringOn, OutputBytesStringOff = _plugin.NoteMap[oldTriggerNoteNum].OutputBytesStringOff }; MapNoteDetailsUI dlg = new MapNoteDetailsUI(tempItem); bool complete = false; while (!complete) { if (dlg.ShowDialog(this) == DialogResult.OK) { // Check if the NoteMap changed, but already exists in the list if ( (dlg.TempMapNoteItem.TriggerNoteNumber != oldTriggerNoteNum) && (_plugin.NoteMap.Contains(dlg.TempMapNoteItem.TriggerNoteNumber)) ) { MessageBox.Show(this, String.Format("A mapping with Note# {0} already exists.", dlg.TempMapNoteItem.TriggerNoteNumber), "Edit a Note Map Item."); continue; // Show dialog again } // Remove the old entry Could use the ChangeItemKey Method here, but let's keep it simple. if (_plugin.NoteMap.Remove(oldTriggerNoteNum)) { // Add new entry _plugin.NoteMap.Add(dlg.TempMapNoteItem); complete = true; // Successfully replaced } else { MessageBox.Show("(Edit) Logic Error: Remove Failed! oldTriggerNoteNum=" + oldTriggerNoteNum); break; } } else { complete = true; // Successfully cancelled } } // while FillList(); } else { MessageBox.Show("(Edit) Logic Error: oldTriggerNoteNum=" + oldTriggerNoteNum + " is in table but was not found in list."); } }
// "Add" Button private void AddBtn_Click(object sender, EventArgs e) { MapNoteItem newMapNoteItem = new MapNoteItem() { KeyName = "New Note Map", TriggerNoteNumber = 60, // C4 OutputBytesStringOn = "", OutputBytesStringOff = "" }; bool complete = false; while (!complete) { MapNoteDetailsUI dlg = new MapNoteDetailsUI(newMapNoteItem); if (dlg.ShowDialog(this) == DialogResult.OK) { // Check if the NoteMap already exists, and prompt for replacement if (_plugin.NoteMap.Contains(dlg.TempMapNoteItem.TriggerNoteNumber)) { if (MessageBox.Show(this, String.Format("A mapping with Note# {0} already exists. Replace?", dlg.TempMapNoteItem.TriggerNoteNumber), "Add a Note Map Item.", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { // Remove the old entry Could use the ChangeItemKey Method here, but let's start simple. _plugin.NoteMap.Remove(dlg.TempMapNoteItem.TriggerNoteNumber); } else { newMapNoteItem = dlg.TempMapNoteItem; // This is a bit wonky, but persists the note item for the next iteration. continue; // Show the dialog again } } // if // Add new entry _plugin.NoteMap.Add(dlg.TempMapNoteItem); complete = true; // Successfully added } else { complete = true; // Successfully cancelled } } // while FillList(); }