From bcebd5ae00a7c41bf1c80bdeef562849ebe892a2 Mon Sep 17 00:00:00 2001 From: ochafik Date: Sun, 26 Mar 2023 22:33:14 +0100 Subject: [PATCH] Run openscad from /home (w/ symlinks to libs) and force user files to relative --- src/components/EditorPanel.tsx | 48 ++----------------------- src/components/FilePicker.tsx | 24 ++----------- src/components/Footer.tsx | 60 +++++++++++++------------------- src/components/PanelSwitcher.tsx | 8 +++-- src/fs/filesystem.ts | 7 ++-- src/runner/actions.ts | 12 +++---- src/runner/openscad-worker.ts | 4 +-- src/runner/output-parser.ts | 15 ++++++-- src/state/initial-state.ts | 2 +- src/state/model.ts | 10 +++++- 10 files changed, 68 insertions(+), 122 deletions(-) diff --git a/src/components/EditorPanel.tsx b/src/components/EditorPanel.tsx index 2fc8daa..8a85e76 100644 --- a/src/components/EditorPanel.tsx +++ b/src/components/EditorPanel.tsx @@ -6,14 +6,12 @@ import openscadEditorOptions from '../language/openscad-editor-options'; import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'; import { Button } from 'primereact/button'; import { MenuItem } from 'primereact/menuitem'; -import { TreeSelect } from 'primereact/treeselect'; -import TreeNode from 'primereact/treenode'; import { Menu } from 'primereact/menu'; -import { getParentDir, librariesFolder } from '../fs/filesystem'; import { buildUrlForStateParams } from '../state/fragment-state'; import { blankProjectState } from '../state/initial-state'; import { ModelContext, FSContext } from './contexts'; -import FilePicker, { isFileWritable } from './FilePicker'; +import FilePicker, { } from './FilePicker'; +import { isFileWritable } from '../state/model'; // import "primereact/resources/themes/lara-light-indigo/theme.css"; // import "primereact/resources/primereact.min.css"; @@ -22,46 +20,6 @@ import FilePicker, { isFileWritable } from './FilePicker'; let monacoInstance: Monaco loader.init().then(mi => monacoInstance = mi); -// const isFileWritable = (path: string) => getParentDir(path) === '/home' - -// function listFilesAsNodes(fs: FS, path: string): TreeNode[] { -// const files: [string, string][] = [] -// const dirs: [string, string][] = [] -// for (const name of fs.readdirSync(path)) { -// if (name.startsWith('.')) { -// continue; -// } -// const childPath = `${path}/${name}`; -// const stat = fs.lstatSync(childPath); -// const isDirectory = stat.isDirectory(); -// if (!isDirectory && !name.endsWith('.scad')) { -// continue; -// } -// (isDirectory ? dirs : files).push([name, childPath]); -// } -// [files, dirs].forEach(arr => arr.sort(([a], [b]) => a.localeCompare(b))); - -// const nodes: TreeNode[] = [] -// for (const [arr, isDirectory] of [[files, false], [dirs, true]] as [[string, string][], boolean][]) { -// for (const [name, path] of arr) { -// const children = isDirectory ? listFilesAsNodes(fs, path) : undefined; -// if (isDirectory && children!.length == 0) { -// continue; -// } -// nodes.push({ -// // icon: path == '/home' ? 'pi-home' : ... -// icon: isDirectory ? 'pi pi-folder' : isFileWritable(path) ? 'pi pi-file' : 'pi pi-lock', -// label: name, -// data: path, -// key: path, -// children, -// selectable: !isDirectory // && (name == 'LICENSE' || name.endsWith('.scad') || name.endsWith('.scad') -// }); -// } -// } -// return nodes; -// } - export default function EditorPanel({className, style}: {className?: string, style?: CSSProperties}) { const model = useContext(ModelContext); @@ -71,9 +29,7 @@ export default function EditorPanel({className, style}: {className?: string, sty const state = model.state; - // const fs = useContext(FSContext); const [editor, setEditor] = useState(null as monaco.editor.IStandaloneCodeEditor | null) - // const [modelFile, setModelFile] = useState(state.params.sourcePath); if (editor) { const checkerRun = state.lastCheckerRun; diff --git a/src/components/FilePicker.tsx b/src/components/FilePicker.tsx index 25521cc..6fd99bd 100644 --- a/src/components/FilePicker.tsx +++ b/src/components/FilePicker.tsx @@ -3,12 +3,8 @@ import { CSSProperties, useContext } from 'react'; import { TreeSelect } from 'primereact/treeselect'; import TreeNode from 'primereact/treenode'; -import { getParentDir, librariesFolder } from '../fs/filesystem'; import { ModelContext, FSContext } from './contexts'; - -export const isFileWritable = (path: string) => getParentDir(path) === '/home' - -// export const isFileWritable = (path: string) => !path.startsWith(librariesFolder + '/'); +import { isFileWritable } from '../state/model'; function listFilesAsNodes(fs: FS, path: string, accept?: (path: string) => boolean): TreeNode[] { const files: [string, string][] = [] @@ -58,23 +54,7 @@ export default function FilePicker({className, style}: {className?: string, styl const fs = useContext(FSContext); - const fsItems = fs && [ - { - icon: 'pi pi-home', - label: 'User files', - key: '/home', - children: listFilesAsNodes(fs, '/home'),// - // children: listFilesAsNodes(fs, '/', f => f != librariesFolder && !f.startsWith(`${librariesFolder}/`)), - selectable: false - }, - { - icon: 'pi pi-database', - label: 'Builtin libraries', - key: librariesFolder, - children: listFilesAsNodes(fs, librariesFolder), - selectable: false - }, - ] || []; + const fsItems = fs && listFilesAsNodes(fs, '/home') return ( - {/* {state.error != null && - } */} + {(state.lastCheckerRun || state.output) && + } - + {state.output && ( +