右侧边栏支持快捷操作“提交代码”

This commit is contained in:
xintaofei
2026-03-08 08:42:51 +08:00
parent ab31d3063e
commit 7b65fe8ddc
5 changed files with 80 additions and 0 deletions

View File

@@ -29,6 +29,7 @@ import {
gitStatus,
readFileForEdit,
readFilePreview,
openCommitWindow,
renameFileTreeEntry,
saveFileCopy,
startFileTreeWatch,
@@ -410,6 +411,7 @@ interface RenderNodeProps {
onOpenFilePreview: (path: string) => void
onOpenFileDiff: (path: string) => void
onOpenDirDiff: (path: string) => void
onOpenCommitWindow: () => void
onRequestCompareWithBranch: (target: FileActionTarget) => void
onRequestRollback: (target: FileActionTarget) => void
onOpenDirInTerminal: (dirPath: string, fileName: string) => Promise<void>
@@ -432,6 +434,7 @@ function RenderNode({
onOpenFilePreview,
onOpenFileDiff,
onOpenDirDiff,
onOpenCommitWindow,
onRequestCompareWithBranch,
onRequestRollback,
onOpenDirInTerminal,
@@ -507,6 +510,12 @@ function RenderNode({
{t("git")}
</ContextMenuSubTrigger>
<ContextMenuSubContent>
<ContextMenuItem
onSelect={() => onOpenCommitWindow()}
disabled={isGitMenuDisabled}
>
{t("actions.commitCode")}
</ContextMenuItem>
<ContextMenuItem
onSelect={() => onRequestAddToVcs(node)}
disabled={
@@ -614,6 +623,7 @@ function RenderNode({
onOpenFilePreview={onOpenFilePreview}
onOpenFileDiff={onOpenFileDiff}
onOpenDirDiff={onOpenDirDiff}
onOpenCommitWindow={onOpenCommitWindow}
onRequestCompareWithBranch={onRequestCompareWithBranch}
onRequestRollback={onRequestRollback}
onOpenDirInTerminal={onOpenDirInTerminal}
@@ -632,6 +642,12 @@ function RenderNode({
{t("git")}
</ContextMenuSubTrigger>
<ContextMenuSubContent>
<ContextMenuItem
onSelect={() => onOpenCommitWindow()}
disabled={isGitMenuDisabled}
>
{t("actions.commitCode")}
</ContextMenuItem>
<ContextMenuItem
onSelect={() => onRequestAddToVcs(node)}
disabled={isGitMenuDisabled}
@@ -1114,6 +1130,16 @@ export function FileTreeTab() {
[createTerminalInDirectory, t]
)
const handleOpenCommitWindow = useCallback(() => {
if (!folder) return
openCommitWindow(folder.id).catch((error) => {
const message = error instanceof Error ? error.message : String(error)
toast.error(t("toasts.openCommitWindowFailed"), {
description: message,
})
})
}, [folder, t])
const handleRequestRename = useCallback((target: FileActionTarget) => {
setRenameTarget(target)
setRenameValue(target.name)
@@ -2012,6 +2038,7 @@ export function FileTreeTab() {
onOpenDirDiff={(path) => {
void openWorkingTreeDiff(path, { mode: "overview" })
}}
onOpenCommitWindow={handleOpenCommitWindow}
onRequestCompareWithBranch={
handleRequestCompareWithBranch
}

View File

@@ -42,6 +42,7 @@ import {
gitAddFiles,
gitRollbackFile,
gitStatus,
openCommitWindow,
startFileTreeWatch,
stopFileTreeWatch,
} from "@/lib/tauri"
@@ -682,6 +683,16 @@ export function GitChangesTab() {
setExpandedUntrackedPaths(new Set())
}, [allUntrackedDirectoryPaths, untrackedCanExpand])
const handleOpenCommitWindow = useCallback(() => {
if (!folder) return
openCommitWindow(folder.id).catch((error) => {
const message = error instanceof Error ? error.message : String(error)
toast.error(t("toasts.openCommitWindowFailed"), {
description: message,
})
})
}, [folder, t])
const resetDirectoryGitActionDialog = useCallback(() => {
setDirectoryGitActionType(null)
setDirectoryGitActionTarget(null)
@@ -902,6 +913,13 @@ export function GitChangesTab() {
</FileTreeFolder>
</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem
onSelect={() => {
handleOpenCommitWindow()
}}
>
{t("actions.commitCode")}
</ContextMenuItem>
<ContextMenuItem
onSelect={() => {
void openWorkingTreeDiff(node.path, { mode: "overview" })
@@ -966,6 +984,13 @@ export function GitChangesTab() {
</FileTreeFile>
</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem
onSelect={() => {
handleOpenCommitWindow()
}}
>
{t("actions.commitCode")}
</ContextMenuItem>
<ContextMenuItem
disabled={!canOpenCurrentFile}
onSelect={() => {
@@ -1002,6 +1027,7 @@ export function GitChangesTab() {
)
},
[
handleOpenCommitWindow,
handleAddToVcs,
handleRequestRollback,
openFilePreview,
@@ -1034,6 +1060,13 @@ export function GitChangesTab() {
</FileTreeFolder>
</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem
onSelect={() => {
handleOpenCommitWindow()
}}
>
{t("actions.commitCode")}
</ContextMenuItem>
<ContextMenuItem
onSelect={() => {
void openWorkingTreeDiff(node.path, { mode: "overview" })
@@ -1090,6 +1123,13 @@ export function GitChangesTab() {
</FileTreeFile>
</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem
onSelect={() => {
handleOpenCommitWindow()
}}
>
{t("actions.commitCode")}
</ContextMenuItem>
<ContextMenuItem
onSelect={() => {
void openFilePreview(file.path)
@@ -1124,6 +1164,7 @@ export function GitChangesTab() {
)
},
[
handleOpenCommitWindow,
handleAddToVcs,
handleRequestRollback,
openFilePreview,

View File

@@ -895,6 +895,7 @@
"expandUntracked": "Expand untracked files",
"collapseUntracked": "Collapse untracked files",
"actions": {
"commitCode": "Commit code",
"rollback": "Rollback",
"addToVcs": "Add to VCS"
},
@@ -903,6 +904,7 @@
"noRollbackFilesInDir": "No changed files in this directory can be rolled back",
"addedToVcs": "Added {name} to VCS",
"addToVcsFailed": "Failed to add to VCS",
"openCommitWindowFailed": "Failed to open commit window",
"rolledBack": "Rolled back {name}",
"rollbackFailed": "Rollback failed",
"addedFilesToVcs": "Added {count, plural, one {# file} other {# files}} to VCS",
@@ -946,6 +948,7 @@
"actions": {
"select": "Select",
"unselect": "Unselect",
"commitCode": "Commit code",
"rollback": "Rollback",
"addToVcs": "Add to VCS"
},
@@ -955,6 +958,7 @@
"toasts": {
"openDirectoryFailed": "Failed to open directory",
"openBuiltinTerminalFailed": "Unable to open built-in terminal",
"openCommitWindowFailed": "Failed to open commit window",
"noAddableFilesInDir": "No changed files in this directory can be added to VCS",
"noRollbackFilesInDir": "No changed files in this directory can be rolled back",
"addedToVcs": "Added {name} to VCS",

View File

@@ -895,6 +895,7 @@
"expandUntracked": "展开未跟踪文件",
"collapseUntracked": "折叠未跟踪文件",
"actions": {
"commitCode": "提交代码",
"rollback": "回滚",
"addToVcs": "添加到 VCS"
},
@@ -903,6 +904,7 @@
"noRollbackFilesInDir": "该目录下没有可回滚的变更文件",
"addedToVcs": "已添加 {name} 到 VCS",
"addToVcsFailed": "添加到 VCS 失败",
"openCommitWindowFailed": "打开提交窗口失败",
"rolledBack": "已回滚 {name}",
"rollbackFailed": "回滚失败",
"addedFilesToVcs": "已添加 {count} 个文件到 VCS",
@@ -946,6 +948,7 @@
"actions": {
"select": "选择",
"unselect": "取消选择",
"commitCode": "提交代码",
"rollback": "回滚",
"addToVcs": "添加到 VCS"
},
@@ -955,6 +958,7 @@
"toasts": {
"openDirectoryFailed": "打开目录失败",
"openBuiltinTerminalFailed": "无法打开内置终端",
"openCommitWindowFailed": "打开提交窗口失败",
"noAddableFilesInDir": "该目录下没有可添加到 VCS 的变更文件",
"noRollbackFilesInDir": "该目录下没有可回滚的变更文件",
"addedToVcs": "已添加 {name} 到 VCS",

View File

@@ -895,6 +895,7 @@
"expandUntracked": "展開未追蹤檔案",
"collapseUntracked": "折疊未追蹤檔案",
"actions": {
"commitCode": "提交程式碼",
"rollback": "回滾",
"addToVcs": "加入到 VCS"
},
@@ -903,6 +904,7 @@
"noRollbackFilesInDir": "該目錄下沒有可回滾的變更檔案",
"addedToVcs": "已加入 {name} 到 VCS",
"addToVcsFailed": "加入到 VCS 失敗",
"openCommitWindowFailed": "打開提交視窗失敗",
"rolledBack": "已回滾 {name}",
"rollbackFailed": "回滾失敗",
"addedFilesToVcs": "已加入 {count} 個檔案到 VCS",
@@ -946,6 +948,7 @@
"actions": {
"select": "選擇",
"unselect": "取消選擇",
"commitCode": "提交程式碼",
"rollback": "回滾",
"addToVcs": "加入到 VCS"
},
@@ -955,6 +958,7 @@
"toasts": {
"openDirectoryFailed": "開啟目錄失敗",
"openBuiltinTerminalFailed": "無法開啟內建終端",
"openCommitWindowFailed": "打開提交視窗失敗",
"noAddableFilesInDir": "該目錄下沒有可加入到 VCS 的變更檔案",
"noRollbackFilesInDir": "該目錄下沒有可回滾的變更檔案",
"addedToVcs": "已加入 {name} 到 VCS",