private void ExecuteBlurAction(string feature, Selection selection, Models.PowerPointPresentation pres, Models.PowerPointSlide slide, int percentage) { ClipboardUtil.RestoreClipboardAfterAction(() => { switch (feature) { case EffectsLabText.BlurrinessFeatureSelected: EffectsLabBlur.ExecuteBlurSelected(slide, selection, percentage); break; case EffectsLabText.BlurrinessFeatureRemainder: EffectsLabBlur.ExecuteBlurRemainder(slide, selection, percentage); break; case EffectsLabText.BlurrinessFeatureBackground: EffectsLabBlur.ExecuteBlurBackground(slide, selection, percentage); break; default: Logger.Log(feature + " does not exist!", Common.Logger.LogType.Error); break; } return(ClipboardUtil.ClipboardRestoreSuccess); }, pres, slide); }
public static void SaveFile(Models.PowerPointPresentation currentPresentation) { // Opens up a new Save File Dialog SaveFileDialog saveFileDialog = new SaveFileDialog(); Models.PowerPointPresentation newPresentation; List <Models.PowerPointSlide> selectedSlides = currentPresentation.SelectedSlides; // Setting for Save File Dialog saveFileDialog.InitialDirectory = SaveLabSettings.GetSaveFolderPath(); saveFileDialog.Filter = "PowerPoint Presentations|*.pptx"; saveFileDialog.Title = "Save Selected Slides"; saveFileDialog.OverwritePrompt = true; if (saveFileDialog.ShowDialog() == DialogResult.OK) { // Copy the Current Presentation under a new name currentPresentation.Presentation.SaveCopyAs(saveFileDialog.FileName, PpSaveAsFileType.ppSaveAsDefault); try { // Re-open the save copy in the same directory in the background Presentations newPres = new Microsoft.Office.Interop.PowerPoint.Application().Presentations; Presentation tempPresentation = newPres.Open(saveFileDialog.FileName, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse); newPresentation = new Models.PowerPointPresentation(tempPresentation); // Hashset to store the unique IDs of selected slides HashSet <int> idHash = new HashSet <int>(); foreach (Models.PowerPointSlide selectedSlide in selectedSlides) { idHash.Add(selectedSlide.ID); } // Check each slide in new presentation and remove un-selected slides using unique slide ID for (int i = newPresentation.SlideCount - 1; i >= 0; i--) { if (!idHash.Contains(newPresentation.Slides[i].ID)) { newPresentation.RemoveSlide(i); } } // Check for and remove empty sections in new presentation if (newPresentation.HasEmptySection) { newPresentation.RemoveEmptySections(); } // Save and then close the presentation newPresentation.Save(); newPresentation.Close(); } catch (System.Runtime.InteropServices.COMException) { // do nothing as file is successfully copied } } }
protected override void ExecuteAction(string ribbonId) { Selection currentSelection = this.GetCurrentSelection(); Models.PowerPointPresentation currentPresentation = this.GetCurrentPresentation(); // Check the type of selection and ensure that it is a slide and that the number of slides selected is >= 1 if (currentSelection.Type == PpSelectionType.ppSelectionSlides && currentSelection.SlideRange.Count >= 1) { // Perform the actual save action SaveLabMain.SaveFile(currentPresentation); } else { // If no slides return error message or do nothing MessageBox.Show(SaveLabText.ErrorZeroSlidesSelected, CommonText.ErrorSlideSelectionTitle); } }
protected override void ExecuteAction(string ribbonId) { this.StartNewUndoEntry(); Models.PowerPointPresentation pres = this.GetCurrentPresentation(); bool isButton = false; bool isCustom = ribbonId.Contains(EffectsLabText.BlurrinessCustom); int keywordIndex; if (ribbonId.Contains(CommonText.DynamicMenuButtonId)) { isButton = true; keywordIndex = ribbonId.IndexOf(CommonText.DynamicMenuButtonId); } else { keywordIndex = ribbonId.IndexOf(CommonText.DynamicMenuOptionId); } string feature = ribbonId.Substring(0, keywordIndex); Selection selection = this.GetCurrentSelection(); Models.PowerPointSlide slide = this.GetCurrentSlide(); if (isButton) { EffectsLabSettings.ShowBlurSettingsDialog(feature); this.GetRibbonUi().RefreshRibbonControl(feature + CommonText.DynamicMenuOptionId + EffectsLabText.BlurrinessCustom); } else { int startIndex = keywordIndex + CommonText.DynamicMenuOptionId.Length; int percentage = isCustom ? GetCustomPercentage(feature) : int.Parse(ribbonId.Substring(startIndex, ribbonId.Length - startIndex)); ExecuteBlurAction(feature, selection, pres, slide, percentage); } }