public void addSlide(Slide slide, int index = -1) { if (index == -1) { slideshow.addSlide(slide); } else { slideshow.insertSlide(index, slide); } if (!editorController.ResourceProvider.exists(slide.UniqueName)) { editorController.ResourceProvider.createDirectory("", slide.UniqueName); } if (SlideAdded != null) { SlideAdded.Invoke(slide, index); } //Delay this till the next frame, so the rml has actually been rendererd ThreadManager.invoke(new Action(delegate() { if (slideEditorContext != null) { slideEditorContext.updateThumbnail(); } })); if (allowUndoCreation) { if (lastEditSlide == null) { undoBuffer.pushAndSkip(new TwoWayDelegateCommand <SlideInfo>(new SlideInfo(slide, slideshow.indexOf(slide)), new TwoWayDelegateCommand <SlideInfo> .Funcs() { ExecuteFunc = (executeSlide) => { allowUndoCreation = false; addSlide(executeSlide.Slide, executeSlide.Index); allowUndoCreation = true; }, UndoFunc = (undoSlide) => { allowUndoCreation = false; removeSlide(undoSlide.Slide); allowUndoCreation = true; }, TrimmedFunc = cleanupThumbnail, } )); } else { undoBuffer.pushAndSkip(new TwoWayDelegateCommand <RemoveSlideInfo>(new RemoveSlideInfo(slide, index, lastEditSlide), new TwoWayDelegateCommand <RemoveSlideInfo> .Funcs() { ExecuteFunc = (executeSlide) => { //Hacky, but we cannot modify the active slide without messing up the classes that triggered this. ThreadManager.invoke(new Action(delegate() { allowUndoCreation = false; addSlide(executeSlide.Slide, executeSlide.Index); if (SlideSelected != null) { SlideSelected.Invoke(executeSlide.Slide, IEnumerableUtil <Slide> .EmptyIterator); } allowUndoCreation = true; })); }, UndoFunc = (undoSlide) => { //Hacky, but we cannot modify the active slide without messing up the classes that triggered this. ThreadManager.invoke(new Action(delegate() { allowUndoCreation = false; if (SlideSelected != null) { SlideSelected.Invoke(undoSlide.ChangeToSlide, IEnumerableUtil <Slide> .EmptyIterator); } removeSlide(undoSlide.Slide); allowUndoCreation = true; })); }, TrimmedFunc = cleanupThumbnail })); } } bool wasAllowingUndo = allowUndoCreation; allowUndoCreation = false; if (SlideSelected != null) { SlideSelected.Invoke(slide, IEnumerableUtil <Slide> .EmptyIterator); } allowUndoCreation = wasAllowingUndo; }