Skip to content

Commit

Permalink
fix: file imports being broken
Browse files Browse the repository at this point in the history
  • Loading branch information
solvedDev committed May 28, 2022
1 parent cb19d5e commit 2536278
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
17 changes: 8 additions & 9 deletions src/components/ImportFile/BasicFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { InformedChoiceWindow } from '/@/components/Windows/InformedChoice/Infor
import { FilePathWindow } from '/@/components/Windows/Common/FilePath/Window'
import { ConfirmationWindow } from '/@/components/Windows/Common/Confirm/ConfirmWindow'
import { AnyFileHandle } from '../FileSystem/Types'
import { join } from '/@/utils/path'

export class BasicFileImporter extends FileImporter {
constructor(fileDropper: FileDropper) {
Expand Down Expand Up @@ -67,19 +68,20 @@ export class BasicFileImporter extends FileImporter {
// Allow user to change file path that the file is saved to
const filePathWindow = new FilePathWindow({
fileName: fileHandle.name,
startPath: (await App.fileType.guessFolder(fileHandle)) ?? '',
startPath: app.project.relativePath(
(await App.fileType.guessFolder(fileHandle)) ?? ''
),
isPersistent: false,
})
filePathWindow.open()

const userInput = await filePathWindow.fired
if (userInput === null) return
const { filePath, fileName = fileHandle.name } = userInput
const newFilePath = join(filePath, fileName)

// Get user confirmation if file overwrites already existing file
const fileExists = await app.project.fileSystem.fileExists(
`${filePath}${fileName}`
)
const fileExists = await app.project.fileSystem.fileExists(newFilePath)
if (fileExists) {
const confirmWindow = new ConfirmationWindow({
description: 'windows.createPreset.overwriteFiles',
Expand All @@ -93,18 +95,15 @@ export class BasicFileImporter extends FileImporter {
app.windows.loadingWindow.open()

const destHandle = await app.project.fileSystem.getFileHandle(
`${filePath}${fileName}`,
newFilePath,
true
)

await app.project.fileSystem.copyFileHandle(fileHandle, destHandle)
App.eventSystem.dispatch('fileAdded', undefined)

await app.project.updateFile(
app.project.config.resolvePackPath(
undefined,
`${filePath}${fileName}`
)
app.project.config.resolvePackPath(undefined, newFilePath)
)
await app.project.openFile(destHandle, { isTemporary: false })

Expand Down
7 changes: 6 additions & 1 deletion src/components/Windows/Common/FilePath/Window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ export class FilePathWindow extends BaseWindow<IChangedFileData | null> {
return this.close(
skippedDialog
? null
: { filePath: this.currentFilePath, fileName: this.hasFilePath ? `${this.fileName}${this.fileExt}` : undefined }
: {
filePath: this.currentFilePath,
fileName: this.hasFilePath
? `${this.fileName}${this.fileExt}`
: undefined,
}
)
}
}
2 changes: 1 addition & 1 deletion src/components/Windows/Project/CreatePreset/PresetPath.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default {
},
computed: {
path() {
return this.value.substring(0, this.value.length - 1)
return this.editedPath.substring(0, this.editedPath.length - 1)
},
},
methods: {
Expand Down

0 comments on commit 2536278

Please sign in to comment.