diff --git a/frontend/src/components/layout/Workbench.tsx b/frontend/src/components/layout/Workbench.tsx index fc41d2480..0e93313fc 100644 --- a/frontend/src/components/layout/Workbench.tsx +++ b/frontend/src/components/layout/Workbench.tsx @@ -111,11 +111,14 @@ export default function Workbench() { onRotate={pageEditorFunctions.handleRotate} onDelete={pageEditorFunctions.handleDelete} onSplit={pageEditorFunctions.handleSplit} + onSplitAll={pageEditorFunctions.handleSplitAll} onExportSelected={pageEditorFunctions.onExportSelected} onExportAll={pageEditorFunctions.onExportAll} exportLoading={pageEditorFunctions.exportLoading} selectionMode={pageEditorFunctions.selectionMode} selectedPages={pageEditorFunctions.selectedPages} + splitPositions={pageEditorFunctions.splitPositions} + totalPages={pageEditorFunctions.totalPages} /> )} diff --git a/frontend/src/components/pageEditor/PageEditor.tsx b/frontend/src/components/pageEditor/PageEditor.tsx index abb578458..072c1097c 100644 --- a/frontend/src/components/pageEditor/PageEditor.tsx +++ b/frontend/src/components/pageEditor/PageEditor.tsx @@ -127,6 +127,7 @@ export interface PageEditorProps { handleRotate: (direction: 'left' | 'right') => void; handleDelete: () => void; handleSplit: () => void; + handleSplitAll: () => void; showExportPreview: (selectedOnly: boolean) => void; onExportSelected: () => void; onExportAll: () => void; @@ -134,6 +135,8 @@ export interface PageEditorProps { exportLoading: boolean; selectionMode: boolean; selectedPages: number[]; + splitPositions: Set; + totalPages: number; closePdf: () => void; }) => void; } @@ -523,6 +526,28 @@ const PageEditor = ({ }); }, [selectedPageNumbers, displayDocument]); + const handleSplitAll = useCallback(() => { + if (!displayDocument) return; + + // Check if all possible split positions are already set + const allPossibleSplits = new Set(); + for (let i = 0; i < displayDocument.pages.length - 1; i++) { + allPossibleSplits.add(i); + } + + const hasAllSplits = Array.from(allPossibleSplits).every(pos => splitPositions.has(pos)); + + if (hasAllSplits) { + // Remove all splits + console.log('Removing all split markers'); + setSplitPositions(new Set()); + } else { + // Add split marker after every page except the last one + console.log('Adding split markers after every page'); + setSplitPositions(allPossibleSplits); + } + }, [displayDocument, splitPositions]); + const handleReorderPages = useCallback((sourcePageNumber: number, targetIndex: number, selectedPages?: number[]) => { if (!displayDocument) return; @@ -729,6 +754,7 @@ const PageEditor = ({ handleRotate, handleDelete, handleSplit, + handleSplitAll, showExportPreview: handleExportPreview, onExportSelected, onExportAll, @@ -736,12 +762,15 @@ const PageEditor = ({ exportLoading, selectionMode, selectedPages: selectedPageNumbers, + splitPositions, + totalPages: displayDocument?.pages.length || 0, closePdf, }); } }, [ - onFunctionsReady, handleUndo, handleRedo, handleRotate, handleDelete, handleSplit, - handleExportPreview, onExportSelected, onExportAll, applyChanges, exportLoading, selectionMode, selectedPageNumbers, closePdf + onFunctionsReady, handleUndo, handleRedo, handleRotate, handleDelete, handleSplit, handleSplitAll, + handleExportPreview, onExportSelected, onExportAll, applyChanges, exportLoading, selectionMode, selectedPageNumbers, + splitPositions, displayDocument?.pages.length, closePdf ]); // Display all pages - use edited or original document diff --git a/frontend/src/components/pageEditor/PageEditorControls.tsx b/frontend/src/components/pageEditor/PageEditorControls.tsx index 43e224e2b..2c48f2034 100644 --- a/frontend/src/components/pageEditor/PageEditorControls.tsx +++ b/frontend/src/components/pageEditor/PageEditorControls.tsx @@ -27,6 +27,7 @@ interface PageEditorControlsProps { onRotate: (direction: 'left' | 'right') => void; onDelete: () => void; onSplit: () => void; + onSplitAll: () => void; // Export functions onExportSelected: () => void; @@ -36,6 +37,10 @@ interface PageEditorControlsProps { // Selection state selectionMode: boolean; selectedPages: number[]; + + // Split state (for tooltip logic) + splitPositions?: Set; + totalPages?: number; } const PageEditorControls = ({ @@ -47,12 +52,33 @@ const PageEditorControls = ({ onRotate, onDelete, onSplit, + onSplitAll, onExportSelected, onExportAll, exportLoading, selectionMode, - selectedPages + selectedPages, + splitPositions, + totalPages }: PageEditorControlsProps) => { + // Calculate split all tooltip text + const getSplitAllTooltip = () => { + if (selectionMode) { + return "Split Selected"; + } + + if (!splitPositions || !totalPages) { + return "Split All"; + } + + // Check if all possible splits are active + const allPossibleSplitsCount = totalPages - 1; + const hasAllSplits = splitPositions.size === allPossibleSplitsCount && + Array.from({length: allPossibleSplitsCount}, (_, i) => i).every(pos => splitPositions.has(pos)); + + return hasAllSplits ? "Remove All Splits" : "Split All"; + }; + return (
- + 0 ? "light" : "default"} color={selectionMode && selectedPages.length > 0 ? "blue" : undefined}