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

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, gitStatus,
readFileForEdit, readFileForEdit,
readFilePreview, readFilePreview,
openCommitWindow,
renameFileTreeEntry, renameFileTreeEntry,
saveFileCopy, saveFileCopy,
startFileTreeWatch, startFileTreeWatch,
@@ -410,6 +411,7 @@ interface RenderNodeProps {
onOpenFilePreview: (path: string) => void onOpenFilePreview: (path: string) => void
onOpenFileDiff: (path: string) => void onOpenFileDiff: (path: string) => void
onOpenDirDiff: (path: string) => void onOpenDirDiff: (path: string) => void
onOpenCommitWindow: () => void
onRequestCompareWithBranch: (target: FileActionTarget) => void onRequestCompareWithBranch: (target: FileActionTarget) => void
onRequestRollback: (target: FileActionTarget) => void onRequestRollback: (target: FileActionTarget) => void
onOpenDirInTerminal: (dirPath: string, fileName: string) => Promise<void> onOpenDirInTerminal: (dirPath: string, fileName: string) => Promise<void>
@@ -432,6 +434,7 @@ function RenderNode({
onOpenFilePreview, onOpenFilePreview,
onOpenFileDiff, onOpenFileDiff,
onOpenDirDiff, onOpenDirDiff,
onOpenCommitWindow,
onRequestCompareWithBranch, onRequestCompareWithBranch,
onRequestRollback, onRequestRollback,
onOpenDirInTerminal, onOpenDirInTerminal,
@@ -507,6 +510,12 @@ function RenderNode({
{t("git")} {t("git")}
</ContextMenuSubTrigger> </ContextMenuSubTrigger>
<ContextMenuSubContent> <ContextMenuSubContent>
<ContextMenuItem
onSelect={() => onOpenCommitWindow()}
disabled={isGitMenuDisabled}
>
{t("actions.commitCode")}
</ContextMenuItem>
<ContextMenuItem <ContextMenuItem
onSelect={() => onRequestAddToVcs(node)} onSelect={() => onRequestAddToVcs(node)}
disabled={ disabled={
@@ -614,6 +623,7 @@ function RenderNode({
onOpenFilePreview={onOpenFilePreview} onOpenFilePreview={onOpenFilePreview}
onOpenFileDiff={onOpenFileDiff} onOpenFileDiff={onOpenFileDiff}
onOpenDirDiff={onOpenDirDiff} onOpenDirDiff={onOpenDirDiff}
onOpenCommitWindow={onOpenCommitWindow}
onRequestCompareWithBranch={onRequestCompareWithBranch} onRequestCompareWithBranch={onRequestCompareWithBranch}
onRequestRollback={onRequestRollback} onRequestRollback={onRequestRollback}
onOpenDirInTerminal={onOpenDirInTerminal} onOpenDirInTerminal={onOpenDirInTerminal}
@@ -632,6 +642,12 @@ function RenderNode({
{t("git")} {t("git")}
</ContextMenuSubTrigger> </ContextMenuSubTrigger>
<ContextMenuSubContent> <ContextMenuSubContent>
<ContextMenuItem
onSelect={() => onOpenCommitWindow()}
disabled={isGitMenuDisabled}
>
{t("actions.commitCode")}
</ContextMenuItem>
<ContextMenuItem <ContextMenuItem
onSelect={() => onRequestAddToVcs(node)} onSelect={() => onRequestAddToVcs(node)}
disabled={isGitMenuDisabled} disabled={isGitMenuDisabled}
@@ -1114,6 +1130,16 @@ export function FileTreeTab() {
[createTerminalInDirectory, t] [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) => { const handleRequestRename = useCallback((target: FileActionTarget) => {
setRenameTarget(target) setRenameTarget(target)
setRenameValue(target.name) setRenameValue(target.name)
@@ -2012,6 +2038,7 @@ export function FileTreeTab() {
onOpenDirDiff={(path) => { onOpenDirDiff={(path) => {
void openWorkingTreeDiff(path, { mode: "overview" }) void openWorkingTreeDiff(path, { mode: "overview" })
}} }}
onOpenCommitWindow={handleOpenCommitWindow}
onRequestCompareWithBranch={ onRequestCompareWithBranch={
handleRequestCompareWithBranch handleRequestCompareWithBranch
} }

View File

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

View File

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

View File

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

View File

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