Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/notebook/browser/controller/layoutActions.ts
5248 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 { Codicon } from '../../../../../base/common/codicons.js';
7
import { DisposableStore } from '../../../../../base/common/lifecycle.js';
8
import { URI, UriComponents } from '../../../../../base/common/uri.js';
9
import { localize, localize2 } from '../../../../../nls.js';
10
import { Categories } from '../../../../../platform/action/common/actionCommonCategories.js';
11
import { Action2, MenuId, MenuRegistry, registerAction2 } from '../../../../../platform/actions/common/actions.js';
12
import { ICommandService } from '../../../../../platform/commands/common/commands.js';
13
import { ConfigurationTarget, IConfigurationService } from '../../../../../platform/configuration/common/configuration.js';
14
import { ContextKeyExpr } from '../../../../../platform/contextkey/common/contextkey.js';
15
import { ServicesAccessor } from '../../../../../platform/instantiation/common/instantiation.js';
16
import { IQuickInputService, IQuickPickItem } from '../../../../../platform/quickinput/common/quickInput.js';
17
import { NOTEBOOK_ACTIONS_CATEGORY } from './coreActions.js';
18
import { getNotebookEditorFromEditorPane } from '../notebookBrowser.js';
19
import { INotebookEditorService } from '../services/notebookEditorService.js';
20
import { NotebookSetting } from '../../common/notebookCommon.js';
21
import { NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_IS_ACTIVE_EDITOR } from '../../common/notebookContextKeys.js';
22
import { INotebookService } from '../../common/notebookService.js';
23
import { IEditorService } from '../../../../services/editor/common/editorService.js';
24
import { IPreferencesService } from '../../../../services/preferences/common/preferences.js';
25
26
registerAction2(class NotebookConfigureLayoutAction extends Action2 {
27
constructor() {
28
super({
29
id: 'workbench.notebook.layout.select',
30
title: localize2('workbench.notebook.layout.select.label', "Select between Notebook Layouts"),
31
f1: true,
32
precondition: ContextKeyExpr.equals(`config.${NotebookSetting.openGettingStarted}`, true),
33
category: NOTEBOOK_ACTIONS_CATEGORY,
34
menu: [
35
{
36
id: MenuId.EditorTitle,
37
group: 'notebookLayout',
38
when: ContextKeyExpr.and(
39
NOTEBOOK_IS_ACTIVE_EDITOR,
40
ContextKeyExpr.notEquals('config.notebook.globalToolbar', true),
41
ContextKeyExpr.equals(`config.${NotebookSetting.openGettingStarted}`, true)
42
),
43
order: 0
44
},
45
{
46
id: MenuId.NotebookToolbar,
47
group: 'notebookLayout',
48
when: ContextKeyExpr.and(
49
ContextKeyExpr.equals('config.notebook.globalToolbar', true),
50
ContextKeyExpr.equals(`config.${NotebookSetting.openGettingStarted}`, true)
51
),
52
order: 0
53
}
54
]
55
});
56
}
57
run(accessor: ServicesAccessor): void {
58
accessor.get(ICommandService).executeCommand('workbench.action.openWalkthrough', { category: 'notebooks', step: 'notebookProfile' }, true);
59
}
60
});
61
62
registerAction2(class NotebookConfigureLayoutAction extends Action2 {
63
constructor() {
64
super({
65
id: 'workbench.notebook.layout.configure',
66
title: localize2('workbench.notebook.layout.configure.label', "Customize Notebook Layout"),
67
f1: true,
68
category: NOTEBOOK_ACTIONS_CATEGORY,
69
menu: [
70
{
71
id: MenuId.NotebookToolbar,
72
group: 'notebookLayout',
73
when: ContextKeyExpr.equals('config.notebook.globalToolbar', true),
74
order: 1
75
}
76
]
77
});
78
}
79
run(accessor: ServicesAccessor): void {
80
accessor.get(IPreferencesService).openSettings({ jsonEditor: false, query: '@tag:notebookLayout' });
81
}
82
});
83
84
registerAction2(class NotebookConfigureLayoutFromEditorTitle extends Action2 {
85
constructor() {
86
super({
87
id: 'workbench.notebook.layout.configure.editorTitle',
88
title: localize2('workbench.notebook.layout.configure.label', "Customize Notebook Layout"),
89
f1: false,
90
category: NOTEBOOK_ACTIONS_CATEGORY,
91
menu: [
92
{
93
id: MenuId.NotebookEditorLayoutConfigure,
94
group: 'notebookLayout',
95
when: NOTEBOOK_IS_ACTIVE_EDITOR,
96
order: 1
97
}
98
]
99
});
100
}
101
run(accessor: ServicesAccessor): void {
102
accessor.get(IPreferencesService).openSettings({ jsonEditor: false, query: '@tag:notebookLayout' });
103
}
104
});
105
106
MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
107
submenu: MenuId.NotebookEditorLayoutConfigure,
108
title: localize2('customizeNotebook', "Customize Notebook..."),
109
icon: Codicon.gear,
110
group: 'navigation',
111
order: -1,
112
when: NOTEBOOK_IS_ACTIVE_EDITOR
113
});
114
115
registerAction2(class ToggleLineNumberFromEditorTitle extends Action2 {
116
constructor() {
117
super({
118
id: 'notebook.toggleLineNumbersFromEditorTitle',
119
title: localize2('notebook.toggleLineNumbers', 'Toggle Notebook Line Numbers'),
120
shortTitle: localize2('notebook.toggleLineNumbers.short', 'Line Numbers'),
121
precondition: NOTEBOOK_EDITOR_FOCUSED,
122
menu: [
123
{
124
id: MenuId.NotebookEditorLayoutConfigure,
125
group: 'notebookLayoutDetails',
126
order: 1,
127
when: NOTEBOOK_IS_ACTIVE_EDITOR
128
}],
129
category: NOTEBOOK_ACTIONS_CATEGORY,
130
f1: true,
131
toggled: {
132
condition: ContextKeyExpr.notEquals('config.notebook.lineNumbers', 'off'),
133
title: localize('notebook.showLineNumbers', "Line Numbers"),
134
}
135
});
136
}
137
138
async run(accessor: ServicesAccessor): Promise<void> {
139
return accessor.get(ICommandService).executeCommand('notebook.toggleLineNumbers');
140
}
141
});
142
143
registerAction2(class ToggleCellToolbarPositionFromEditorTitle extends Action2 {
144
constructor() {
145
super({
146
id: 'notebook.toggleCellToolbarPositionFromEditorTitle',
147
title: localize2('notebook.toggleCellToolbarPosition', 'Toggle Cell Toolbar Position'),
148
menu: [{
149
id: MenuId.NotebookEditorLayoutConfigure,
150
group: 'notebookLayoutDetails',
151
order: 3
152
}],
153
category: NOTEBOOK_ACTIONS_CATEGORY,
154
f1: false
155
});
156
}
157
158
async run(accessor: ServicesAccessor, ...args: unknown[]): Promise<void> {
159
return accessor.get(ICommandService).executeCommand('notebook.toggleCellToolbarPosition', ...args);
160
}
161
});
162
163
registerAction2(class ToggleBreadcrumbFromEditorTitle extends Action2 {
164
constructor() {
165
super({
166
id: 'breadcrumbs.toggleFromEditorTitle',
167
title: localize2('notebook.toggleBreadcrumb', 'Toggle Breadcrumbs'),
168
shortTitle: localize2('notebook.toggleBreadcrumb.short', 'Breadcrumbs'),
169
toggled: {
170
condition: ContextKeyExpr.equals('config.breadcrumbs.enabled', true),
171
title: localize('cmd.toggle2', "Breadcrumbs")
172
},
173
menu: [{
174
id: MenuId.NotebookEditorLayoutConfigure,
175
group: 'notebookLayoutDetails',
176
order: 2
177
}],
178
category: NOTEBOOK_ACTIONS_CATEGORY,
179
f1: false
180
});
181
}
182
183
async run(accessor: ServicesAccessor): Promise<void> {
184
return accessor.get(ICommandService).executeCommand('breadcrumbs.toggle');
185
}
186
});
187
188
registerAction2(class SaveMimeTypeDisplayOrder extends Action2 {
189
constructor() {
190
super({
191
id: 'notebook.saveMimeTypeOrder',
192
title: localize2('notebook.saveMimeTypeOrder', "Save Mimetype Display Order"),
193
f1: true,
194
category: NOTEBOOK_ACTIONS_CATEGORY,
195
precondition: NOTEBOOK_IS_ACTIVE_EDITOR,
196
});
197
}
198
199
run(accessor: ServicesAccessor) {
200
const service = accessor.get(INotebookService);
201
const disposables = new DisposableStore();
202
const qp = disposables.add(accessor.get(IQuickInputService).createQuickPick<IQuickPickItem & { target: ConfigurationTarget }>());
203
qp.placeholder = localize('notebook.placeholder', 'Settings file to save in');
204
qp.items = [
205
{ target: ConfigurationTarget.USER, label: localize('saveTarget.machine', 'User Settings') },
206
{ target: ConfigurationTarget.WORKSPACE, label: localize('saveTarget.workspace', 'Workspace Settings') },
207
];
208
209
disposables.add(qp.onDidAccept(() => {
210
const target = qp.selectedItems[0]?.target;
211
if (target !== undefined) {
212
service.saveMimeDisplayOrder(target);
213
}
214
qp.dispose();
215
}));
216
217
disposables.add(qp.onDidHide(() => disposables.dispose()));
218
219
qp.show();
220
}
221
});
222
223
registerAction2(class NotebookWebviewResetAction extends Action2 {
224
constructor() {
225
super({
226
id: 'workbench.notebook.layout.webview.reset',
227
title: localize2('workbench.notebook.layout.webview.reset.label', "Reset Notebook Webview"),
228
f1: false,
229
category: NOTEBOOK_ACTIONS_CATEGORY
230
});
231
}
232
run(accessor: ServicesAccessor, args?: UriComponents): void {
233
const editorService = accessor.get(IEditorService);
234
235
if (args) {
236
const uri = URI.revive(args);
237
const notebookEditorService = accessor.get(INotebookEditorService);
238
const widgets = notebookEditorService.listNotebookEditors().filter(widget => widget.hasModel() && widget.textModel.uri.toString() === uri.toString());
239
for (const widget of widgets) {
240
if (widget.hasModel()) {
241
widget.getInnerWebview()?.reload();
242
}
243
}
244
} else {
245
const editor = getNotebookEditorFromEditorPane(editorService.activeEditorPane);
246
if (!editor) {
247
return;
248
}
249
250
editor.getInnerWebview()?.reload();
251
}
252
}
253
});
254
255
registerAction2(class ToggleNotebookStickyScroll extends Action2 {
256
constructor() {
257
super({
258
id: 'notebook.action.toggleNotebookStickyScroll',
259
title: {
260
...localize2('toggleStickyScroll', "Toggle Notebook Sticky Scroll"),
261
mnemonicTitle: localize({ key: 'mitoggleNotebookStickyScroll', comment: ['&& denotes a mnemonic'] }, "&&Sticky Scroll"),
262
},
263
shortTitle: localize2('toggleStickyScroll.short', "Sticky Scroll"),
264
category: Categories.View,
265
toggled: {
266
condition: ContextKeyExpr.equals('config.notebook.stickyScroll.enabled', true),
267
title: localize('notebookStickyScroll', "Sticky Scroll"),
268
mnemonicTitle: localize({ key: 'mitoggleNotebookStickyScroll', comment: ['&& denotes a mnemonic'] }, "&&Sticky Scroll"),
269
},
270
menu: [
271
{ id: MenuId.CommandPalette },
272
{ id: MenuId.NotebookStickyScrollContext, group: 'notebookView', order: 2 },
273
{ id: MenuId.NotebookToolbarContext, group: 'notebookView', order: 2 }
274
]
275
});
276
}
277
278
override async run(accessor: ServicesAccessor): Promise<void> {
279
const configurationService = accessor.get(IConfigurationService);
280
const newValue = !configurationService.getValue('notebook.stickyScroll.enabled');
281
return configurationService.updateValue('notebook.stickyScroll.enabled', newValue);
282
}
283
});
284
285