From b185e071ef2b865af8e976a3d69158f4649744db Mon Sep 17 00:00:00 2001 From: Heiko Joerg Schick Date: Sun, 9 Mar 2025 15:59:31 +0100 Subject: [PATCH] Added implementations for alignment buttoms. --- src/taskpane/components/AlignmentButtons.tsx | 108 +++++++++++++++++-- 1 file changed, 102 insertions(+), 6 deletions(-) diff --git a/src/taskpane/components/AlignmentButtons.tsx b/src/taskpane/components/AlignmentButtons.tsx index 6d8a8fde..49b38d4c 100644 --- a/src/taskpane/components/AlignmentButtons.tsx +++ b/src/taskpane/components/AlignmentButtons.tsx @@ -44,8 +44,24 @@ export const AlignmentButtons: React.FC = () => { setIsProcessing(true); try { await PowerPoint.run(async (context) => { + // Get the selected shapes const shapes = context.presentation.getSelectedShapes(); - // Implementation will go here + shapes.load("items"); + await context.sync(); + + // Check if shapes are selected + if (shapes.items.length === 0) { + setStatusMessage("No shapes are selected. Please select shapes first."); + setStatusType("warning"); + return; + } + + // Loop through all select shapes and align them + for (let i = 0; i < shapes.items.length; i++) { + shapes.items[i].left = 81.1; + } + await context.sync(); + setStatusMessage("Objects aligned to left."); setStatusType("success"); }); @@ -62,8 +78,24 @@ export const AlignmentButtons: React.FC = () => { setIsProcessing(true); try { await PowerPoint.run(async (context) => { + // Get the selected shapes const shapes = context.presentation.getSelectedShapes(); - // Implementation will go here + shapes.load("items"); + await context.sync(); + + // Check if shapes are selected + if (shapes.items.length === 0) { + setStatusMessage("No shapes are selected. Please select shapes first."); + setStatusType("warning"); + return; + } + + // Loop through all select shapes and align them + for (let i = 0; i < shapes.items.length; i++) { + shapes.items[i].left = 480 - (shapes.items[i].width / 2); + } + await context.sync(); + setStatusMessage("Objects aligned to center."); setStatusType("success"); }); @@ -80,8 +112,24 @@ export const AlignmentButtons: React.FC = () => { setIsProcessing(true); try { await PowerPoint.run(async (context) => { + // Get the selected shapes const shapes = context.presentation.getSelectedShapes(); - // Implementation will go here + shapes.load("items"); + await context.sync(); + + // Check if shapes are selected + if (shapes.items.length === 0) { + setStatusMessage("No shapes are selected. Please select shapes first."); + setStatusType("warning"); + return; + } + + // Loop through all select shapes and align them + for (let i = 0; i < shapes.items.length; i++) { + shapes.items[i].left = 879.75 - shapes.items[i].width; + } + await context.sync(); + setStatusMessage("Objects aligned to right."); setStatusType("success"); }); @@ -98,8 +146,24 @@ export const AlignmentButtons: React.FC = () => { setIsProcessing(true); try { await PowerPoint.run(async (context) => { + // Get the selected shapes const shapes = context.presentation.getSelectedShapes(); - // Implementation will go here + shapes.load("items"); + await context.sync(); + + // Check if shapes are selected + if (shapes.items.length === 0) { + setStatusMessage("No shapes are selected. Please select shapes first."); + setStatusType("warning"); + return; + } + + // Loop through all select shapes and align them + for (let i = 0; i < shapes.items.length; i++) { + shapes.items[i].top = 136.75; + } + await context.sync(); + setStatusMessage("Objects aligned to top."); setStatusType("success"); }); @@ -116,8 +180,24 @@ export const AlignmentButtons: React.FC = () => { setIsProcessing(true); try { await PowerPoint.run(async (context) => { + // Get the selected shapes const shapes = context.presentation.getSelectedShapes(); - // Implementation will go here + shapes.load("items"); + await context.sync(); + + // Check if shapes are selected + if (shapes.items.length === 0) { + setStatusMessage("No shapes are selected. Please select shapes first."); + setStatusType("warning"); + return; + } + + // Loop through all select shapes and align them + for (let i = 0; i < shapes.items.length; i++) { + shapes.items[i].top = 321 - (shapes.items[i].height / 2); + } + await context.sync(); + setStatusMessage("Objects aligned to middle."); setStatusType("success"); }); @@ -134,8 +214,24 @@ export const AlignmentButtons: React.FC = () => { setIsProcessing(true); try { await PowerPoint.run(async (context) => { + // Get the selected shapes const shapes = context.presentation.getSelectedShapes(); - // Implementation will go here + shapes.load("items"); + await context.sync(); + + // Check if shapes are selected + if (shapes.items.length === 0) { + setStatusMessage("No shapes are selected. Please select shapes first."); + setStatusType("warning"); + return; + } + + // Loop through all select shapes and align them + for (let i = 0; i < shapes.items.length; i++) { + shapes.items[i].top = 505.25 - shapes.items[i].height; + } + await context.sync(); + setStatusMessage("Objects aligned to bottom."); setStatusType("success"); });