diff --git a/src/components/GitPanelEnhanced.tsx b/src/components/GitPanelEnhanced.tsx index 9b29dcc..c686492 100644 --- a/src/components/GitPanelEnhanced.tsx +++ b/src/components/GitPanelEnhanced.tsx @@ -39,6 +39,8 @@ import { TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip"; +import { useTranslation } from "@/hooks/useTranslation"; + interface GitFileStatus { path: string; @@ -140,19 +142,21 @@ export const GitPanelEnhanced: React.FC = ({ const [isResizing, setIsResizing] = useState(false); const [expandedNodes, setExpandedNodes] = useState>(new Set()); const [selectedPath, setSelectedPath] = useState(null); - + const panelRef = useRef(null); const resizeHandleRef = useRef(null); + const { t } = useTranslation(); + const refreshIntervalRef = useRef(null); // 处理拖拽调整宽度 useEffect(() => { const handleMouseMove = (e: MouseEvent) => { if (!isResizing) return; - + const windowWidth = window.innerWidth; const newWidth = windowWidth - e.clientX; - + if (newWidth >= 200 && newWidth <= 600) { setWidth(newWidth); } @@ -184,11 +188,11 @@ export const GitPanelEnhanced: React.FC = ({ try { setLoading(true); setError(null); - + const status = await invoke("get_git_status", { path: projectPath, // 修改参数名为 path }); - + setGitStatus(status); } catch (err) { console.error("Failed to load git status:", err); @@ -207,7 +211,7 @@ export const GitPanelEnhanced: React.FC = ({ projectPath: projectPath, // 使用驼峰命名 limit: 20, }); - + setCommits(commitList); } catch (err) { console.error("Failed to load commits:", err); @@ -300,11 +304,11 @@ export const GitPanelEnhanced: React.FC = ({ if (!currentNode.children) { currentNode.children = []; } - + let dirNode = currentNode.children.find( child => child.type === 'directory' && child.name === part ); - + if (!dirNode) { dirNode = { name: part, @@ -314,7 +318,7 @@ export const GitPanelEnhanced: React.FC = ({ }; currentNode.children.push(dirNode); } - + currentNode = dirNode; } } @@ -327,7 +331,7 @@ export const GitPanelEnhanced: React.FC = ({ if (a.type === 'file' && b.type === 'directory') return 1; return a.name.localeCompare(b.name); }); - + nodes.forEach(node => { if (node.children) { sortNodes(node.children); @@ -345,7 +349,7 @@ export const GitPanelEnhanced: React.FC = ({ // 展开所有节点(从指定节点开始) const expandAll = useCallback((startPath?: string) => { const nodesToExpand = new Set(); - + const collectNodes = (nodes: FileTreeNode[], parentPath: string = '') => { nodes.forEach(node => { if (node.type === 'directory') { @@ -357,7 +361,7 @@ export const GitPanelEnhanced: React.FC = ({ } }); }; - + if (startPath) { // 找到指定节点并展开其子节点 const findAndExpand = (nodes: FileTreeNode[]): boolean => { @@ -375,7 +379,7 @@ export const GitPanelEnhanced: React.FC = ({ } return false; }; - + // 先构建完整的树 const allTrees = []; if (gitStatus) { @@ -384,7 +388,7 @@ export const GitPanelEnhanced: React.FC = ({ if (gitStatus.untracked.length > 0) allTrees.push(...buildFileTree(gitStatus.untracked)); if (gitStatus.conflicted.length > 0) allTrees.push(...buildFileTree(gitStatus.conflicted)); } - + findAndExpand(allTrees); } else { // 展开所有节点 @@ -397,7 +401,7 @@ export const GitPanelEnhanced: React.FC = ({ collectNodes(allTrees); } } - + setExpandedNodes(nodesToExpand); }, [gitStatus]); @@ -405,7 +409,7 @@ export const GitPanelEnhanced: React.FC = ({ const collapseAll = useCallback((startPath?: string) => { if (startPath) { const nodesToRemove = new Set(); - + const collectNodes = (nodes: FileTreeNode[]): boolean => { for (const node of nodes) { if (node.path === startPath && node.type === 'directory') { @@ -426,7 +430,7 @@ export const GitPanelEnhanced: React.FC = ({ } return false; }; - + // 构建完整的树 const allTrees = []; if (gitStatus) { @@ -435,9 +439,9 @@ export const GitPanelEnhanced: React.FC = ({ if (gitStatus.untracked.length > 0) allTrees.push(...buildFileTree(gitStatus.untracked)); if (gitStatus.conflicted.length > 0) allTrees.push(...buildFileTree(gitStatus.conflicted)); } - + collectNodes(allTrees); - + setExpandedNodes(prev => { const next = new Set(prev); nodesToRemove.forEach(path => next.delete(path)); @@ -485,7 +489,7 @@ export const GitPanelEnhanced: React.FC = ({ {isDirectory && !hasChildren && (
// 空文件夹的占位符 )} - + {isDirectory ? ( isExpanded ? ( @@ -498,7 +502,7 @@ export const GitPanelEnhanced: React.FC = ({ )} - + @@ -535,16 +539,16 @@ export const GitPanelEnhanced: React.FC = ({
{getFileStatusIcon(statusType)} - {statusType === 'modified' && '已修改'} - {statusType === 'staged' && '已暂存'} - {statusType === 'untracked' && '未跟踪'} - {statusType === 'conflicted' && '冲突'} + {statusType === 'modified' && t('app.modified')} + {statusType === 'staged' && t('app.staged')} + {statusType === 'untracked' && t('app.untracked')} + {statusType === 'conflicted' && t('app.conflicted')} {files.length}
- +
{fileTree.map((node) => renderFileTreeNode(node, 0, statusType))}
@@ -558,7 +562,7 @@ export const GitPanelEnhanced: React.FC = ({ return (
-

暂无提交记录

+

{t('app.noCommitsFound')}

); } @@ -588,7 +592,7 @@ export const GitPanelEnhanced: React.FC = ({ {commit.files_changed > 0 && ( - {commit.files_changed} files + {commit.files_changed} {t('app.filesChanged')} )}
@@ -640,7 +644,7 @@ export const GitPanelEnhanced: React.FC = ({
-

Git

+

{t('app.gitPanel')}

{gitStatus && ( {gitStatus.branch} @@ -662,11 +666,11 @@ export const GitPanelEnhanced: React.FC = ({ -

{selectedPath ? '展开当前文件夹' : '展开所有文件夹'}

+

{selectedPath ? t('app.expandCurrentFolder') : t('app.expandAllFolders')}

- + @@ -680,14 +684,14 @@ export const GitPanelEnhanced: React.FC = ({ -

{selectedPath ? '收起当前文件夹' : '收起所有文件夹'}

+

{selectedPath ? t('app.collapseCurrentFolder') : t('app.collapseAllFolders')}

- + {changeStats && changeStats.total > 0 && ( - {changeStats.total} 变更 + {changeStats.total} {t('app.gitChanges')} )}
@@ -739,7 +743,7 @@ export const GitPanelEnhanced: React.FC = ({ - 变更 + {t('app.gitChanges')} {changeStats && changeStats.total > 0 && ( {changeStats.total} @@ -748,7 +752,7 @@ export const GitPanelEnhanced: React.FC = ({ - 历史 + {t('app.gitHistory')} @@ -773,11 +777,11 @@ export const GitPanelEnhanced: React.FC = ({ {renderFileList(gitStatus.modified, 'modified')} {renderFileList(gitStatus.untracked, 'untracked')} {renderFileList(gitStatus.conflicted, 'conflicted')} - + {changeStats?.total === 0 && (
-

工作区干净

+

{t('app.workingTreeClean')}

)} diff --git a/src/locales/en/common.json b/src/locales/en/common.json index 35be688..6cc55fa 100644 --- a/src/locales/en/common.json +++ b/src/locales/en/common.json @@ -73,6 +73,14 @@ "saved": "Saved", "unsavedChangesConfirm": "You have unsaved changes. Are you sure you want to leave?", "gitPanel": "Git", + "gitChanges": "Changes", + "expandCurrentFolder": "Expand current folder", + "expandAllFolders": "Expand all folders", + "collapseCurrentFolder": "Collapse current folder", + "collapseAllFolders": "Collapse all folders", + "ahead": "ahead", + "behind": "behind", + "gitStatus": "Status", "gitHistory": "History", "gitBranches": "Branches", diff --git a/src/locales/zh/common.json b/src/locales/zh/common.json index a9308a5..eb243e3 100644 --- a/src/locales/zh/common.json +++ b/src/locales/zh/common.json @@ -73,6 +73,14 @@ "gitStatus": "状态", "gitHistory": "历史", "gitBranches": "分支", + "gitChanges": "变更", + "expandCurrentFolder": "展开当前文件夹", + "expandAllFolders": "展开所有文件夹", + "collapseCurrentFolder": "收起当前文件夹", + "collapseAllFolders": "收起所有文件夹", + "ahead": "领先", + "behind": "落后", + "workingTreeClean": "工作区清洁", "staged": "已暂存", "modified": "已修改",