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
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 { 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
rememberDefaultAction: false,
109
title: localize2('customizeNotebook', "Customize Notebook..."),
110
icon: Codicon.gear,
111
group: 'navigation',
112
order: -1,
113
when: NOTEBOOK_IS_ACTIVE_EDITOR
114
});
115
116
registerAction2(class ToggleLineNumberFromEditorTitle extends Action2 {
117
constructor() {
118
super({
119
id: 'notebook.toggleLineNumbersFromEditorTitle',
120
title: localize2('notebook.toggleLineNumbers', 'Toggle Notebook 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', "Notebook 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: any[]): 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
menu: [{
169
id: MenuId.NotebookEditorLayoutConfigure,
170
group: 'notebookLayoutDetails',
171
order: 2
172
}],
173
f1: false
174
});
175
}
176
177
async run(accessor: ServicesAccessor): Promise<void> {
178
return accessor.get(ICommandService).executeCommand('breadcrumbs.toggle');
179
}
180
});
181
182
registerAction2(class SaveMimeTypeDisplayOrder extends Action2 {
183
constructor() {
184
super({
185
id: 'notebook.saveMimeTypeOrder',
186
title: localize2('notebook.saveMimeTypeOrder', "Save Mimetype Display Order"),
187
f1: true,
188
category: NOTEBOOK_ACTIONS_CATEGORY,
189
precondition: NOTEBOOK_IS_ACTIVE_EDITOR,
190
});
191
}
192
193
run(accessor: ServicesAccessor) {
194
const service = accessor.get(INotebookService);
195
const disposables = new DisposableStore();
196
const qp = disposables.add(accessor.get(IQuickInputService).createQuickPick<IQuickPickItem & { target: ConfigurationTarget }>());
197
qp.placeholder = localize('notebook.placeholder', 'Settings file to save in');
198
qp.items = [
199
{ target: ConfigurationTarget.USER, label: localize('saveTarget.machine', 'User Settings') },
200
{ target: ConfigurationTarget.WORKSPACE, label: localize('saveTarget.workspace', 'Workspace Settings') },
201
];
202
203
disposables.add(qp.onDidAccept(() => {
204
const target = qp.selectedItems[0]?.target;
205
if (target !== undefined) {
206
service.saveMimeDisplayOrder(target);
207
}
208
qp.dispose();
209
}));
210
211
disposables.add(qp.onDidHide(() => disposables.dispose()));
212
213
qp.show();
214
}
215
});
216
217
registerAction2(class NotebookWebviewResetAction extends Action2 {
218
constructor() {
219
super({
220
id: 'workbench.notebook.layout.webview.reset',
221
title: localize2('workbench.notebook.layout.webview.reset.label', "Reset Notebook Webview"),
222
f1: false,
223
category: NOTEBOOK_ACTIONS_CATEGORY
224
});
225
}
226
run(accessor: ServicesAccessor, args?: UriComponents): void {
227
const editorService = accessor.get(IEditorService);
228
229
if (args) {
230
const uri = URI.revive(args);
231
const notebookEditorService = accessor.get(INotebookEditorService);
232
const widgets = notebookEditorService.listNotebookEditors().filter(widget => widget.hasModel() && widget.textModel.uri.toString() === uri.toString());
233
for (const widget of widgets) {
234
if (widget.hasModel()) {
235
widget.getInnerWebview()?.reload();
236
}
237
}
238
} else {
239
const editor = getNotebookEditorFromEditorPane(editorService.activeEditorPane);
240
if (!editor) {
241
return;
242
}
243
244
editor.getInnerWebview()?.reload();
245
}
246
}
247
});
248
249
registerAction2(class ToggleNotebookStickyScroll extends Action2 {
250
constructor() {
251
super({
252
id: 'notebook.action.toggleNotebookStickyScroll',
253
title: {
254
...localize2('toggleStickyScroll', "Toggle Notebook Sticky Scroll"),
255
mnemonicTitle: localize({ key: 'mitoggleNotebookStickyScroll', comment: ['&& denotes a mnemonic'] }, "&&Toggle Notebook Sticky Scroll"),
256
},
257
category: Categories.View,
258
toggled: {
259
condition: ContextKeyExpr.equals('config.notebook.stickyScroll.enabled', true),
260
title: localize('notebookStickyScroll', "Toggle Notebook Sticky Scroll"),
261
mnemonicTitle: localize({ key: 'mitoggleNotebookStickyScroll', comment: ['&& denotes a mnemonic'] }, "&&Toggle Notebook Sticky Scroll"),
262
},
263
menu: [
264
{ id: MenuId.CommandPalette },
265
{ id: MenuId.NotebookStickyScrollContext, group: 'notebookView', order: 2 },
266
{ id: MenuId.NotebookToolbarContext, group: 'notebookView', order: 2 }
267
]
268
});
269
}
270
271
override async run(accessor: ServicesAccessor): Promise<void> {
272
const configurationService = accessor.get(IConfigurationService);
273
const newValue = !configurationService.getValue('notebook.stickyScroll.enabled');
274
return configurationService.updateValue('notebook.stickyScroll.enabled', newValue);
275
}
276
});
277
278