private PowerPointShapeGalleryPresentation PrepareImportGallery(string importFilePath, bool fromCategory)
        {
            var importFileCopyPath = Path.Combine(ShapeRootFolderPath, ImportFileCopyName);

            // copy the file to the current shape root if the file is not under root 
            if (!File.Exists(importFileCopyPath))
            {
                File.Copy(importFilePath, importFileCopyPath);
            }

            // init the file as an imported file
            var importShapeGallery = new PowerPointShapeGalleryPresentation(ShapeRootFolderPath,
                                                                            ImportFileNameNoExtension)
                                         {
                                             IsImportedFile = true,
                                             ImportToCategory = fromCategory ? string.Empty : CurrentCategory
                                         };

            return importShapeGallery;
        }
        private void ImportShapesFromLibrary(PowerPointShapeGalleryPresentation importShapeGallery)
        {
            foreach (var importCategory in importShapeGallery.Categories)
            {
                importShapeGallery.CopyCategory(importCategory);

                Globals.ThisAddIn.ShapePresentation.AddCategory(importCategory, false, true);

                _categoryBinding.Add(importCategory);
            }
        }
        private void ImportShapesFromSingleShape(PowerPointShapeGalleryPresentation importShapeGallery)
        {
            var shapeRange = importShapeGallery.Slides[0].Shapes.Range();

            if (shapeRange.Count < 1) return;

            var shapeName = shapeRange[1].Name;

            if (shapeRange.Count > 1)
            {
                shapeName = TextCollection.CustomShapeDefaultShapeName;
                importShapeGallery.CopyShape();
            }
            else
            {
                importShapeGallery.CopyShape(shapeName);
            }

            shapeName = Globals.ThisAddIn.ShapePresentation.AddShape(null, shapeName, fromClipBoard: true);
            var exportPath = Path.Combine(CurrentShapeFolderPath, shapeName + ".png");

            Graphics.ExportShape(shapeRange, exportPath);
        }
Esempio n. 4
0
        public void InitializeShapeGallery()
        {
            // achieves singleton ShapePresentation
            if (ShapePresentation != null) return;

            var shapeRootFolderPath = ShapesLabConfigs.ShapeRootFolder;

            ShapePresentation =
                new PowerPointShapeGalleryPresentation(shapeRootFolderPath, ShapeGalleryPptxName);

            if (!ShapePresentation.Open(withWindow: false, focus: false) &&
                !ShapePresentation.Opened)
            {
                // if the presentation gets some error during opening, and the error could not
                // be resolved by consistency check, prompt the user about the error
                MessageBox.Show(TextCollection.ShapeGalleryInitErrorMsg);
                return;
            }

            if (ShapePresentation.HasCategory(ShapesLabConfigs.DefaultCategory))
            {
                ShapePresentation.DefaultCategory = ShapesLabConfigs.DefaultCategory;

                return;
            }

            // if we do not have the default category, create and add it to ShapeGallery
            ShapePresentation.AddCategory(ShapesLabConfigs.DefaultCategory);
            ShapePresentation.Save();
        }