/// <summary> /// Removes a specified slide from this part (can be undone). /// </summary> /// <param name="slide"></param> public void RemoveSlide(SongSlide slide) { if (slide == null) { throw new ArgumentNullException("slide"); } if (Slides.Count <= 1) { throw new InvalidOperationException("Can't remove last slide in a part."); } int i = Slides.IndexOf(slide); if (i < 0) { throw new InvalidOperationException("Slide is not in this part."); } Undo.ChangeFactory.OnChanging(this, () => { slides.Insert(i, slide); }, () => { slides.Remove(slide); }, "RemoveSlide"); slides.Remove(slide); }
/// <summary> /// Duplicates the specified part and inserts the copy /// directly after the original slide in the same part (can be undone). /// </summary> /// <param name="slide">The slide to duplicate.</param> /// <returns>The created duplicate.</returns> public SongSlide DuplicateSlide(SongSlide slide) { SongSlide s; int i = Slides.IndexOf(slide); using (Undo.ChangeFactory.Batch(this, "DuplicateSlide")) { s = slide.Copy(); Undo.ChangeFactory.OnChanging(this, () => { slides.Remove(s); }, () => { slides.Insert(i + 1, s); }, "DuplicateSlide"); slides.Insert(i + 1, s); } return(s); }
/// <summary> /// Inserts a slide after a specified target slide in this part (can be undone). /// </summary> /// <param name="slide">The slide to insert.</param> /// <param name="target">The target slide. Must be contained in this part.</param> public void InsertSlideAfter(SongSlide slide, SongSlide target) { var index = Slides.IndexOf(target); if (index < 0) { throw new InvalidOperationException("Slide is not in this part."); } if (index >= Slides.Count - 1) { AddSlide(slide); } else { Undo.ChangeFactory.OnChanging(this, () => { slides.Remove(slide); }, () => { slides.Insert(index + 1, slide); }, "InsertSlideAfter"); slides.Insert(index + 1, slide); } }