/** * Tab bar for the project editor. * Shows open files as tabs with dirty indicator (dot) and close button. */ import { Tooltip, TooltipContent, TooltipTrigger } from '@renderer/components/ui/tooltip'; import { useStore } from '@renderer/store'; import { X } from 'lucide-react'; import { getFileIcon } from './fileIcons'; import type { EditorFileTab } from '@shared/types/editor'; // ============================================================================= // Types // ============================================================================= interface EditorTabBarProps { /** Called instead of direct closeTab — allows parent to intercept dirty tabs */ onRequestCloseTab: (tabId: string) => void; } // ============================================================================= // Component // ============================================================================= export const EditorTabBar = ({ onRequestCloseTab, }: EditorTabBarProps): React.ReactElement | null => { const tabs = useStore((s) => s.editorOpenTabs); const activeTabId = useStore((s) => s.editorActiveTabId); const modifiedFiles = useStore((s) => s.editorModifiedFiles); const setActiveEditorTab = useStore((s) => s.setActiveEditorTab); if (tabs.length === 0) return null; return (
{tabs.map((tab) => ( setActiveEditorTab(tab.id)} onClose={() => onRequestCloseTab(tab.id)} /> ))}
); }; // ============================================================================= // Tab item // ============================================================================= interface TabProps { tab: EditorFileTab; isActive: boolean; isModified: boolean; onActivate: () => void; onClose: () => void; } const Tab = ({ tab, isActive, isModified, onActivate, onClose }: TabProps): React.ReactElement => { const handleClose = (e: React.MouseEvent) => { e.stopPropagation(); onClose(); }; const handleAuxClick = (e: React.MouseEvent) => { if (e.button === 1) { e.preventDefault(); onClose(); } }; const iconInfo = getFileIcon(tab.fileName); const FileIcon = iconInfo.icon; return ( {tab.filePath} ); };