diff --git a/src/vs/sessions/contrib/sessions/browser/sessionsTitleBarWidget.ts b/src/vs/sessions/contrib/sessions/browser/sessionsTitleBarWidget.ts index 6ff448786dde75..f2a3198b33beaa 100644 --- a/src/vs/sessions/contrib/sessions/browser/sessionsTitleBarWidget.ts +++ b/src/vs/sessions/contrib/sessions/browser/sessionsTitleBarWidget.ts @@ -4,16 +4,23 @@ *--------------------------------------------------------------------------------------------*/ import './media/sessionsTitleBarWidget.css'; -import { $, addDisposableListener, EventType, reset } from '../../../../base/browser/dom.js'; +import { $, addDisposableListener, EventType, getActiveWindow, reset } from '../../../../base/browser/dom.js'; +import { Separator } from '../../../../base/common/actions.js'; import { Disposable, DisposableStore, MutableDisposable } from '../../../../base/common/lifecycle.js'; +import { MarshalledId } from '../../../../base/common/marshallingIds.js'; +import { StandardMouseEvent } from '../../../../base/browser/mouseEvent.js'; import { localize } from '../../../../nls.js'; import { IHoverService } from '../../../../platform/hover/browser/hover.js'; import { getDefaultHoverDelegate } from '../../../../base/browser/ui/hover/hoverDelegateFactory.js'; import { BaseActionViewItem, IBaseActionViewItemOptions } from '../../../../base/browser/ui/actionbar/actionViewItems.js'; import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js'; -import { MenuRegistry, SubmenuItemAction } from '../../../../platform/actions/common/actions.js'; -import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js'; +import { IMenuService, MenuId, MenuRegistry, SubmenuItemAction } from '../../../../platform/actions/common/actions.js'; +import { IContextKeyService, ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js'; +import { IContextMenuService } from '../../../../platform/contextview/browser/contextView.js'; +import { ChatContextKeys } from '../../../../workbench/contrib/chat/common/actions/chatContextKeys.js'; +import { IMarshalledAgentSessionContext } from '../../../../workbench/contrib/chat/browser/agentSessions/agentSessionsModel.js'; +import { IChatSessionsService } from '../../../../workbench/contrib/chat/common/chatSessionsService.js'; import { Menus } from '../../../browser/menus.js'; import { IWorkbenchContribution } from '../../../../workbench/common/contributions.js'; @@ -65,6 +72,10 @@ export class SessionsTitleBarWidget extends BaseActionViewItem { @ISessionsManagementService private readonly activeSessionService: ISessionsManagementService, @IChatService private readonly chatService: IChatService, @IAgentSessionsService private readonly agentSessionsService: IAgentSessionsService, + @IContextMenuService private readonly contextMenuService: IContextMenuService, + @IMenuService private readonly menuService: IMenuService, + @IContextKeyService private readonly contextKeyService: IContextKeyService, + @IChatSessionsService private readonly chatSessionsService: IChatSessionsService, ) { super(undefined, action, options); @@ -176,6 +187,11 @@ export class SessionsTitleBarWidget extends BaseActionViewItem { e.stopPropagation(); this._showSessionsPicker(); })); + this._dynamicDisposables.add(addDisposableListener(sessionPill, EventType.CONTEXT_MENU, (e) => { + e.preventDefault(); + e.stopPropagation(); + this._showContextMenu(e); + })); this._container.appendChild(sessionPill); @@ -284,6 +300,42 @@ export class SessionsTitleBarWidget extends BaseActionViewItem { return basename(uri); } + private _showContextMenu(e: MouseEvent): void { + const activeSession = this.activeSessionService.getActiveSession(); + if (!activeSession) { + return; + } + + const agentSession = this.agentSessionsService.getSession(activeSession.resource); + if (!agentSession) { + return; + } + + this.chatSessionsService.activateChatSessionItemProvider(agentSession.providerType); + + const contextOverlay: Array<[string, boolean | string]> = [ + [ChatContextKeys.isArchivedAgentSession.key, agentSession.isArchived()], + [ChatContextKeys.isReadAgentSession.key, agentSession.isRead()], + [ChatContextKeys.agentSessionType.key, agentSession.providerType], + ]; + + const menu = this.menuService.createMenu(MenuId.AgentSessionsContext, this.contextKeyService.createOverlay(contextOverlay)); + + const marshalledContext: IMarshalledAgentSessionContext = { + session: agentSession, + sessions: [agentSession], + $mid: MarshalledId.AgentSessionContext, + }; + + this.contextMenuService.showContextMenu({ + getActions: () => Separator.join(...menu.getActions({ arg: marshalledContext, shouldForwardArgs: true }).map(([, actions]) => actions)), + getAnchor: () => new StandardMouseEvent(getActiveWindow(), e), + getActionsContext: () => marshalledContext + }); + + menu.dispose(); + } + private _showSessionsPicker(): void { const picker = this.instantiationService.createInstance(AgentSessionsPicker, undefined, { overrideSessionOpen: (session, openOptions) => this.activeSessionService.openSession(session.resource, openOptions)