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