diff --git a/src/renderer/components/DirectoryDialog.vue b/src/renderer/components/DirectoryDialog.vue new file mode 100644 index 0000000..4940a5a --- /dev/null +++ b/src/renderer/components/DirectoryDialog.vue @@ -0,0 +1,124 @@ + + + \ No newline at end of file diff --git a/src/renderer/screens/CreateTemplateScreen.vue b/src/renderer/screens/CreateTemplateScreen.vue index 733c593..b55984a 100644 --- a/src/renderer/screens/CreateTemplateScreen.vue +++ b/src/renderer/screens/CreateTemplateScreen.vue @@ -151,42 +151,14 @@ - - + - - - {{ currentEditingItem ? '编辑目录' : '添加目录' }} - - - - - - - - - 取消 - - {{ currentEditingItem ? '保存' : '添加' }} - - - - + :is-edit-mode="!!currentEditingItem" + :parent-directory="parentDirectoryForNewItems" + :editing-item="currentEditingItem" + @confirm="handleDirectoryDialogConfirm" + /> (null) const fileInputRef = ref(null) +// Directory dialog state +const showDirectoryDialog = ref(false) +const directoryFormValid = ref(false) +const parentDirectoryForNewItems = ref(null) +const currentEditingItem = ref(null) + // New item state -const newDirectoryPath = ref('') const newFilePath = ref('') -const parentDirectoryForNewItems = ref(null) // Track parent context const selectedSourcePath = ref('') // Track the selected source file or folder // Tree state @@ -390,9 +364,9 @@ const updateTreeHeight = () => { } const addRootDirectory = () => { - newDirectoryPath.value = '' + parentDirectoryForNewItems.value = null + currentEditingItem.value = null showDirectoryDialog.value = true - autoFocusDirectoryInput() } const addRootFile = () => { @@ -413,23 +387,12 @@ const addFileToDirectory = (directoryItem: TreeItem) => { const addNewItemToCurrentDirectory = (directoryItem: TreeItem) => { parentDirectoryForNewItems.value = directoryItem.name // Store parent context - newDirectoryPath.value = '' // Don't pre-fill the path + currentEditingItem.value = null showDirectoryDialog.value = true - autoFocusDirectoryInput() } -const confirmAddDirectory = () => { - if (!newDirectoryPath.value.trim()) return - - // Construct the full path if there's a parent directory - let fullPath = newDirectoryPath.value - if (parentDirectoryForNewItems.value) { - // Make sure parent directory ends with a slash before appending - const parentPath = parentDirectoryForNewItems.value.endsWith('/') - ? parentDirectoryForNewItems.value - : parentDirectoryForNewItems.value + '/' - fullPath = parentPath + newDirectoryPath.value - } +const handleDirectoryDialogConfirm = (data: { path: string; fullPath: string }) => { + const { path, fullPath } = data // Check for duplicate names in the same parent directory if (parentDirectoryForNewItems.value) { @@ -440,7 +403,7 @@ const confirmAddDirectory = () => { ) if (parentNode && parentNode.children) { const duplicateExists = parentNode.children.some( - (child) => child.name === newDirectoryPath.value + (child) => child.name === path ) if (duplicateExists) { snackbar.error('当前目录下已存在同名节点!') @@ -450,7 +413,7 @@ const confirmAddDirectory = () => { } else { // Check at root level for duplicates const duplicateExists = treeStructure.value.some( - (node) => node.name === newDirectoryPath.value + (node) => node.name === path ) if (duplicateExists) { snackbar.error('根目录下已存在同名节点!') @@ -468,7 +431,7 @@ const confirmAddDirectory = () => { // Find and update the existing directory in the tree const updatedNode: TreeNode = { id: currentEditingItem.value.id, - name: newDirectoryPath.value, + name: path, path: fullPath, type: 'directory' } @@ -481,7 +444,7 @@ const confirmAddDirectory = () => { // Create new directory node const newNode: TreeNode = { id: newId, - name: newDirectoryPath.value, + name: path, path: fullPath, type: 'directory' } @@ -508,8 +471,6 @@ const confirmAddDirectory = () => { nextTick(() => { expandAll() }) - - newDirectoryPath.value = '' } // 在树状结构中更新节点的辅助函数 @@ -560,13 +521,7 @@ const addChildToNode = ( }) } -// Functions to close dialogs and reset state -const closeDirectoryDialog = () => { - showDirectoryDialog.value = false - newDirectoryPath.value = '' - parentDirectoryForNewItems.value = null - currentEditingItem.value = null -} + const closeFileDialog = () => { showFileDialog.value = false @@ -846,9 +801,8 @@ const findNodeInTreeByName = ( const showEditDirectoryDialog = (directory: TreeNode) => { // Set up for editing an existing directory currentEditingItem.value = directory - newDirectoryPath.value = directory.path // Set the current path for editing + parentDirectoryForNewItems.value = null showDirectoryDialog.value = true - autoFocusDirectoryInput() } // Show dialog to edit file @@ -866,8 +820,7 @@ const showEditFileDialog = (file: TreeNode) => { autoFocusFileInput() } -// Variable to track the current item being edited -const currentEditingItem = ref(null) + const deleteItem = async (item: TreeItem) => { const confirmed = await ConfirmDialogService.confirm({ @@ -911,13 +864,7 @@ const selectSourceFileOrFolder = async () => { } } -// Auto focus methods -const autoFocusDirectoryInput = async () => { - await nextTick() - if (directoryInputRef.value) { - ;(directoryInputRef.value as HTMLInputElement).focus() - } -} + const autoFocusFileInput = async () => { await nextTick()