import * as vscode from 'vscode' ; import JSCADEditorController from './JSCADEditorController' ; import JSCADPreviewPanel from './JSCADPreviewPanel' ; import JSCADExporter from './JSCADExporter' ; import JSCADIntellisenseProvider from './JSCADIntellisenseProvider' ; import ImportPathFromSVGAction from './actions/ImportPathFromSVGAction' ; export function activate ( context ) { console . log ( 'vscode-jscad-editor active' ) ; const controller = new JSCADEditorController ( ) ; context . subscriptions . push ( controller ) ; const exporter = new JSCADExporter ( context . extensionPath ) ; new JSCADIntellisenseProvider ( ) ; context . subscriptions . push ( vscode . commands . registerCommand ( 'jscadEditor.openPreview' , ( ) => { console . log ( 'jscadEditor.openPreview: command runs' ) ; JSCADPreviewPanel . createOrShow ( context . extensionPath ) ; } ) ) ; context . subscriptions . push ( vscode . commands . registerCommand ( 'jscadEditor.exportAsSTL' , async ( ) => { const editor = vscode . window . activeTextEditor ; if ( editor && editor . document . fileName . match ( /\.jscad$/i ) ) { const result = await exporter . command ( `npx openjscad "${ editor . document . fileName }"` ) ; if ( result ) { vscode . window . showInformationMessage ( 'JSCAD: STL export succeeded' ) ; } else { vscode . window . showErrorMessage ( 'JSCAD: STL export failed (check task output for details)' ) ; } } } ) ) ; context . subscriptions . push ( vscode . commands . registerCommand ( 'jscadEditor.importPathFromSVG' , async ( ) => { const editor = vscode . window . activeTextEditor ; if ( editor && editor . document . fileName . match ( /\.jscad$/i ) ) { const selectedFiles = await vscode . window . showOpenDialog ( { filters : { 'SVG files' : [ 'svg' ] } , } ) ; if ( selectedFiles && selectedFiles . length > 0 ) { const importer = new ImportPathFromSVGAction ( selectedFiles [ 0 ] . fsPath ) ; const polygonElements = importer . getPolygonsFromSVG ( ) ; if ( ! polygonElements ) { vscode . window . showErrorMessage ( 'No <polygon> element found in provided SVG document' ) ; return ; } const svgString = importer . convertSVGPolygonToJSCADString ( polygonElements ) ; if ( ! svgString ) { vscode . window . showErrorMessage ( 'Failed to comvert <polygon> element to JSCAD. See error output for details.' ) ; return ; } editor . insertSnippet ( new vscode . SnippetString ( svgString ) ) ; } } } ) ) ; if ( vscode . window . registerWebviewPanelSerializer ) { vscode . window . registerWebviewPanelSerializer ( JSCADPreviewPanel . viewType , { async deserializeWebviewPanel ( webviewPanel , state ) { console . log ( `JSCADPreview activate: restore state ${ state }` ) ; const panel = JSCADPreviewPanel . revive ( webviewPanel , context . extensionPath , state ) ; panel . onDidInitialize ( e => { console . log ( 'INIT DONE' ) ; vscode . window . showInformationMessage ( 'JSCAD Viewer initialized!' ) ; controller . updatePanelWithEditorData ( ) ; } ) ; } } ) ; } } export function deactivate ( ) { }