diff --git a/packages/notebook-extension/schema/full-width-notebook.json b/packages/notebook-extension/schema/full-width-notebook.json index 50e5cb9237..03189ce2fa 100644 --- a/packages/notebook-extension/schema/full-width-notebook.json +++ b/packages/notebook-extension/schema/full-width-notebook.json @@ -1,6 +1,19 @@ { - "title": "Jupyter Notebook Width Settings", - "description": "Jupyter Notebook Width Settings", + "title": "Jupyter Notebook Full Width Notebook", + "description": "Jupyter Notebook Notebook With settings", + "jupyter.lab.menus": { + "main": [ + { + "id": "jp-mainmenu-view", + "items": [ + { + "command": "notebook:toggle-full-width", + "rank": 4 + } + ] + } + ] + }, "properties": { "fullWidthNotebook": { "type": "boolean", diff --git a/packages/notebook-extension/src/index.ts b/packages/notebook-extension/src/index.ts index f73ff012e8..f0f645b58f 100644 --- a/packages/notebook-extension/src/index.ts +++ b/packages/notebook-extension/src/index.ts @@ -220,29 +220,44 @@ const fullWidthNotebook: JupyterFrontEndPlugin = { description: 'A plugin to set the notebook to full width.', autoStart: true, requires: [INotebookTracker], - optional: [ISettingRegistry], + optional: [ICommandPalette, ISettingRegistry, ITranslator], activate: ( app: JupyterFrontEnd, tracker: INotebookTracker, - settingRegistry: ISettingRegistry | null + palette: ICommandPalette | null, + settingRegistry: ISettingRegistry | null, + translator: ITranslator | null ) => { - const setFullWidth = (value: boolean) => { + const trans = (translator ?? nullTranslator).load('notebook'); + + let fullWidth = false; + + const toggleFullWidth = () => { const current = tracker.currentWidget; + fullWidth = !fullWidth; if (!current) { return; } - current.content.toggleClass(FULL_WIDTH_NOTEBOOK_CLASS, value); + const content = current.content; + content.toggleClass(FULL_WIDTH_NOTEBOOK_CLASS, fullWidth); }; + let notebookSettings: ISettingRegistry.ISettings; + if (settingRegistry) { const loadSettings = settingRegistry.load(fullWidthNotebook.id); const updateSettings = (settings: ISettingRegistry.ISettings): void => { - setFullWidth(settings.get('fullWidthNotebook').composite as boolean); + const newFullWidth = settings.get('fullWidthNotebook') + .composite as boolean; + if (newFullWidth !== fullWidth) { + toggleFullWidth(); + } }; Promise.all([loadSettings, app.restored]) .then(([settings]) => { + notebookSettings = settings; updateSettings(settings); settings.changed.connect((settings) => { updateSettings(settings); @@ -252,6 +267,25 @@ const fullWidthNotebook: JupyterFrontEndPlugin = { console.error(reason.message); }); } + + app.commands.addCommand(CommandIDs.toggleFullWidth, { + label: trans.__('Enable Full Width Notebook'), + execute: () => { + toggleFullWidth(); + if (notebookSettings) { + notebookSettings.set('fullWidthNotebook', fullWidth); + } + }, + isEnabled: () => tracker.currentWidget !== null, + isToggled: () => fullWidth, + }); + + if (palette) { + palette.addItem({ + command: CommandIDs.toggleFullWidth, + category: 'Notebook Operations', + }); + } }, };