Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/browser/parts/titlebar/titlebarActions.ts
3296 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 { ILocalizedString, localize, localize2 } from '../../../../nls.js';
7
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
8
import { ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js';
9
import { IStorageService, StorageScope, StorageTarget } from '../../../../platform/storage/common/storage.js';
10
import { LayoutSettings } from '../../../services/layout/browser/layoutService.js';
11
import { Action2, MenuId, registerAction2 } from '../../../../platform/actions/common/actions.js';
12
import { ContextKeyExpr, ContextKeyExpression, IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js';
13
import { ACCOUNTS_ACTIVITY_ID, GLOBAL_ACTIVITY_ID } from '../../../common/activity.js';
14
import { IAction } from '../../../../base/common/actions.js';
15
import { IsMainWindowFullscreenContext, IsCompactTitleBarContext, TitleBarStyleContext, TitleBarVisibleContext } from '../../../common/contextkeys.js';
16
import { CustomTitleBarVisibility, TitleBarSetting, TitlebarStyle } from '../../../../platform/window/common/window.js';
17
18
// --- Context Menu Actions --- //
19
20
export class ToggleTitleBarConfigAction extends Action2 {
21
22
constructor(private readonly section: string, title: string, description: string | ILocalizedString | undefined, order: number, when?: ContextKeyExpression) {
23
24
super({
25
id: `toggle.${section}`,
26
title,
27
metadata: description ? { description } : undefined,
28
toggled: ContextKeyExpr.equals(`config.${section}`, true),
29
menu: [
30
{
31
id: MenuId.TitleBarContext,
32
when,
33
order,
34
group: '2_config'
35
},
36
{
37
id: MenuId.TitleBarTitleContext,
38
when,
39
order,
40
group: '2_config'
41
}
42
]
43
});
44
}
45
46
run(accessor: ServicesAccessor, ...args: any[]): void {
47
const configService = accessor.get(IConfigurationService);
48
const value = configService.getValue(this.section);
49
configService.updateValue(this.section, !value);
50
}
51
}
52
53
registerAction2(class ToggleCommandCenter extends ToggleTitleBarConfigAction {
54
constructor() {
55
super(LayoutSettings.COMMAND_CENTER, localize('toggle.commandCenter', 'Command Center'), localize('toggle.commandCenterDescription', "Toggle visibility of the Command Center in title bar"), 1, IsCompactTitleBarContext.toNegated());
56
}
57
});
58
59
registerAction2(class ToggleNavigationControl extends ToggleTitleBarConfigAction {
60
constructor() {
61
super('workbench.navigationControl.enabled', localize('toggle.navigation', 'Navigation Controls'), localize('toggle.navigationDescription', "Toggle visibility of the Navigation Controls in title bar"), 2, ContextKeyExpr.and(IsCompactTitleBarContext.toNegated(), ContextKeyExpr.has('config.window.commandCenter')));
62
}
63
});
64
65
registerAction2(class ToggleLayoutControl extends ToggleTitleBarConfigAction {
66
constructor() {
67
super(LayoutSettings.LAYOUT_ACTIONS, localize('toggle.layout', 'Layout Controls'), localize('toggle.layoutDescription', "Toggle visibility of the Layout Controls in title bar"), 4);
68
}
69
});
70
71
registerAction2(class ToggleCustomTitleBar extends Action2 {
72
constructor() {
73
super({
74
id: `toggle.${TitleBarSetting.CUSTOM_TITLE_BAR_VISIBILITY}`,
75
title: localize('toggle.hideCustomTitleBar', 'Hide Custom Title Bar'),
76
menu: [
77
{ id: MenuId.TitleBarContext, order: 0, when: ContextKeyExpr.equals(TitleBarStyleContext.key, TitlebarStyle.NATIVE), group: '3_toggle' },
78
{ id: MenuId.TitleBarTitleContext, order: 0, when: ContextKeyExpr.equals(TitleBarStyleContext.key, TitlebarStyle.NATIVE), group: '3_toggle' },
79
]
80
});
81
}
82
83
run(accessor: ServicesAccessor, ...args: any[]): void {
84
const configService = accessor.get(IConfigurationService);
85
configService.updateValue(TitleBarSetting.CUSTOM_TITLE_BAR_VISIBILITY, CustomTitleBarVisibility.NEVER);
86
}
87
});
88
89
registerAction2(class ToggleCustomTitleBarWindowed extends Action2 {
90
constructor() {
91
super({
92
id: `toggle.${TitleBarSetting.CUSTOM_TITLE_BAR_VISIBILITY}.windowed`,
93
title: localize('toggle.hideCustomTitleBarInFullScreen', 'Hide Custom Title Bar In Full Screen'),
94
menu: [
95
{ id: MenuId.TitleBarContext, order: 1, when: IsMainWindowFullscreenContext, group: '3_toggle' },
96
{ id: MenuId.TitleBarTitleContext, order: 1, when: IsMainWindowFullscreenContext, group: '3_toggle' },
97
]
98
});
99
}
100
101
run(accessor: ServicesAccessor, ...args: any[]): void {
102
const configService = accessor.get(IConfigurationService);
103
configService.updateValue(TitleBarSetting.CUSTOM_TITLE_BAR_VISIBILITY, CustomTitleBarVisibility.WINDOWED);
104
}
105
});
106
107
class ToggleCustomTitleBar extends Action2 {
108
109
constructor() {
110
super({
111
id: `toggle.toggleCustomTitleBar`,
112
title: localize('toggle.customTitleBar', 'Custom Title Bar'),
113
toggled: TitleBarVisibleContext,
114
menu: [
115
{
116
id: MenuId.MenubarAppearanceMenu,
117
order: 6,
118
when: ContextKeyExpr.or(
119
ContextKeyExpr.and(
120
ContextKeyExpr.equals(TitleBarStyleContext.key, TitlebarStyle.NATIVE),
121
ContextKeyExpr.and(
122
ContextKeyExpr.equals('config.workbench.layoutControl.enabled', false),
123
ContextKeyExpr.equals('config.window.commandCenter', false),
124
ContextKeyExpr.notEquals('config.workbench.editor.editorActionsLocation', 'titleBar'),
125
ContextKeyExpr.notEquals('config.workbench.activityBar.location', 'top'),
126
ContextKeyExpr.notEquals('config.workbench.activityBar.location', 'bottom')
127
)?.negate()
128
),
129
IsMainWindowFullscreenContext
130
),
131
group: '2_workbench_layout'
132
},
133
],
134
});
135
}
136
137
run(accessor: ServicesAccessor, ...args: any[]): void {
138
const configService = accessor.get(IConfigurationService);
139
const contextKeyService = accessor.get(IContextKeyService);
140
const titleBarVisibility = configService.getValue<CustomTitleBarVisibility>(TitleBarSetting.CUSTOM_TITLE_BAR_VISIBILITY);
141
switch (titleBarVisibility) {
142
case CustomTitleBarVisibility.NEVER:
143
configService.updateValue(TitleBarSetting.CUSTOM_TITLE_BAR_VISIBILITY, CustomTitleBarVisibility.AUTO);
144
break;
145
case CustomTitleBarVisibility.WINDOWED: {
146
const isFullScreen = IsMainWindowFullscreenContext.evaluate(contextKeyService.getContext(null));
147
if (isFullScreen) {
148
configService.updateValue(TitleBarSetting.CUSTOM_TITLE_BAR_VISIBILITY, CustomTitleBarVisibility.AUTO);
149
} else {
150
configService.updateValue(TitleBarSetting.CUSTOM_TITLE_BAR_VISIBILITY, CustomTitleBarVisibility.NEVER);
151
}
152
break;
153
}
154
case CustomTitleBarVisibility.AUTO:
155
default:
156
configService.updateValue(TitleBarSetting.CUSTOM_TITLE_BAR_VISIBILITY, CustomTitleBarVisibility.NEVER);
157
break;
158
}
159
}
160
}
161
registerAction2(ToggleCustomTitleBar);
162
163
registerAction2(class ShowCustomTitleBar extends Action2 {
164
constructor() {
165
super({
166
id: `showCustomTitleBar`,
167
title: localize2('showCustomTitleBar', "Show Custom Title Bar"),
168
precondition: TitleBarVisibleContext.negate(),
169
f1: true
170
});
171
}
172
173
run(accessor: ServicesAccessor, ...args: any[]): void {
174
const configService = accessor.get(IConfigurationService);
175
configService.updateValue(TitleBarSetting.CUSTOM_TITLE_BAR_VISIBILITY, CustomTitleBarVisibility.AUTO);
176
}
177
});
178
179
registerAction2(class HideCustomTitleBar extends Action2 {
180
constructor() {
181
super({
182
id: `hideCustomTitleBar`,
183
title: localize2('hideCustomTitleBar', "Hide Custom Title Bar"),
184
precondition: TitleBarVisibleContext,
185
f1: true
186
});
187
}
188
189
run(accessor: ServicesAccessor, ...args: any[]): void {
190
const configService = accessor.get(IConfigurationService);
191
configService.updateValue(TitleBarSetting.CUSTOM_TITLE_BAR_VISIBILITY, CustomTitleBarVisibility.NEVER);
192
}
193
});
194
195
registerAction2(class HideCustomTitleBar extends Action2 {
196
constructor() {
197
super({
198
id: `hideCustomTitleBarInFullScreen`,
199
title: localize2('hideCustomTitleBarInFullScreen', "Hide Custom Title Bar In Full Screen"),
200
precondition: ContextKeyExpr.and(TitleBarVisibleContext, IsMainWindowFullscreenContext),
201
f1: true
202
});
203
}
204
205
run(accessor: ServicesAccessor, ...args: any[]): void {
206
const configService = accessor.get(IConfigurationService);
207
configService.updateValue(TitleBarSetting.CUSTOM_TITLE_BAR_VISIBILITY, CustomTitleBarVisibility.WINDOWED);
208
}
209
});
210
211
registerAction2(class ToggleEditorActions extends Action2 {
212
static readonly settingsID = `workbench.editor.editorActionsLocation`;
213
constructor() {
214
215
const titleBarContextCondition = ContextKeyExpr.and(
216
ContextKeyExpr.equals(`config.workbench.editor.showTabs`, 'none').negate(),
217
ContextKeyExpr.equals(`config.${ToggleEditorActions.settingsID}`, 'default'),
218
)?.negate();
219
220
super({
221
id: `toggle.${ToggleEditorActions.settingsID}`,
222
title: localize('toggle.editorActions', 'Editor Actions'),
223
toggled: ContextKeyExpr.equals(`config.${ToggleEditorActions.settingsID}`, 'hidden').negate(),
224
menu: [
225
{ id: MenuId.TitleBarContext, order: 3, when: titleBarContextCondition, group: '2_config' },
226
{ id: MenuId.TitleBarTitleContext, order: 3, when: titleBarContextCondition, group: '2_config' }
227
]
228
});
229
}
230
231
run(accessor: ServicesAccessor, ...args: any[]): void {
232
const configService = accessor.get(IConfigurationService);
233
const storageService = accessor.get(IStorageService);
234
235
const location = configService.getValue<string>(ToggleEditorActions.settingsID);
236
if (location === 'hidden') {
237
const showTabs = configService.getValue<string>(LayoutSettings.EDITOR_TABS_MODE);
238
239
// If tabs are visible, then set the editor actions to be in the title bar
240
if (showTabs !== 'none') {
241
configService.updateValue(ToggleEditorActions.settingsID, 'titleBar');
242
}
243
244
// If tabs are not visible, then set the editor actions to the last location the were before being hidden
245
else {
246
const storedValue = storageService.get(ToggleEditorActions.settingsID, StorageScope.PROFILE);
247
configService.updateValue(ToggleEditorActions.settingsID, storedValue ?? 'default');
248
}
249
250
storageService.remove(ToggleEditorActions.settingsID, StorageScope.PROFILE);
251
}
252
// Store the current value (titleBar or default) in the storage service for later to restore
253
else {
254
configService.updateValue(ToggleEditorActions.settingsID, 'hidden');
255
storageService.store(ToggleEditorActions.settingsID, location, StorageScope.PROFILE, StorageTarget.USER);
256
}
257
}
258
});
259
260
// --- Toolbar actions --- //
261
262
export const ACCOUNTS_ACTIVITY_TILE_ACTION: IAction = {
263
id: ACCOUNTS_ACTIVITY_ID,
264
label: localize('accounts', "Accounts"),
265
tooltip: localize('accounts', "Accounts"),
266
class: undefined,
267
enabled: true,
268
run: function (): void { }
269
};
270
271
export const GLOBAL_ACTIVITY_TITLE_ACTION: IAction = {
272
id: GLOBAL_ACTIVITY_ID,
273
label: localize('manage', "Manage"),
274
tooltip: localize('manage', "Manage"),
275
class: undefined,
276
enabled: true,
277
run: function (): void { }
278
};
279
280