private void addButton_Click(object sender, EventArgs e) { using(AnimationDialog dialog = new AnimationDialog(project)) { if (dialog.ShowDialog(this) == DialogResult.OK) { string name = dialog.AnimationName; var anim = dialog.Animation; var list = new Undo.UndoCommandList("Add animation " + name, new Undo.UndoCommand( delegate() { project.animations.Add(name, anim); }, delegate() { project.animations.Remove(name); } )); project.Undo.DoCommand(list); } } }
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); } }
private void listBox_DoubleClick(object sender, EventArgs e) { if (listBox.SelectedIndex == -1) return; var animKvp = (KeyValuePair<string, Animation>)listBox.SelectedItem; Animation anim = animKvp.Value; string name = animKvp.Key; using(AnimationDialog dialog = new AnimationDialog(anim, project)) { if (dialog.ShowDialog(this) == DialogResult.OK) { Animation newAnim = dialog.Animation; string newName = dialog.AnimationName; var oldGroups = anim.groups; var oldSheet = anim.sheet; var list = new Undo.UndoCommandList("Modify sprite " + anim.Name, new Undo.UndoCommand( delegate() { anim.groups = newAnim.groups; anim.sheet = newAnim.sheet; if (name != newName) { project.animations.Remove(name); project.animations.Add(newName, anim); } }, delegate() { anim.groups = oldGroups; anim.sheet = oldSheet; if (name != newName) { project.animations.Remove(newName); project.animations.Add(name, anim); } } )); project.Undo.DoCommand(list); } } }