private void addbutton_Click(object sender, EventArgs e) { if (openFileDialog.ShowDialog() == DialogResult.OK) { string fileName = Path.GetFileName(openFileDialog.FileName); //If a file already exists with the same name, do not allow to add foreach (var kvp in project.musics) { if (kvp.Key.ToLower() == fileName.ToLower()) { MessageBox.Show("A file with the same name already exists!", "Cannot add sound/music"); return; } } BigFile contents = new BigFile(System.IO.File.ReadAllBytes(openFileDialog.FileName)); var list = new Undo.UndoCommandList("Add music " + fileName, new Undo.UndoCommand( delegate() { project.musics.Add(fileName, contents); }, delegate() { project.musics.Remove(fileName); } )); project.Undo.DoCommand(list); } }
public void RemoveMusic(BigFile music) { var list = new UndoCommandList("Remove audio file"); RemoveMusic(music, list); Undo.DoCommand(list); }
public void RemoveMusic(BigFile music, UndoCommandList list) { string name = null; foreach (var m in musics) { if (m.Value == music) { name = m.Key; } } if (name == null) throw new ArgumentException("Music is not in the list!"); list.Add(new UndoCommand( delegate() { musics.Remove(name); }, delegate() { musics.Add(name, music); } )); }