| |
| |
| |
| |
| import { showDialog, createSelectContent, createInputContent, showConfirmDialog } from './dialog'; |
| import { tr, trf } from '../lang/i18n-lite'; |
|
|
| export function showMoveDialog( |
| folders: string[], |
| currentPath: string, |
| onConfirm: (targetPath: string) => void |
| ): void { |
| |
| const sortedFolders = [...folders].sort((a, b) => { |
| |
| if (a === '/' || a === '') { |
| if (b === '/' || b === '') return 0; |
| return -1; |
| } |
| if (b === '/' || b === '') return 1; |
| |
| |
| return a.localeCompare(b, 'zh-CN', { numeric: true, sensitivity: 'base' }); |
| }); |
|
|
| |
| const options = sortedFolders.map(folder => ({ |
| value: folder, |
| text: folder === '' || folder === '/' ? tr('/ (Root)') : folder |
| })); |
|
|
| |
| const lastSelectedPathKey = 'lastMoveTargetPath'; |
| const lastSelectedPath = localStorage.getItem(lastSelectedPathKey); |
| |
| |
| let defaultPath = '/'; |
| if (lastSelectedPath && sortedFolders.includes(lastSelectedPath)) { |
| defaultPath = lastSelectedPath; |
| } else if (currentPath && sortedFolders.includes(currentPath)) { |
| defaultPath = currentPath; |
| } else if (sortedFolders.length > 0) { |
| defaultPath = sortedFolders[0]; |
| } |
|
|
| showDialog({ |
| title: tr('Move to...'), |
| content: createSelectContent(tr('Target folder:'), options, defaultPath), |
| onConfirm: (targetPath: string) => { |
| |
| localStorage.setItem(lastSelectedPathKey, targetPath); |
| onConfirm(targetPath); |
| }, |
| cancelText: tr('Cancel') |
| }); |
| } |
|
|
| export function showRenameDialog( |
| currentName: string, |
| onConfirm: (newName: string) => void |
| ): void { |
| showDialog({ |
| title: tr('Rename'), |
| content: createInputContent(tr('New name:'), currentName), |
| onConfirm: (newName: string) => { |
| if (newName) { |
| onConfirm(newName); |
| } |
| }, |
| cancelText: tr('Cancel') |
| }); |
| } |
|
|
| export function showDeleteConfirm( |
| itemName: string, |
| itemType: 'file' | 'folder', |
| onConfirm: () => void |
| ): void { |
| const itemTypeText = itemType === 'folder' ? tr('Folder') : tr('File'); |
| showConfirmDialog( |
| tr('Confirm deletion'), |
| `${trf('Are you sure you want to delete {type} "{name}"?', { type: itemTypeText, name: itemName })}\n\n${tr('This action cannot be undone.')}`, |
| onConfirm, |
| undefined, |
| tr('Delete'), |
| tr('Cancel') |
| ); |
| } |
|
|
| export function showCreateFolderDialog( |
| onConfirm: (folderName: string) => void |
| ): void { |
| showDialog({ |
| title: tr('New folder'), |
| content: createInputContent(tr('Folder name:'), '', tr('Enter folder name')), |
| onConfirm: (folderName: string) => { |
| if (folderName) { |
| onConfirm(folderName); |
| } |
| }, |
| cancelText: tr('Cancel') |
| }); |
| } |
|
|
|
|