From c1e8bb5288f83f8c33b0548f457ad26f3677e754 Mon Sep 17 00:00:00 2001 From: Frank Noirot Date: Fri, 17 May 2024 16:40:20 -0400 Subject: [PATCH] Add "copy to clipboard" button to Variables pane (#2388) --- .../ModelingPanes/MemoryPane.tsx | 37 +++++++++++++++++++ .../ModelingSidebar/ModelingPanes/index.ts | 3 +- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/components/ModelingSidebar/ModelingPanes/MemoryPane.tsx b/src/components/ModelingSidebar/ModelingPanes/MemoryPane.tsx index 0cc33d6f9..2efe7e9fb 100644 --- a/src/components/ModelingSidebar/ModelingPanes/MemoryPane.tsx +++ b/src/components/ModelingSidebar/ModelingPanes/MemoryPane.tsx @@ -3,6 +3,43 @@ import { useMemo } from 'react' import { ProgramMemory, Path, ExtrudeSurface } from 'lang/wasm' import { useKclContext } from 'lang/KclProvider' import { useResolvedTheme } from 'hooks/useResolvedTheme' +import { ActionButton } from 'components/ActionButton' +import toast from 'react-hot-toast' +import Tooltip from 'components/Tooltip' + +export const MemoryPaneMenu = () => { + const { programMemory } = useKclContext() + + function copyProgramMemoryToClipboard() { + if (globalThis && 'navigator' in globalThis) { + try { + navigator.clipboard.writeText(JSON.stringify(programMemory)) + toast.success('Program memory copied to clipboard') + } catch (e) { + toast.error('Failed to copy program memory to clipboard') + } + } + } + + return ( + <> + + + Copy to clipboard + + + + ) +} export const MemoryPane = () => { const theme = useResolvedTheme() diff --git a/src/components/ModelingSidebar/ModelingPanes/index.ts b/src/components/ModelingSidebar/ModelingPanes/index.ts index 2a40fed52..ffb3c9a7e 100644 --- a/src/components/ModelingSidebar/ModelingPanes/index.ts +++ b/src/components/ModelingSidebar/ModelingPanes/index.ts @@ -10,7 +10,7 @@ import { KclEditorMenu } from 'components/ModelingSidebar/ModelingPanes/KclEdito import { CustomIconName } from 'components/CustomIcon' import { KclEditorPane } from 'components/ModelingSidebar/ModelingPanes/KclEditorPane' import { ReactNode } from 'react' -import { MemoryPane } from './MemoryPane' +import { MemoryPane, MemoryPaneMenu } from './MemoryPane' import { KclErrorsPane, LogsPane } from './LoggingPanes' import { DebugPane } from './DebugPane' import { FileTreeInner, FileTreeMenu } from 'components/FileTree' @@ -61,6 +61,7 @@ export const bottomPanes: SidebarPane[] = [ title: 'Variables', icon: faSquareRootVariable, Content: MemoryPane, + Menu: MemoryPaneMenu, keybinding: 'shift + v', }, {