Example #1
0
        protected void AddSelectedShapes(IFile libraryFile)
        {
            PPT.Application    ppt = null;
            PPT.Presentation   pr  = null;
            PPT.DocumentWindow aw  = null;
            PPT.Selection      sel = null;

            try
            {
                timerCheckForUpdates.Enabled = false;

                ppt = new PPT.Application();
                pr  = ppt.ActivePresentation;

                if (pr.FullName == libraryFile.FullPath)
                {
                    MessageBox.Show("You can't add slides to the same presentation");
                    return;
                }

                aw  = ppt.ActiveWindow;
                sel = aw.Selection;
                List <PPT.Shape> shapesToAdd = new List <PPT.Shape>();

                if (sel.Type == PPT.PpSelectionType.ppSelectionShapes)
                {
                    foreach (PPT.Shape slide in sel.ShapeRange)
                    {
                        shapesToAdd.Add(slide);
                    }
                }
                else
                {
                    shapesToAdd.Add(aw.View.Slide as PPT.Shape);
                }

                if (shapesToAdd.Count > 0)
                {
                    libraryFile.AppendShapes(shapesToAdd);
                    uxImagesView.DataSource = LibraryData.GetAllItems().ToList();
                    Filter();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                sel.ReleaseCOM();
                sel = null;

                pr.ReleaseCOM();
                pr = null;

                aw.ReleaseCOM();
                aw = null;

                ppt.ReleaseCOM();
                ppt = null;

                timerCheckForUpdates.Enabled = !needsUpdate;
            }
        }
Example #2
0
        private void InsertItem(IFileItem item)
        {
            if (item == null)
            {
                return;
            }

            PPT.Application   app  = new PPT.Application();
            PPT.Presentations pres = app.Presentations;

            PPT.Presentation pptx   = pres.Open(item.File.FullPath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
            PPT.Slides       slides = pptx.Slides;
            PPT.Slide        slide  = slides[item.Index];

            if (item.Type == ItemType.Slide)
            {
                slide.Copy();
            }
            else
            {
                PPT.Shapes shapes = slide.Shapes;
                PPT.Shape  shape  = shapes[1];

                shape.Copy();

                shapes.ReleaseCOM();
                shapes = null;
                shape.ReleaseCOM();
                shape = null;
            }

            PPT.Presentation dstpptx = app.ActivePresentation;

            PPT.DocumentWindow wnd  = app.ActiveWindow;
            PPT.View           view = wnd.View;

            //TODO: Check if there is no selection (selection between slides)
            PPT.Slides dstSlides = dstpptx.Slides;
            PPT.Slide  dstSlide  = null;

            dstSlide = view.Slide as PPT.Slide;
            int ix = dstSlide.SlideIndex + 1;

            if (item.Type == ItemType.Slide)
            {
                dstSlide.Copy();

                var r = dstSlides.Paste(); //TODO: dstSlides.Paste(ix) Hangs here
                var s = r[1];

                s.MoveTo(ix);

                s.ReleaseCOM();
                s = null;

                r.ReleaseCOM();
                r = null;
            }
            else
            {
                view.Paste();
            }

            dstSlide.ReleaseCOM();
            dstSlide = null;

            wnd.ReleaseCOM();
            wnd = null;

            view.ReleaseCOM();
            view = null;

            dstpptx.ReleaseCOM();
            dstpptx = null;


            slide.ReleaseCOM();
            slide = null;

            slides.ReleaseCOM();
            slides = null;

            pptx.Close();
            pptx.ReleaseCOM();
            pptx = null;

            pres.ReleaseCOM();
            pres = null;

            app.ReleaseCOM();
            app = null;

            dstSlides.ReleaseCOM();
            dstSlides = null;
        }