Path: blob/main/src/vs/sessions/contrib/changes/browser/changesTitleBarWidget.ts
13401 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import './media/changesTitleBarWidget.css';67import { mainWindow } from '../../../../base/browser/window.js';8import { Codicon } from '../../../../base/common/codicons.js';9import { Disposable } from '../../../../base/common/lifecycle.js';10import { localize, localize2 } from '../../../../nls.js';11import { Action2, MenuRegistry, registerAction2 } from '../../../../platform/actions/common/actions.js';12import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';13import { ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js';14import { IWorkbenchContribution } from '../../../../workbench/common/contributions.js';15import { IsAuxiliaryWindowContext, AuxiliaryBarVisibleContext } from '../../../../workbench/common/contextkeys.js';16import { IWorkbenchLayoutService, Parts } from '../../../../workbench/services/layout/browser/layoutService.js';17import { IPaneCompositePartService } from '../../../../workbench/services/panecomposite/browser/panecomposite.js';18import { IEditorGroupsService } from '../../../../workbench/services/editor/common/editorGroupsService.js';19import { ITelemetryService } from '../../../../platform/telemetry/common/telemetry.js';20import { ViewContainerLocation } from '../../../../workbench/common/views.js';21import { registerIcon } from '../../../../platform/theme/common/iconRegistry.js';22import { Menus } from '../../../browser/menus.js';23import { SessionsWelcomeVisibleContext } from '../../../common/contextkeys.js';24import { logChangesViewToggle } from '../../../common/sessionsTelemetry.js';25import { CHANGES_VIEW_CONTAINER_ID } from '../common/changes.js';2627const TOGGLE_CHANGES_VIEW_ID = 'workbench.action.agentSessions.toggleChangesView';28const TOGGLE_SECONDARY_SIDEBAR_TOOLTIP = localize('toggleSecondarySidebarTooltip', "Toggle Secondary Side Bar Visibility");2930const secondarySidebarToggleClosedIcon = registerIcon('agent-secondary-sidebar-toggle-closed', Codicon.layoutSidebarRightOff, localize('agentSecondarySidebarToggleClosedIcon', "Icon for the sessions secondary sidebar when closed."));31const secondarySidebarToggleOpenIcon = registerIcon('agent-secondary-sidebar-toggle-open', Codicon.layoutSidebarRight, localize('agentSecondarySidebarToggleOpenIcon', "Icon for the sessions secondary sidebar when open."));3233/**34* Registers the Changes view toggle action in the titlebar session toolbar.35*/36export class ChangesTitleBarContribution extends Disposable implements IWorkbenchContribution {3738static readonly ID = 'workbench.contrib.changesTitleBar';3940constructor() {41super();4243// Register the toggle action in the session toolbar44this._register(MenuRegistry.appendMenuItem(Menus.TitleBarSessionMenu, {45command: {46id: TOGGLE_CHANGES_VIEW_ID,47title: localize2('showChanges', "Show Changes"),48tooltip: TOGGLE_SECONDARY_SIDEBAR_TOOLTIP,49icon: secondarySidebarToggleClosedIcon,50toggled: {51condition: AuxiliaryBarVisibleContext,52icon: secondarySidebarToggleOpenIcon,53title: localize('hideChanges', "Hide Changes"),54tooltip: TOGGLE_SECONDARY_SIDEBAR_TOOLTIP,55},56},57group: 'navigation',58order: 11, // After Open in VS Code (7), Run Script (8), and Open Terminal (10)59when: ContextKeyExpr.and(IsAuxiliaryWindowContext.toNegated(), SessionsWelcomeVisibleContext.toNegated()),60}));61}62}6364// Register the toggle action65registerAction2(class extends Action2 {66constructor() {67super({68id: TOGGLE_CHANGES_VIEW_ID,69title: localize2('showChanges', "Show Changes"),70tooltip: TOGGLE_SECONDARY_SIDEBAR_TOOLTIP,71icon: secondarySidebarToggleClosedIcon,72toggled: {73condition: AuxiliaryBarVisibleContext,74icon: secondarySidebarToggleOpenIcon,75title: localize('hideChanges', "Hide Changes"),76tooltip: TOGGLE_SECONDARY_SIDEBAR_TOOLTIP,77},78precondition: ContextKeyExpr.and(IsAuxiliaryWindowContext.toNegated(), SessionsWelcomeVisibleContext.toNegated()),79});80}8182run(accessor: ServicesAccessor): void {83const layoutService = accessor.get(IWorkbenchLayoutService);84const paneCompositeService = accessor.get(IPaneCompositePartService);85const editorGroupService = accessor.get(IEditorGroupsService);86const telemetryService = accessor.get(ITelemetryService);8788const isVisible = !layoutService.isVisible(Parts.AUXILIARYBAR_PART);8990if (isVisible) {91// Editor part92const hasEditors = editorGroupService.groups.some(group => !group.isEmpty);93if (hasEditors && !layoutService.isVisible(Parts.EDITOR_PART, mainWindow)) {94layoutService.setPartHidden(false, Parts.EDITOR_PART);95}9697// Auxiliary bar part98layoutService.setPartHidden(false, Parts.AUXILIARYBAR_PART);99paneCompositeService.openPaneComposite(CHANGES_VIEW_CONTAINER_ID, ViewContainerLocation.AuxiliaryBar);100} else {101layoutService.setPartHidden(true, Parts.EDITOR_PART);102layoutService.setPartHidden(true, Parts.AUXILIARYBAR_PART);103}104105logChangesViewToggle(telemetryService, isVisible);106}107});108109110