private void InformCacheListenersOnItemRemoved(ShapeFavorite removedItem)
 {
     foreach (CacheListener listener in cacheListeners)
     {
         listener.OnItemRemoved(removedItem);
     }
 }
 private void InformCacheListenersOnItemAdded(ShapeFavorite addedItem)
 {
     foreach (CacheListener listener in cacheListeners)
     {
         listener.OnItemAdded(addedItem);
     }
 }
Beispiel #3
0
        private void DrawShape(ShapeFavorite shape, Panel panel)
        {
            var index      = panel.Controls.Count;
            var pictureBox = GetPictureBox(shape, index);

            panel.Controls.Add(pictureBox);
            this.displayedShapes.Add(pictureBox, shape);
        }
        internal void DeleteShape(ShapeFavorite shapeFavorite)
        {
            logger.Log("Deleting shape of type " + shapeFavorite.Shape.Type);
            var thumbnail = GetThumbnailPath(shapeFavorite);

            this.DeleteIfExtant(shapeFavorite.FilePath, thumbnail);
            CachedShapes.Remove(shapeFavorite);
            this.InformCacheListenersOnItemRemoved(shapeFavorite);
        }
        internal string GetThumbnail(ShapeFavorite shape)
        {
            var thumbnailPath = GetThumbnailPath(shape);

            if (!System.IO.File.Exists(thumbnailPath))
            {
                logger.Log("Thumbnail does not exist. Creating one.");
                var temporaryPresentation = Globals.ThisAddIn.Application.Presentations.Open(shape.FilePath, Core.MsoTriState.msoTrue, Core.MsoTriState.msoTrue, Core.MsoTriState.msoFalse);
                var targetSlide           = temporaryPresentation.Slides[1];
                var targetShape           = targetSlide.Shapes[1];
                CreateThumbnail(thumbnailPath, targetShape);
                temporaryPresentation.Close();
            }
            return(thumbnailPath);
        }
Beispiel #6
0
        private PictureBox GetPictureBox(ShapeFavorite shape, int index)
        {
            var pictureBox = new PictureBox();

            pictureBox.Height = 100;
            pictureBox.Width  = 100;
            int column = index % 2;
            int row    = (index - (index % 2)) / 2;

            pictureBox.Location          = new Point(4 + (column * 120), 4 + (row * 120));
            pictureBox.Image             = shape.Thumbnail;
            pictureBox.SizeMode          = PictureBoxSizeMode.Zoom;
            pictureBox.MouseDoubleClick += new MouseEventHandler((sender, args) => HandlePictureBoxDoubleClick(shape));
            pictureBox.ContextMenu       = GetContextMenu(pictureBox);
            return(pictureBox);
        }
        public bool Move(ShapeFavorite shapeFavorite, bool up, bool toLimit)
        {
            logger.Log("Moving shapeFavorite: " + shapeFavorite + (up ? " up" : " down"));
            var shapeFavorites = new List <ShapeFavorite>(CachedShapes);
            int targetIndex    = GetTargetIndexForMoveOperation(shapeFavorites, shapeFavorite, up, toLimit);

            if (targetIndex == -1)
            {
                logger.Log("Cannot move shape in the given direction.");
                return(false);
            }
            logger.Log("Setting targetIndex for move operation: " + targetIndex);
            shapeFavorites.Remove(shapeFavorite);
            shapeFavorites.Insert(targetIndex, shapeFavorite);
            CachedShapes = shapeFavorites;
            return(true);
        }
        public bool SaveShapeFromClipBoard(Shape shape)
        {
            var temporaryPresentation = Globals.ThisAddIn.Application.Presentations.Add(Core.MsoTriState.msoFalse);
            var targetSlide           = temporaryPresentation.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutBlank);
            var newUuid         = Guid.NewGuid().ToString();
            var fileName        = GetFileName(newUuid);
            var persistenceFile = GetPersistenceFile(fileName);

            try
            {
                targetSlide.Shapes.Paste();
            }
            catch (Exception e)
            {
                logger.Log("Clipboard content could not be pasted. " + e.Message);
                temporaryPresentation.Close();
                return(false);
            }
            logger.Log("Saving shape.");
            var cachedShapes = CachedShapes; // ensure this is already loaded before saving!

            logger.Log("Saving shape of type " + targetSlide.Shapes[1]);
            temporaryPresentation.SaveAs(persistenceFile, PowerPoint.PpSaveAsFileType.ppSaveAsOpenXMLPresentation, Core.MsoTriState.msoFalse);
            temporaryPresentation.Close();
            //we reload this since the shape's type seems not to be known otherwise...
            var shapeToSave = new ShapeFavorite(persistenceFile, this.GetShapesFromFile(persistenceFile).First()); // there is only one shape in this file

            if (shape == null)
            {
                this.GetThumbnail(shapeToSave); //create thumbnail
            }
            else
            {
                this.CreateThumbnail(GetThumbnailPath(shapeToSave), shape);
            }
            cachedShapes.Add(shapeToSave);
            InformCacheListenersOnItemAdded(shapeToSave);
            return(true);
        }
Beispiel #9
0
        private void SetCenterLocation(ShapeFavorite shape)
        {
            PowerPoint.Presentation currentPresentation = Globals.ThisAddIn.Application.ActivePresentation;
            var slideHeight = currentPresentation.PageSetup.SlideHeight;
            var slideWidth  = currentPresentation.PageSetup.SlideWidth;
            var centerLeft  = 0F;
            var centerTop   = 0F;

            if (shape.Shape.Type != Core.MsoShapeType.msoTextBox)
            {
                var shapeHeight = shape.Shape.Height;
                var shapeWidth  = shape.Shape.Width;
                centerLeft = slideWidth / 2 - (shapeWidth / 2);
                centerTop  = slideHeight / 2 - (shapeHeight / 2);
            }
            else
            {
                centerLeft = slideWidth / 2;
                centerTop  = slideHeight / 2;
            }
            shape.Shape.Left = centerLeft;
            shape.Shape.Top  = centerTop;
        }
Beispiel #10
0
 public void PasteToCurrentPresentation(ShapeFavorite shape)
 {
     SetCenterLocation(shape);
     shape.Shape.Copy();
     this.PasteToCurrentPresentation();
 }
Beispiel #11
0
 private void HandlePictureBoxDoubleClick(ShapeFavorite shape)
 {
     logger.Log("Double click on picture box. Pasting shape.");
     this.shapeService.PasteToCurrentPresentation(shape);
 }
Beispiel #12
0
 internal bool MoveDownShape(ShapeFavorite shapeFavorite)
 {
     return(this.shapePersistance.Move(shapeFavorite, false, false));
 }
Beispiel #13
0
 internal bool MoveShapeToBottom(ShapeFavorite shapeFavorite)
 {
     return(this.shapePersistance.Move(shapeFavorite, false, true));
 }
Beispiel #14
0
 private string GetThumbnailPath(ShapeFavorite shape)
 {
     return(shape.FilePath.Replace(PERSISTENCE_EXTENSION, PNG_EXTENSION));
 }
Beispiel #15
0
 internal bool MoveShapeToTop(ShapeFavorite shapeFavorite)
 {
     return(this.shapePersistance.Move(shapeFavorite, true, true));
 }
Beispiel #16
0
        private int GetTargetIndexForMoveOperation(List <ShapeFavorite> shapeFavorites, ShapeFavorite shapeFavorite, bool up, bool toLimit)
        {
            int targetIndex = -1;

            for (int i = 0; i < shapeFavorites.Count; i++)
            {
                var currentIndex = up ? i : shapeFavorites.Count - 1 - i;
                var currentShape = shapeFavorites[currentIndex];
                if (IsPeerShapeType(currentShape.Shape.Type, shapeFavorite.Shape.Type) && !(currentShape.Equals(shapeFavorite)))
                {
                    targetIndex = currentIndex;
                    if (toLimit)
                    {
                        break;
                    }
                }
                if (currentShape.Equals(shapeFavorite))
                {
                    break;
                }
            }
            return(targetIndex);
        }
Beispiel #17
0
 public void OnItemRemoved(ShapeFavorite removedItem)
 {
     logger.Log("ItemRemovedListener fired.");
     this.sharedFavView.RedrawFavorites(); //it would be difficult to do this incrementally since that would imply reordering of the picture boxes...
 }
Beispiel #18
0
 public void OnItemAdded(ShapeFavorite addedItem)
 {
     WriteStructure();
 }
Beispiel #19
0
 internal void DeleteShape(ShapeFavorite shapeFavorite)
 {
     this.shapePersistance.DeleteShape(shapeFavorite);
 }
Beispiel #20
0
 public void OnItemRemoved(ShapeFavorite removedItem)
 {
     WriteStructure();
 }
Beispiel #21
0
 void ShapePersistence.CacheListener.OnItemRemoved(ShapeFavorite removedItem)
 {
     this.redrawRibbon();
 }
Beispiel #22
0
 public void OnItemAdded(ShapeFavorite addedItem)
 {
     logger.Log("ItemAddedListener fired.");
     this.sharedFavView.DrawShape(addedItem, this.sharedFavView.panels[addedItem.Shape.Type]);
 }