支持文件和变更区域的根目录快捷操作

This commit is contained in:
xintaofei
2026-03-13 21:50:15 +08:00
parent bf14a99168
commit 3376974d0f
4 changed files with 252 additions and 59 deletions

View File

@@ -1120,7 +1120,7 @@ export function FileWorkspacePanel() {
path: diffListContext.path, path: diffListContext.path,
branch: diffListContext.branch, branch: diffListContext.branch,
}) })
: diffListContext.path : (activeFileTab.description ?? diffListContext.path)
const handleOpenDiff = async (path: string) => { const handleOpenDiff = async (path: string) => {
if (diffListContext.kind === "commit") { if (diffListContext.kind === "commit") {

View File

@@ -1701,6 +1701,22 @@ export function FileTreeTab() {
return baseName(folder.path) return baseName(folder.path)
}, [folder?.path, t]) }, [folder?.path, t])
const systemExplorerLabel =
typeof navigator === "undefined"
? t("openInFileManager")
: (() => {
const platform =
`${navigator.platform} ${navigator.userAgent}`.toLowerCase()
if (platform.includes("mac")) return t("openInFinder")
if (platform.includes("win")) return t("openInExplorer")
return t("openInFileManager")
})()
const rootTarget: FileActionTarget = useMemo(
() => ({ kind: "dir", path: "", name: rootNodeName }),
[rootNodeName]
)
useEffect(() => { useEffect(() => {
if (!isFileTreeTabActive) return if (!isFileTreeTabActive) return
void fetchTree() void fetchTree()
@@ -2009,6 +2025,8 @@ export function FileTreeTab() {
onSelect={handleTreeSelect} onSelect={handleTreeSelect}
> >
{folder?.path && ( {folder?.path && (
<ContextMenu>
<ContextMenuTrigger asChild>
<FileTreeFolder <FileTreeFolder
path={FILE_TREE_ROOT_PATH} path={FILE_TREE_ROOT_PATH}
name={rootNodeName} name={rootNodeName}
@@ -2033,7 +2051,9 @@ export function FileTreeTab() {
void openWorkingTreeDiff(path) void openWorkingTreeDiff(path)
}} }}
onOpenDirDiff={(path) => { onOpenDirDiff={(path) => {
void openWorkingTreeDiff(path, { mode: "overview" }) void openWorkingTreeDiff(path, {
mode: "overview",
})
}} }}
onOpenCommitWindow={handleOpenCommitWindow} onOpenCommitWindow={handleOpenCommitWindow}
onRequestCompareWithBranch={ onRequestCompareWithBranch={
@@ -2048,6 +2068,85 @@ export function FileTreeTab() {
/> />
))} ))}
</FileTreeFolder> </FileTreeFolder>
</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuSub>
<ContextMenuSubTrigger disabled={!gitEnabled}>
{t("git")}
</ContextMenuSubTrigger>
<ContextMenuSubContent>
<ContextMenuItem
onSelect={() => handleOpenCommitWindow()}
disabled={!gitEnabled}
>
{t("actions.commitCode")}
</ContextMenuItem>
<ContextMenuItem
onSelect={() => void handleAddToVcs(rootTarget)}
disabled={!gitEnabled}
>
{t("actions.addToVcs")}
</ContextMenuItem>
<ContextMenuItem
onSelect={() =>
void openWorkingTreeDiff(".", {
mode: "overview",
})
}
disabled={!gitEnabled}
>
{tCommon("viewDiff")}
</ContextMenuItem>
<ContextMenuItem
onSelect={() =>
handleRequestCompareWithBranch(rootTarget)
}
disabled={!gitEnabled}
>
{t("compareWithBranch")}
</ContextMenuItem>
<ContextMenuItem
variant="destructive"
onSelect={() => handleRequestRollback(rootTarget)}
disabled={!gitEnabled}
>
{t("actions.rollback")}
</ContextMenuItem>
</ContextMenuSubContent>
</ContextMenuSub>
<ContextMenuItem
onSelect={() => {
void fetchTree()
}}
>
{t("reloadFromDisk")}
</ContextMenuItem>
<ContextMenuSub>
<ContextMenuSubTrigger>
{t("openIn")}
</ContextMenuSubTrigger>
<ContextMenuSubContent>
<ContextMenuItem
onSelect={() => {
void revealItemInDir(folder.path)
}}
>
{systemExplorerLabel}
</ContextMenuItem>
<ContextMenuItem
onSelect={() => {
void handleOpenDirInTerminal(
folder.path,
rootNodeName
)
}}
>
{t("openInTerminal")}
</ContextMenuItem>
</ContextMenuSubContent>
</ContextMenuSub>
</ContextMenuContent>
</ContextMenu>
)} )}
</FileTree> </FileTree>
</div> </div>

View File

@@ -1236,6 +1236,8 @@ export function GitChangesTab() {
expanded={expandedTrackedPaths} expanded={expandedTrackedPaths}
onExpandedChange={setExpandedTrackedPaths} onExpandedChange={setExpandedTrackedPaths}
> >
<ContextMenu>
<ContextMenuTrigger asChild>
<FileTreeFolder <FileTreeFolder
path={TRACKED_ROOT_PATH} path={TRACKED_ROOT_PATH}
name={folderName} name={folderName}
@@ -1245,6 +1247,49 @@ export function GitChangesTab() {
> >
{trackedTreeNodes.map(renderTrackedNode)} {trackedTreeNodes.map(renderTrackedNode)}
</FileTreeFolder> </FileTreeFolder>
</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem
onSelect={() => {
handleOpenCommitWindow()
}}
>
{t("actions.commitCode")}
</ContextMenuItem>
<ContextMenuItem
onSelect={() => {
void openWorkingTreeDiff(".", {
mode: "overview",
})
}}
>
{tCommon("viewDiff")}
</ContextMenuItem>
<ContextMenuItem
onSelect={() => {
handleRequestRollback({
kind: "dir",
path: "",
name: folderName,
})
}}
variant="destructive"
>
{t("actions.rollback")}
</ContextMenuItem>
<ContextMenuItem
onSelect={() => {
void handleAddToVcs({
kind: "dir",
path: "",
name: folderName,
})
}}
>
{t("actions.addToVcs")}
</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>
</FileTree> </FileTree>
</section> </section>
)} )}
@@ -1284,6 +1329,8 @@ export function GitChangesTab() {
expanded={expandedUntrackedPaths} expanded={expandedUntrackedPaths}
onExpandedChange={setExpandedUntrackedPaths} onExpandedChange={setExpandedUntrackedPaths}
> >
<ContextMenu>
<ContextMenuTrigger asChild>
<FileTreeFolder <FileTreeFolder
path={UNTRACKED_ROOT_PATH} path={UNTRACKED_ROOT_PATH}
name={folderName} name={folderName}
@@ -1293,6 +1340,49 @@ export function GitChangesTab() {
> >
{untrackedTreeNodes.map(renderUntrackedNode)} {untrackedTreeNodes.map(renderUntrackedNode)}
</FileTreeFolder> </FileTreeFolder>
</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem
onSelect={() => {
handleOpenCommitWindow()
}}
>
{t("actions.commitCode")}
</ContextMenuItem>
<ContextMenuItem
onSelect={() => {
void openWorkingTreeDiff(".", {
mode: "overview",
})
}}
>
{tCommon("viewDiff")}
</ContextMenuItem>
<ContextMenuItem
onSelect={() => {
handleRequestRollback({
kind: "dir",
path: "",
name: folderName,
})
}}
variant="destructive"
>
{t("actions.rollback")}
</ContextMenuItem>
<ContextMenuItem
onSelect={() => {
void handleAddToVcs({
kind: "dir",
path: "",
name: folderName,
})
}}
>
{t("actions.addToVcs")}
</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>
</FileTree> </FileTree>
</section> </section>
)} )}

View File

@@ -440,10 +440,14 @@ export function WorkspaceProvider({ children }: WorkspaceProviderProps) {
const mode = options?.mode ?? "auto" const mode = options?.mode ?? "auto"
if (mode === "overview") { if (mode === "overview") {
const isRoot = path === "."
const displayPath = isRoot ? folderPath : path
const encodedPath = encodeURIComponent(path) const encodedPath = encodeURIComponent(path)
const tabId = `diff:working-overview:${encodedPath}` const tabId = `diff:working-overview:${encodedPath}`
const title = t("diffTitleFile", { name: fileName(path) }) const title = t("diffTitleFile", {
const description = path name: fileName(displayPath ?? path),
})
const description = displayPath ?? path
upsertLoadingTab( upsertLoadingTab(
loadingTab(tabId, "diff", title, description, path, "diff") loadingTab(tabId, "diff", title, description, path, "diff")
) )