Change so that the new file in new projects get the units
This commit is contained in:
@ -402,8 +402,10 @@ const ProjectsContextDesktop = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the project around the file if newProject
|
// Create the project around the file if newProject
|
||||||
|
let fileLoaded = false
|
||||||
if (input.method === 'newProject') {
|
if (input.method === 'newProject') {
|
||||||
await createNewProjectDirectory(projectName, input.code)
|
await createNewProjectDirectory(projectName, input.code)
|
||||||
|
fileLoaded = true
|
||||||
message = `Project "${projectName}" created successfully with link contents`
|
message = `Project "${projectName}" created successfully with link contents`
|
||||||
} else {
|
} else {
|
||||||
message = `File "${fileName}" created successfully`
|
message = `File "${fileName}" created successfully`
|
||||||
@ -420,13 +422,16 @@ const ProjectsContextDesktop = ({
|
|||||||
})
|
})
|
||||||
|
|
||||||
fileName = name
|
fileName = name
|
||||||
const codeToWrite = newKclFile(
|
if (!fileLoaded) {
|
||||||
input.code ?? '',
|
const codeToWrite = newKclFile(
|
||||||
settings.modeling.defaultUnit.current
|
input.code ?? '',
|
||||||
)
|
settings.modeling.defaultUnit.current
|
||||||
if (err(codeToWrite)) return Promise.reject(codeToWrite)
|
)
|
||||||
await window.electron.writeFile(path, codeToWrite)
|
if (err(codeToWrite)) return Promise.reject(codeToWrite)
|
||||||
|
await window.electron.writeFile(path, codeToWrite)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Return the project's file name if one was created.
|
||||||
return {
|
return {
|
||||||
message,
|
message,
|
||||||
fileName,
|
fileName,
|
||||||
|
@ -9,6 +9,7 @@ import {
|
|||||||
parseProjectSettings,
|
parseProjectSettings,
|
||||||
} from 'lang/wasm'
|
} from 'lang/wasm'
|
||||||
import {
|
import {
|
||||||
|
DEFAULT_DEFAULT_LENGTH_UNIT,
|
||||||
PROJECT_ENTRYPOINT,
|
PROJECT_ENTRYPOINT,
|
||||||
PROJECT_FOLDER,
|
PROJECT_FOLDER,
|
||||||
PROJECT_IMAGE_NAME,
|
PROJECT_IMAGE_NAME,
|
||||||
@ -21,6 +22,7 @@ import {
|
|||||||
import { DeepPartial } from './types'
|
import { DeepPartial } from './types'
|
||||||
import { ProjectConfiguration } from '@rust/kcl-lib/bindings/ProjectConfiguration'
|
import { ProjectConfiguration } from '@rust/kcl-lib/bindings/ProjectConfiguration'
|
||||||
import { Configuration } from '@rust/kcl-lib/bindings/Configuration'
|
import { Configuration } from '@rust/kcl-lib/bindings/Configuration'
|
||||||
|
import { newKclFile } from 'lang/project'
|
||||||
|
|
||||||
export async function renameProjectDirectory(
|
export async function renameProjectDirectory(
|
||||||
projectPath: string,
|
projectPath: string,
|
||||||
@ -113,7 +115,18 @@ export async function createNewProjectDirectory(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const projectFile = window.electron.path.join(projectDir, PROJECT_ENTRYPOINT)
|
const projectFile = window.electron.path.join(projectDir, PROJECT_ENTRYPOINT)
|
||||||
await window.electron.writeFile(projectFile, initialCode ?? '')
|
// When initialCode is present, we're loading existing code. If it's not
|
||||||
|
// present, we're creating a new project, and we want to incorporate the
|
||||||
|
// user's settings.
|
||||||
|
const codeToWrite =
|
||||||
|
initialCode ??
|
||||||
|
newKclFile(
|
||||||
|
'',
|
||||||
|
configuration?.settings?.modeling?.base_unit ??
|
||||||
|
DEFAULT_DEFAULT_LENGTH_UNIT
|
||||||
|
)
|
||||||
|
if (err(codeToWrite)) return Promise.reject(codeToWrite)
|
||||||
|
await window.electron.writeFile(projectFile, codeToWrite)
|
||||||
const metadata = await window.electron.stat(projectFile)
|
const metadata = await window.electron.stat(projectFile)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
Reference in New Issue
Block a user