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

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,