reimplement closetab context menu

This commit is contained in:
sawka 2024-06-24 17:50:06 -07:00
parent 997940949a
commit b2e12e4171
2 changed files with 12 additions and 3 deletions

View File

@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import { Button } from "@/element/button"; import { Button } from "@/element/button";
import { ContextMenuModel } from "@/store/contextmenu";
import * as services from "@/store/services"; import * as services from "@/store/services";
import * as WOS from "@/store/wos"; import * as WOS from "@/store/wos";
import { clsx } from "clsx"; import { clsx } from "clsx";
@ -16,7 +17,7 @@ interface TabProps {
isBeforeActive: boolean; isBeforeActive: boolean;
isDragging: boolean; isDragging: boolean;
onSelect: () => void; onSelect: () => void;
onClose: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void; onClose: (event: React.MouseEvent<HTMLButtonElement, MouseEvent> | null) => void;
onDragStart: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void; onDragStart: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
onLoaded: () => void; onLoaded: () => void;
} }
@ -106,12 +107,20 @@ const Tab = forwardRef<HTMLDivElement, TabProps>(
event.stopPropagation(); event.stopPropagation();
}; };
function handleContextMenu(e: React.MouseEvent<HTMLDivElement, MouseEvent>) {
e.preventDefault();
let menu: ContextMenuItem[] = [];
menu.push({ label: "Close Tab", click: () => onClose(null) });
ContextMenuModel.showContextMenu(menu, e);
}
return ( return (
<div <div
ref={ref} ref={ref}
className={clsx("tab", { active, isDragging, "before-active": isBeforeActive })} className={clsx("tab", { active, isDragging, "before-active": isBeforeActive })}
onMouseDown={onDragStart} onMouseDown={onDragStart}
onClick={onSelect} onClick={onSelect}
onContextMenu={handleContextMenu}
data-tab-id={id} data-tab-id={id}
> >
{isFirst && <div className="vertical-line first" />} {isFirst && <div className="vertical-line first" />}

View File

@ -447,8 +447,8 @@ const TabBar = ({ workspace }: TabBarProps) => {
}, 30); }, 30);
}; };
const handleCloseTab = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>, tabId: string) => { const handleCloseTab = (event: React.MouseEvent<HTMLButtonElement, MouseEvent> | null, tabId: string) => {
event.stopPropagation(); event?.stopPropagation();
services.WindowService.CloseTab(tabId); services.WindowService.CloseTab(tabId);
deleteLayoutStateAtomForTab(tabId); deleteLayoutStateAtomForTab(tabId);
}; };