Add 'Clone' feature to file tree (#5232)
* Add 'Clone' file / folder feature to file tree * E2E Test: clone file in file tree * Don't stat if there's no target
This commit is contained in:
@ -124,22 +124,43 @@ export const FileMachineProvider = ({
|
||||
let createdName = input.name.trim() || DEFAULT_FILE_NAME
|
||||
let createdPath: string
|
||||
|
||||
if (input.makeDir) {
|
||||
if (
|
||||
(input.targetPathToClone &&
|
||||
(await window.electron.statIsDirectory(
|
||||
input.targetPathToClone
|
||||
))) ||
|
||||
input.makeDir
|
||||
) {
|
||||
let { name, path } = getNextDirName({
|
||||
entryName: createdName,
|
||||
baseDir: input.selectedDirectory.path,
|
||||
entryName: input.targetPathToClone
|
||||
? window.electron.path.basename(input.targetPathToClone)
|
||||
: createdName,
|
||||
baseDir: input.targetPathToClone
|
||||
? window.electron.path.dirname(input.targetPathToClone)
|
||||
: input.selectedDirectory.path,
|
||||
})
|
||||
createdName = name
|
||||
createdPath = path
|
||||
await window.electron.mkdir(createdPath)
|
||||
} else {
|
||||
const { name, path } = getNextFileName({
|
||||
entryName: createdName,
|
||||
baseDir: input.selectedDirectory.path,
|
||||
entryName: input.targetPathToClone
|
||||
? window.electron.path.basename(input.targetPathToClone)
|
||||
: createdName,
|
||||
baseDir: input.targetPathToClone
|
||||
? window.electron.path.dirname(input.targetPathToClone)
|
||||
: input.selectedDirectory.path,
|
||||
})
|
||||
createdName = name
|
||||
createdPath = path
|
||||
await window.electron.writeFile(createdPath, input.content ?? '')
|
||||
if (input.targetPathToClone) {
|
||||
await window.electron.copyFile(
|
||||
input.targetPathToClone,
|
||||
createdPath
|
||||
)
|
||||
} else {
|
||||
await window.electron.writeFile(createdPath, input.content ?? '')
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
Reference in New Issue
Block a user