merge feat/109-tab-context-menu into dev(#109 Tab 右键菜单补「全部关闭」与「在资源管理器中定位」,含 20 份词典与文档同步)

This commit is contained in:
Menghuan1918 committed 2026-10-05 21:59:25 +08:00
commit 39e7b587d8
27 files changed
+348 -30

No files matched your search

+22
View File
@@ -47,6 +47,7 @@ import { getShellPreset } from './shell-presets.ts'
import { computeTitleBarStrip } from './titlebar-strip.ts'
import { TabContent, buildNewTabOptions } from './sidebar/TabContent.tsx'
import { confirmDiscardDraft, dirtyCount, editorDirtyRevision, subscribeEditorDirty } from './editor-dirty.ts'
import { createOpenInApp } from './open-in-app.ts'
import { useCenterColumn } from './sidebar/use-center-column.ts'
import { useHostFeeds } from './sidebar/use-host-feeds.ts'
import { mountedSessions } from './native/surface.ts'
@@ -575,6 +576,26 @@ export function Sidebar(props: { ctx: Context; store: SidebarStore }) {
referenceInChatShared(ctx, sessionId, path, isDir)
}, [ctx, sessionId])
/**
* The tab context menu's "reveal in the file manager" row. The host's
* open-in-app capability is the ONLY path this plugin reveals through
* (`ctx.remote.session.openWorkspacePath({action:'reveal'})`, shared with
* the explorer's own reveal row via `createOpenInApp`); a deployment
* without a desktop (plain web) answers false, which is logged and
* otherwise a no-op — the bottom panel has no error strip to write to, and
* a failed reveal must never take the strip down. Defined above the
* no-session early return — a hook must never sit behind a conditional
* return (React counts hooks per render).
*/
const openInApp = useMemo(() => createOpenInApp(ctx), [ctx])
const revealTabFile = useCallback((path: string): void => {
void openInApp.reveal(path).then((ok) => {
if (!ok) console.error(`[dsh-better-sidebar] reveal in file manager failed: ${path}`)
}).catch((error: unknown) => {
console.error('[dsh-better-sidebar] reveal in file manager error:', error)
})
}, [openInApp])
if (state === undefined || sessionId === undefined) {
// No conversation yet: the host stays mounted (the drag shield keeps
// covering the region) but nothing is rendered — the toggle button lives
@@ -775,6 +796,7 @@ export function Sidebar(props: { ctx: Context; store: SidebarStore }) {
getTabIcon={tabIconOf}
getTabBadge={tabBadgeOf}
getTabRightActions={tabRightActionsOf}
onRevealInFileManager={revealTabFile}
/>
</div>
</div>
+33 -5
View File
@@ -5,7 +5,8 @@
* are draggable; dropping onto another tab inserts before it, dropping on the
* strip background appends to this pane. Right-clicking a tab opens the tab
* context menu (close / close others / close to the left / close to the
* right, the close ones scoped to this pane).
* right / close all — every close scoped to this pane — plus reveal the
* right-clicked tab's file in the OS file manager).
*/
import { useEffect, useRef, useState, type ReactNode } from 'react'
import clsx from 'clsx'
@@ -79,9 +80,18 @@ export function TabBar(props: {
* render their own).
*/
getTabRightActions?: (tab: SidebarTab, paneId: string) => ReactNode
/**
* Reveal one tab's associated file in the OS file manager — the tab
* context menu's reveal row, fed by the shell with the host's open-in-app
* capability. The row is disabled for a tab with no associated file (no
* `path`, e.g. the changes / tasks / side-chat / diff pages) and when the
* shell passes no resolver at all.
*/
onRevealInFileManager?: (path: string) => void
}) {
const {
paneId, tabs, active, onActivate, onClose, onNewTab, newTabOptions, onDropTab, getTabIcon, getTabBadge, getTabRightActions,
onRevealInFileManager,
} = props
const [menuOpen, setMenuOpen] = useState(false)
// The tab right-click context menu: the target tab plus the cursor
@@ -92,6 +102,12 @@ export function TabBar(props: {
// The context target's index in the render-time tab snapshot; -1 when the
// tab disappeared since the menu opened (the menu hides then).
const tabMenuIndex = tabMenu === null ? -1 : tabs.findIndex(tab => tab.id === tabMenu.tabId)
// The context target's associated file: `path` carries it for file tabs
// (editor windows, folder windows included). The changes / tasks /
// side-chat / diff pages have none — a diff's repo-relative ref is not a
// path the host could reveal — so the reveal row greys out for them.
const tabMenuPath = tabs[tabMenuIndex]?.path
const canReveal = onRevealInFileManager !== undefined && tabMenuPath !== undefined && tabMenuPath !== ''
// The active tab's right-actions node, resolved up front so the render
// below can skip the wrapper entirely when there is nothing to show (an
@@ -284,10 +300,12 @@ export function TabBar(props: {
{/*
The tab context menu, positioned at the right-click cursor (portal
so the panel's overflow clip cannot crop it). Close operations are
scoped to THIS pane: "close others/left/right" walk the render-time
tab snapshot and reuse the per-tab onClose path (which routes
through the service), so the target tab is never closed and the
pane never empties mid-loop.
scoped to THIS pane: "close others/left/right/all" walk the
render-time tab snapshot and reuse the per-tab onClose path (which
routes through the service), so every closed tab runs its own
lifecycle and the target tab is only closed by the operations that
mean it (close / close all). "Close all" is always available: the
menu only opens from a tab, so the pane always holds at least one.
*/}
<Menu
open={tabMenu !== null && tabMenuIndex >= 0}
@@ -297,6 +315,8 @@ export function TabBar(props: {
{ id: 'closeOthers', label: t('closeOtherTabs'), ...(tabs.length <= 1 ? { disabled: true } : {}) },
{ id: 'closeLeft', label: t('closeLeftTabs'), ...(tabMenuIndex <= 0 ? { disabled: true } : {}) },
{ id: 'closeRight', label: t('closeRightTabs'), ...(tabMenuIndex >= tabs.length - 1 ? { disabled: true } : {}) },
{ id: 'closeAll', label: t('closeAllTabs') },
{ id: 'revealInFileManager', label: t('revealTabInFileManager'), ...(canReveal ? {} : { disabled: true }) },
]}
onSelect={(id) => {
const target = tabMenu
@@ -314,6 +334,14 @@ export function TabBar(props: {
for (const tab of tabs.slice(0, index)) onClose(tab.id)
} else if (id === 'closeRight') {
for (const tab of tabs.slice(index + 1)) onClose(tab.id)
} else if (id === 'closeAll') {
// EVERY tab in this pane, the right-clicked one included (that
// is what separates it from "close others") and the ones
// scrolled out of the strip's viewport included.
for (const tab of tabs) onClose(tab.id)
} else if (id === 'revealInFileManager') {
const path = tabs[index]?.path
if (path !== undefined && path !== '') onRevealInFileManager?.(path)
}
}}
portal
+2
View File
@@ -119,6 +119,8 @@ export const ar: Record<string, string> = {
closeOtherTabs: 'إغلاق التبويبات الأخرى',
closeLeftTabs: 'إغلاق التبويبات على اليسار',
closeRightTabs: 'إغلاق التبويبات على اليمين',
closeAllTabs: 'إغلاق كل التبويبات',
revealTabInFileManager: 'إظهار الملف في مدير الملفات',
pinTerminal: 'تثبيت الطرفية',
pinAgentTerminal: 'تثبيت طرفية Agent',
pinToWorkspace: 'تثبيت إلى مساحة العمل',
+2
View File
@@ -104,6 +104,8 @@ export const de: Record<string, string> = {
closeOtherTabs: 'Andere Tabs schließen',
closeLeftTabs: 'Tabs links schließen',
closeRightTabs: 'Tabs rechts schließen',
closeAllTabs: 'Alle Tabs schließen',
revealTabInFileManager: 'Datei im Dateimanager anzeigen',
pinTerminal: 'Terminal anheften',
pinAgentTerminal: 'Agent-Terminal anheften',
pinToWorkspace: 'An Arbeitsbereich anheften',
+2
View File
@@ -111,6 +111,8 @@ export const fr: Record<string, string> = {
closeOtherTabs: 'Fermer les autres onglets',
closeLeftTabs: 'Fermer les onglets à gauche',
closeRightTabs: 'Fermer les onglets à droite',
closeAllTabs: 'Fermer tous les onglets',
revealTabInFileManager: 'Afficher le fichier dans le gestionnaire de fichiers',
pinTerminal: 'Épingler le terminal',
pinAgentTerminal: 'Épingler le terminal Agent',
pinToWorkspace: 'Épingler à l\'espace de travail',
+2
View File
@@ -118,6 +118,8 @@ export const hi: Record<string, string> = {
closeOtherTabs: 'अन्य टैब बंद करें',
closeLeftTabs: 'बाएँ टैब बंद करें',
closeRightTabs: 'दाएँ टैब बंद करें',
closeAllTabs: 'सभी टैब बंद करें',
revealTabInFileManager: 'फ़ाइल को फ़ाइल मैनेजर में दिखाएँ',
pinTerminal: 'टर्मिनल पिन करें',
pinAgentTerminal: 'Agent टर्मिनल पिन करें',
pinToWorkspace: 'वर्कस्पेस पर पिन करें',
+2
View File
@@ -116,6 +116,8 @@ export const id: Record<string, string> = {
closeOtherTabs: 'Tutup Tab Lain',
closeLeftTabs: 'Tutup Tab di Kiri',
closeRightTabs: 'Tutup Tab di Kanan',
closeAllTabs: 'Tutup Semua Tab',
revealTabInFileManager: 'Tampilkan Berkas di Pengelola Berkas',
pinTerminal: 'Sematkan Terminal',
pinAgentTerminal: 'Sematkan Terminal Agent',
pinToWorkspace: 'Sematkan ke Workspace',
+2
View File
@@ -109,6 +109,8 @@ export const it: Record<string, string> = {
closeOtherTabs: 'Chiudi le altre schede',
closeLeftTabs: 'Chiudi le schede a sinistra',
closeRightTabs: 'Chiudi le schede a destra',
closeAllTabs: 'Chiudi tutte le schede',
revealTabInFileManager: 'Mostra il file nel gestore file',
pinTerminal: 'Blocca Terminale',
pinAgentTerminal: 'Blocca Terminale Agent',
pinToWorkspace: 'Blocca in Workspace',
+2
View File
@@ -118,6 +118,8 @@ export const ja: Record<string, string> = {
closeOtherTabs: '他のタブを閉じる',
closeLeftTabs: '左のタブを閉じる',
closeRightTabs: '右のタブを閉じる',
closeAllTabs: 'すべてのタブを閉じる',
revealTabInFileManager: 'ファイルの場所を開く',
pinTerminal: 'ターミナルを固定',
pinAgentTerminal: 'Agent ターミナルを固定',
pinToWorkspace: 'ワークスペースに固定',
+2
View File
@@ -110,6 +110,8 @@ export const ko: Record<string, string> = {
closeOtherTabs: '다른 탭 닫기',
closeLeftTabs: '왼쪽 탭 닫기',
closeRightTabs: '오른쪽 탭 닫기',
closeAllTabs: '모든 탭 닫기',
revealTabInFileManager: '파일 위치 열기',
pinTerminal: '터미널 고정',
pinAgentTerminal: 'Agent 터미널 고정',
pinToWorkspace: '워크스페이스에 고정',
+2
View File
@@ -116,6 +116,8 @@ export const nl: Record<string, string> = {
closeOtherTabs: 'Andere tabbladen sluiten',
closeLeftTabs: 'Tabbladen links sluiten',
closeRightTabs: 'Tabbladen rechts sluiten',
closeAllTabs: 'Alle tabbladen sluiten',
revealTabInFileManager: 'Bestand tonen in bestandsbeheerder',
pinTerminal: 'Terminal vastmaken',
pinAgentTerminal: 'Agent-terminal vastmaken',
pinToWorkspace: 'Vastmaken aan werkruimte',
+2
View File
@@ -120,6 +120,8 @@ export const pl: Record<string, string> = {
closeOtherTabs: 'Zamknij inne karty',
closeLeftTabs: 'Zamknij karty po lewej',
closeRightTabs: 'Zamknij karty po prawej',
closeAllTabs: 'Zamknij wszystkie karty',
revealTabInFileManager: 'Pokaż plik w menedżerze plików',
pinTerminal: 'Przypnij Terminal',
pinAgentTerminal: 'Przypnij Terminal Agent',
pinToWorkspace: 'Przypnij do obszaru roboczego',
+2
View File
@@ -101,6 +101,8 @@ export const pt: Record<string, string> = {
closeOtherTabs: 'Fechar outras abas',
closeLeftTabs: 'Fechar abas à esquerda',
closeRightTabs: 'Fechar abas à direita',
closeAllTabs: 'Fechar todas as abas',
revealTabInFileManager: 'Mostrar arquivo no gerenciador de arquivos',
pinTerminal: 'Fixar Terminal',
pinAgentTerminal: 'Fixar Terminal do Agent',
pinToWorkspace: 'Fixar no Workspace',
+2
View File
@@ -114,6 +114,8 @@ export const ru: Record<string, string> = {
closeOtherTabs: 'Закрыть остальные вкладки',
closeLeftTabs: 'Закрыть вкладки слева',
closeRightTabs: 'Закрыть вкладки справа',
closeAllTabs: 'Закрыть все вкладки',
revealTabInFileManager: 'Показать файл в файловом менеджере',
pinTerminal: 'Закрепить терминал',
pinAgentTerminal: 'Закрепить терминал Agent',
pinToWorkspace: 'Закрепить в рабочей области',
+2
View File
@@ -101,6 +101,8 @@ export const sv: Record<string, string> = {
closeOtherTabs: 'Stäng andra flikar',
closeLeftTabs: 'Stäng flikar till vänster',
closeRightTabs: 'Stäng flikar till höger',
closeAllTabs: 'Stäng alla flikar',
revealTabInFileManager: 'Visa filen i filhanteraren',
pinTerminal: 'Fäst Terminal',
pinAgentTerminal: 'Fäst Agent-terminal',
pinToWorkspace: 'Fäst på arbetsyta',
+2
View File
@@ -118,6 +118,8 @@ export const th: Record<string, string> = {
closeOtherTabs: 'ปิด Tab อื่น',
closeLeftTabs: 'ปิด Tab ด้านซ้าย',
closeRightTabs: 'ปิด Tab ด้านขวา',
closeAllTabs: 'ปิด Tab ทั้งหมด',
revealTabInFileManager: 'แสดงไฟล์ในตัวจัดการไฟล์',
pinTerminal: 'ปักหมุดเทอร์มินัล',
pinAgentTerminal: 'ปักหมุดเทอร์มินัล Agent',
pinToWorkspace: 'ปักหมุดไปยังพื้นที่ทำงาน',
+2
View File
@@ -118,6 +118,8 @@ export const tr: Record<string, string> = {
closeOtherTabs: 'Diğer sekmeleri kapat',
closeLeftTabs: 'Soldaki sekmeleri kapat',
closeRightTabs: 'Sağdaki sekmeleri kapat',
closeAllTabs: 'Tüm sekmeleri kapat',
revealTabInFileManager: 'Dosyayı dosya yöneticisinde göster',
pinTerminal: 'Terminali Sabitle',
pinAgentTerminal: 'Agent Terminalini Sabitle',
pinToWorkspace: 'Çalışma Alanına Sabitle',
+2
View File
@@ -118,6 +118,8 @@ export const vi: Record<string, string> = {
closeOtherTabs: 'Đóng các tab khác',
closeLeftTabs: 'Đóng tab bên trái',
closeRightTabs: 'Đóng tab bên phải',
closeAllTabs: 'Đóng tất cả tab',
revealTabInFileManager: 'Hiển thị tệp trong trình quản lý tệp',
pinTerminal: 'Ghim Terminal',
pinAgentTerminal: 'Ghim Terminal Agent',
pinToWorkspace: 'Ghim vào Workspace',
+2
View File
@@ -133,6 +133,8 @@ export const zhHK: Record<string, string> = {
closeOtherTabs: '關閉其他標籤',
closeLeftTabs: '關閉左側標籤',
closeRightTabs: '關閉右側標籤',
closeAllTabs: '關閉全部標籤',
revealTabInFileManager: '在檔案總管中定位',
pinTerminal: '固定終端',
pinAgentTerminal: '固定 Agent 終端',
pinToWorkspace: '固定到工作區',
+2
View File
@@ -133,6 +133,8 @@ export const zhMO: Record<string, string> = {
closeOtherTabs: '關閉其他標籤',
closeLeftTabs: '關閉左側標籤',
closeRightTabs: '關閉右側標籤',
closeAllTabs: '關閉全部標籤',
revealTabInFileManager: '在檔案總管中定位',
pinTerminal: '固定終端',
pinAgentTerminal: '固定 Agent 終端',
pinToWorkspace: '固定到工作區',
+2
View File
@@ -133,6 +133,8 @@ export const zhTW: Record<string, string> = {
closeOtherTabs: '關閉其他標籤',
closeLeftTabs: '關閉左側標籤',
closeRightTabs: '關閉右側標籤',
closeAllTabs: '關閉全部標籤',
revealTabInFileManager: '在檔案總管中定位',
pinTerminal: '固定終端',
pinAgentTerminal: '固定 Agent 終端',
pinToWorkspace: '固定到工作區',
+4
View File
@@ -130,6 +130,8 @@ export const zh = {
closeOtherTabs: '关闭其他页签',
closeLeftTabs: '关闭左侧页签',
closeRightTabs: '关闭右侧页签',
closeAllTabs: '关闭全部页签',
revealTabInFileManager: '在资源管理器中定位',
pinTerminal: '固定终端',
pinAgentTerminal: '固定 Agent 终端',
pinToWorkspace: '固定到工作区',
@@ -696,6 +698,8 @@ export const en: Record<keyof typeof zh, string> = {
closeOtherTabs: 'Close Other Tabs',
closeLeftTabs: 'Close Tabs to the Left',
closeRightTabs: 'Close Tabs to the Right',
closeAllTabs: 'Close All Tabs',
revealTabInFileManager: 'Reveal in File Manager',
pinTerminal: 'Pin Terminal',
pinAgentTerminal: 'Pin Agent Terminal',
pinToWorkspace: 'Pin to Workspace',
+16 -3
View File
@@ -148,8 +148,13 @@ function LeafView(props: {
getTabIcon?: (tab: SidebarTab) => ReactNode
getTabBadge?: (tab: SidebarTab) => ReactNode
getTabRightActions?: (tab: SidebarTab, paneId: string) => ReactNode
/**
* Reveal a tab's file in the OS file manager (the tab context menu's
* reveal row; see TabBar). Absent → that row stays disabled.
*/
onRevealInFileManager?: (path: string) => void
}) {
const { leaf, newTabOptions, actions, onNewTab, renderTab, getTabIcon, getTabBadge, getTabRightActions } = props
const { leaf, newTabOptions, actions, onNewTab, renderTab, getTabIcon, getTabBadge, getTabRightActions, onRevealInFileManager } = props
const [dropZone, setDropZone] = useState<DropZone | null>(null)
const activeTab = leaf.tabs.find(tab => tab.id === leaf.active) ?? leaf.tabs[leaf.tabs.length - 1]
@@ -206,6 +211,7 @@ function LeafView(props: {
getTabIcon={getTabIcon}
getTabBadge={getTabBadge}
getTabRightActions={getTabRightActions}
onRevealInFileManager={onRevealInFileManager}
onDropTab={(payload, before) => {
if (before === null) actions.moveTabToEdge(payload, leaf.id, 'center')
else actions.moveTabBefore(payload, leaf.id, before)
@@ -246,8 +252,9 @@ function NodeView(props: {
getTabIcon?: (tab: SidebarTab) => ReactNode
getTabBadge?: (tab: SidebarTab) => ReactNode
getTabRightActions?: (tab: SidebarTab, paneId: string) => ReactNode
onRevealInFileManager?: (path: string) => void
}) {
const { node, state, newTabOptions, actions, onNewTab, renderTab, getTabIcon, getTabBadge, getTabRightActions } = props
const { node, state, newTabOptions, actions, onNewTab, renderTab, getTabIcon, getTabBadge, getTabRightActions, onRevealInFileManager } = props
if (node.kind === 'leaf') {
return (
<LeafView
@@ -259,6 +266,7 @@ function NodeView(props: {
getTabIcon={getTabIcon}
getTabBadge={getTabBadge}
getTabRightActions={getTabRightActions}
onRevealInFileManager={onRevealInFileManager}
/>
)
}
@@ -287,6 +295,7 @@ function NodeView(props: {
getTabIcon={getTabIcon}
getTabBadge={getTabBadge}
getTabRightActions={getTabRightActions}
onRevealInFileManager={onRevealInFileManager}
/>
</div>
</Fragment>
@@ -309,8 +318,11 @@ export function Workbench(props: {
getTabIcon?: (tab: SidebarTab) => ReactNode
getTabBadge?: (tab: SidebarTab) => ReactNode
getTabRightActions?: (tab: SidebarTab, paneId: string) => ReactNode
/** Reveal a tab's file in the OS file manager (see TabBar); absent → the
* tab context menu's reveal row is disabled. */
onRevealInFileManager?: (path: string) => void
}) {
const { state, tree, newTabOptions, actions, onNewTab, renderTab, getTabIcon, getTabBadge, getTabRightActions } = props
const { state, tree, newTabOptions, actions, onNewTab, renderTab, getTabIcon, getTabBadge, getTabRightActions, onRevealInFileManager } = props
return (
<div className={css.workbench}>
<NodeView
@@ -323,6 +335,7 @@ export function Workbench(props: {
getTabIcon={getTabIcon}
getTabBadge={getTabBadge}
getTabRightActions={getTabRightActions}
onRevealInFileManager={onRevealInFileManager}
/>
</div>
)