* Fix #954: unify Tooltip styling + replace native selects Replace native HTML title= tooltips and native <select> dropdowns with the existing Radix-based Tooltip / Select components so they share the app's rounded styling, theme tokens and i18n pipeline. Adds a global TooltipProvider in AppWithProviders so every descendant Tooltip works without a per-file Provider wrapper. Scope (driven by the issue #954 examples and "全部都处理" follow-up): - TerminalLayer toolbar: Add Terminal / Split View / SFTP / Scripts / Theme / AI Chat / Move panel / Close panel. - TopTabs middle bar: quick switcher, more tabs, AI assistant, theme toggle, settings; window-control buttons (min/max/close), tray close and hotkey reset/disable have their native title dropped per the user's explicit opt-out ("可以不用Tooltip,直接全局禁用 原生title 属性"). - AI panels: AIChatSidePanel session history / new chat / delete, ConversationExport, AgentSelector, ChatInput attach / expand / permission, ModelSelector, ProviderCard, ai-elements/tool-call. - SFTP: SftpSidePanel header, SftpBreadcrumb, SftpFileRow, SftpPaneToolbar, SftpTabBar, SftpTransferQueue. - Settings: SettingsPage close, SettingsAppearanceTab theme/accent swatches, SettingsFileAssociationsTab edit/remove, SettingsSystemTab crash-log paths and global hotkey reset. - Host vault: HostDetailsPanel (clear / suggestions / show-password / key path / browse key), GroupDetailsPanel, KnownHostsManager, ConnectionLogsManager, KeychainManager, SyncStatusButton, CloudSyncSettings, LogView, QuickSwitcher, ScriptsSidePanel, Terminal status bar copy-host + broadcast/focus, ZmodemProgressIndicator. - Terminal subcomponents: HostKeywordHighlightPopover, TerminalComposeBar, TerminalConnectionDialog, TerminalSearchBar. - Editor: TextEditorPane (subtitle, search, wrap, promote-to-tab). - TrayPanel session rows and port-forwarding rows. Native <select> migrated to custom Select component: - SerialConnectModal (data bits, stop bits, parity, flow control) - SerialHostDetailsPanel (same four fields) - HostDetailsPanel backspace behavior - GroupDetailsPanel backspace behavior - SettingsTerminalTab local shell picker - terminal/ThemeSidePanel font weight Hardcoded English strings extracted to i18n. New keys for both en and zh-CN: terminal.layer.*, topTabs.*, ai.chat.* (sessionHistory, attach, collapse, expand, enableAgent), zmodem.*, settings.shortcuts. resetToDefault. Inline help text on SnippetsManager package-name input removed because the same hint is already shown in a visible <p> below the input. Existing per-file <TooltipProvider> wrappers (SnippetsManager, ScriptsSidePanel, SelectHostPanel, RuleCard, HostDetailsPanel proxy section) are left in place — they nest harmlessly under the global provider and stay self-sufficient for component tests. Tests: - tsc clean for changed files (pre-existing repo-wide errors unrelated to this PR). - All 802 tests pass (3 skipped pre-existing). - HostDetailsPanel.proxyProfile.test and TextEditorPane.test updated to wrap with TooltipProvider, matching the runtime context now needed by the migrated components. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Fix #954: wrap Settings + Tray windows with TooltipProvider Settings and the tray panel mount as separate Electron windows with their own React root in index.tsx, so they do not inherit the global TooltipProvider added under AppWithProviders. After the unified Tooltip migration, any settings tab that used a Tooltip (Appearance, Application, FileAssociations, System, Shortcuts, Terminal, AI ProviderCard, AI ModelSelector) — and TrayPanel — threw "Tooltip must be used within TooltipProvider" and rendered nothing. Wrap both branches with TooltipProvider at the same level as ToastProvider in index.tsx. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
182 lines
8.5 KiB
TypeScript
182 lines
8.5 KiB
TypeScript
/**
|
|
* SFTP Breadcrumb navigation component
|
|
*/
|
|
|
|
import { ChevronDown, ChevronRight, Home, MoreHorizontal } from 'lucide-react';
|
|
import React, { memo, useCallback, useMemo, useState } from 'react';
|
|
import { useI18n } from '../../application/i18n/I18nProvider';
|
|
import { Dropdown, DropdownContent, DropdownTrigger } from '../ui/dropdown';
|
|
import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/tooltip';
|
|
import { cn } from '../../lib/utils';
|
|
|
|
interface SftpBreadcrumbProps {
|
|
path: string;
|
|
onNavigate: (path: string) => void;
|
|
onHome: () => void;
|
|
/** Maximum number of visible path segments before truncation (default: 4) */
|
|
maxVisibleParts?: number;
|
|
isLocal?: boolean;
|
|
onListDrives?: () => Promise<string[]>;
|
|
}
|
|
|
|
const SftpBreadcrumbInner: React.FC<SftpBreadcrumbProps> = ({
|
|
path,
|
|
onNavigate,
|
|
onHome,
|
|
maxVisibleParts = 4,
|
|
isLocal,
|
|
onListDrives,
|
|
}) => {
|
|
const { t } = useI18n();
|
|
|
|
const [drives, setDrives] = useState<string[]>([]);
|
|
const [driveDropdownOpen, setDriveDropdownOpen] = useState(false);
|
|
|
|
const handleDriveDropdownOpen = useCallback(async (open: boolean) => {
|
|
setDriveDropdownOpen(open);
|
|
if (open && onListDrives) {
|
|
const result = await onListDrives();
|
|
setDrives(result);
|
|
}
|
|
}, [onListDrives]);
|
|
|
|
// Handle both Windows (C:\path) and Unix (/path) style paths
|
|
const isWindowsPath = /^[A-Za-z]:/.test(path);
|
|
const separator = isWindowsPath ? /[\\/]/ : /\//;
|
|
const parts = path.split(separator).filter(Boolean);
|
|
|
|
// For Windows, first part might be drive letter like "C:"
|
|
const buildPath = (index: number) => {
|
|
if (isWindowsPath) {
|
|
const builtPath = parts.slice(0, index + 1).join('\\');
|
|
// If this is just a drive letter (e.g., "C:"), add trailing backslash
|
|
if (/^[A-Za-z]:$/.test(builtPath)) {
|
|
return builtPath + '\\';
|
|
}
|
|
return builtPath;
|
|
}
|
|
return '/' + parts.slice(0, index + 1).join('/');
|
|
};
|
|
|
|
// Determine which parts to show (always truncate, no expansion)
|
|
const { visibleParts, hiddenParts, needsTruncation } = useMemo(() => {
|
|
if (parts.length <= maxVisibleParts) {
|
|
return {
|
|
visibleParts: parts.map((part, idx) => ({ part, originalIndex: idx })),
|
|
hiddenParts: [] as { part: string; originalIndex: number }[],
|
|
needsTruncation: false
|
|
};
|
|
}
|
|
|
|
// Show first part + ellipsis + last (maxVisibleParts - 1) parts
|
|
const firstPart = [{ part: parts[0], originalIndex: 0 }];
|
|
const lastPartsCount = maxVisibleParts - 1;
|
|
const lastParts = parts.slice(-lastPartsCount).map((part, idx) => ({
|
|
part,
|
|
originalIndex: parts.length - lastPartsCount + idx
|
|
}));
|
|
const hidden = parts.slice(1, -lastPartsCount).map((part, idx) => ({
|
|
part,
|
|
originalIndex: idx + 1
|
|
}));
|
|
|
|
return {
|
|
visibleParts: [...firstPart, ...lastParts],
|
|
hiddenParts: hidden,
|
|
needsTruncation: true
|
|
};
|
|
}, [parts, maxVisibleParts]);
|
|
|
|
const showDriveDropdown = isWindowsPath && isLocal && !!onListDrives;
|
|
|
|
return (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<div className="flex items-center gap-1 text-xs text-muted-foreground overflow-hidden cursor-default">
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<button
|
|
onClick={onHome}
|
|
className="hover:text-foreground p-1 rounded hover:bg-secondary/60 shrink-0"
|
|
>
|
|
<Home size={12} />
|
|
</button>
|
|
</TooltipTrigger>
|
|
<TooltipContent>{t("sftp.goHome")}</TooltipContent>
|
|
</Tooltip>
|
|
<ChevronRight size={12} className="opacity-40 shrink-0" />
|
|
{visibleParts.map(({ part, originalIndex }, displayIdx) => {
|
|
const partPath = buildPath(originalIndex);
|
|
const isLast = originalIndex === parts.length - 1;
|
|
const showEllipsisBefore = needsTruncation && displayIdx === 1;
|
|
|
|
return (
|
|
<React.Fragment key={partPath}>
|
|
{showEllipsisBefore && (
|
|
<>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<span className="px-1 py-0.5 shrink-0 flex items-center text-muted-foreground cursor-default">
|
|
<MoreHorizontal size={14} />
|
|
</span>
|
|
</TooltipTrigger>
|
|
<TooltipContent>
|
|
{`${t("sftp.showHiddenPaths")}: ${hiddenParts.map(h => h.part).join(' > ')}`}
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
<ChevronRight size={12} className="opacity-40 shrink-0" />
|
|
</>
|
|
)}
|
|
{originalIndex === 0 && showDriveDropdown ? (
|
|
<Dropdown open={driveDropdownOpen} onOpenChange={handleDriveDropdownOpen}>
|
|
<DropdownTrigger asChild>
|
|
<button className="hover:text-foreground px-1 py-0.5 rounded hover:bg-secondary/60 shrink-0 flex items-center gap-0.5">
|
|
{part}
|
|
<ChevronDown size={10} className="opacity-60" />
|
|
</button>
|
|
</DropdownTrigger>
|
|
<DropdownContent align="start" className="w-16 p-1">
|
|
{drives.map(drive => (
|
|
<button
|
|
key={drive}
|
|
onClick={() => { onNavigate(drive + '\\'); setDriveDropdownOpen(false); }}
|
|
className={cn(
|
|
"w-full text-left px-2 py-1 text-xs rounded hover:bg-secondary/60",
|
|
drive === part && "bg-secondary font-medium"
|
|
)}
|
|
>
|
|
{drive}
|
|
</button>
|
|
))}
|
|
</DropdownContent>
|
|
</Dropdown>
|
|
) : (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<button
|
|
onClick={() => onNavigate(partPath)}
|
|
className={cn(
|
|
"hover:text-foreground px-1 py-0.5 rounded hover:bg-secondary/60 truncate max-w-[120px] shrink-0",
|
|
isLast && "text-foreground font-medium"
|
|
)}
|
|
>
|
|
{part}
|
|
</button>
|
|
</TooltipTrigger>
|
|
<TooltipContent>{part}</TooltipContent>
|
|
</Tooltip>
|
|
)}
|
|
{!isLast && <ChevronRight size={12} className="opacity-40 shrink-0" />}
|
|
</React.Fragment>
|
|
);
|
|
})}
|
|
</div>
|
|
</TooltipTrigger>
|
|
<TooltipContent>{path}</TooltipContent>
|
|
</Tooltip>
|
|
);
|
|
};
|
|
|
|
export const SftpBreadcrumb = memo(SftpBreadcrumbInner);
|
|
SftpBreadcrumb.displayName = 'SftpBreadcrumb';
|