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