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); } }
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); }
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); }
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; }
public void PasteToCurrentPresentation(ShapeFavorite shape) { SetCenterLocation(shape); shape.Shape.Copy(); this.PasteToCurrentPresentation(); }
private void HandlePictureBoxDoubleClick(ShapeFavorite shape) { logger.Log("Double click on picture box. Pasting shape."); this.shapeService.PasteToCurrentPresentation(shape); }
internal bool MoveDownShape(ShapeFavorite shapeFavorite) { return(this.shapePersistance.Move(shapeFavorite, false, false)); }
internal bool MoveShapeToBottom(ShapeFavorite shapeFavorite) { return(this.shapePersistance.Move(shapeFavorite, false, true)); }
private string GetThumbnailPath(ShapeFavorite shape) { return(shape.FilePath.Replace(PERSISTENCE_EXTENSION, PNG_EXTENSION)); }
internal bool MoveShapeToTop(ShapeFavorite shapeFavorite) { return(this.shapePersistance.Move(shapeFavorite, true, true)); }
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); }
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... }
public void OnItemAdded(ShapeFavorite addedItem) { WriteStructure(); }
internal void DeleteShape(ShapeFavorite shapeFavorite) { this.shapePersistance.DeleteShape(shapeFavorite); }
public void OnItemRemoved(ShapeFavorite removedItem) { WriteStructure(); }
void ShapePersistence.CacheListener.OnItemRemoved(ShapeFavorite removedItem) { this.redrawRibbon(); }
public void OnItemAdded(ShapeFavorite addedItem) { logger.Log("ItemAddedListener fired."); this.sharedFavView.DrawShape(addedItem, this.sharedFavView.panels[addedItem.Shape.Type]); }