(value: string)
| 526 | }; |
| 527 | |
| 528 | const handlePromptConfirm = async (value: string) => { |
| 529 | if (!promptDialog) return; |
| 530 | |
| 531 | const { type, parentPath, templateExtension, templateGetContent } = promptDialog; |
| 532 | setPromptDialog(null); |
| 533 | |
| 534 | let fileName = value; |
| 535 | let targetPath = `${parentPath}/${value}`; |
| 536 | |
| 537 | try { |
| 538 | if (type === 'create-file') { |
| 539 | await TauriAPI.createFile(targetPath); |
| 540 | } else if (type === 'create-folder') { |
| 541 | await TauriAPI.createDirectory(targetPath); |
| 542 | } else if (type === 'create-template' && templateExtension && templateGetContent) { |
| 543 | if (!fileName.endsWith(`.${templateExtension}`)) { |
| 544 | fileName = `${fileName}.${templateExtension}`; |
| 545 | targetPath = `${parentPath}/${fileName}`; |
| 546 | } |
| 547 | // 获取内容并通过后端 API 写入文件 |
| 548 | const content = await templateGetContent(fileName); |
| 549 | await TauriAPI.writeFileContent(targetPath, content); |
| 550 | } |
| 551 | await refreshTree(); |
| 552 | } catch (error) { |
| 553 | console.error(`Failed to ${type}:`, error); |
| 554 | const errorKey = type === 'create-file' ? 'fileTree.createFileFailed' : |
| 555 | type === 'create-folder' ? 'fileTree.createFolderFailed' : 'fileTree.createTemplateFailed'; |
| 556 | alert(`${t(errorKey)}: ${error}`); |
| 557 | } |
| 558 | }; |
| 559 | |
| 560 | const getContextMenuItems = (node: TreeNode | null): ContextMenuItem[] => { |
| 561 | if (!node) { |
nothing calls this directly
no test coverage detected