Skip to content

Commit 00cfb64

Browse files
committed
enable more ways to toggle
1 parent c5f109c commit 00cfb64

File tree

2 files changed

+54
-7
lines changed

2 files changed

+54
-7
lines changed

packages/notebook-extension/schema/full-width-notebook.json

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
{
2-
"title": "Jupyter Notebook Width Settings",
3-
"description": "Jupyter Notebook Width Settings",
2+
"title": "Jupyter Notebook Full Width Notebook",
3+
"description": "Jupyter Notebook Notebook With settings",
4+
"jupyter.lab.menus": {
5+
"main": [
6+
{
7+
"id": "jp-mainmenu-view",
8+
"items": [
9+
{
10+
"command": "notebook:toggle-full-width",
11+
"rank": 4
12+
}
13+
]
14+
}
15+
]
16+
},
417
"properties": {
518
"fullWidthNotebook": {
619
"type": "boolean",

packages/notebook-extension/src/index.ts

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,29 +220,44 @@ const fullWidthNotebook: JupyterFrontEndPlugin<void> = {
220220
description: 'A plugin to set the notebook to full width.',
221221
autoStart: true,
222222
requires: [INotebookTracker],
223-
optional: [ISettingRegistry],
223+
optional: [ICommandPalette, ISettingRegistry, ITranslator],
224224
activate: (
225225
app: JupyterFrontEnd,
226226
tracker: INotebookTracker,
227-
settingRegistry: ISettingRegistry | null
227+
palette: ICommandPalette | null,
228+
settingRegistry: ISettingRegistry | null,
229+
translator: ITranslator | null
228230
) => {
229-
const setFullWidth = (value: boolean) => {
231+
const trans = (translator ?? nullTranslator).load('notebook');
232+
233+
let fullWidth = false;
234+
235+
const toggleFullWidth = () => {
230236
const current = tracker.currentWidget;
237+
fullWidth = !fullWidth;
231238
if (!current) {
232239
return;
233240
}
234-
current.content.toggleClass(FULL_WIDTH_NOTEBOOK_CLASS, value);
241+
const content = current.content;
242+
content.toggleClass(FULL_WIDTH_NOTEBOOK_CLASS, fullWidth);
235243
};
236244

245+
let notebookSettings: ISettingRegistry.ISettings;
246+
237247
if (settingRegistry) {
238248
const loadSettings = settingRegistry.load(fullWidthNotebook.id);
239249

240250
const updateSettings = (settings: ISettingRegistry.ISettings): void => {
241-
setFullWidth(settings.get('fullWidthNotebook').composite as boolean);
251+
const newFullWidth = settings.get('fullWidthNotebook')
252+
.composite as boolean;
253+
if (newFullWidth !== fullWidth) {
254+
toggleFullWidth();
255+
}
242256
};
243257

244258
Promise.all([loadSettings, app.restored])
245259
.then(([settings]) => {
260+
notebookSettings = settings;
246261
updateSettings(settings);
247262
settings.changed.connect((settings) => {
248263
updateSettings(settings);
@@ -252,6 +267,25 @@ const fullWidthNotebook: JupyterFrontEndPlugin<void> = {
252267
console.error(reason.message);
253268
});
254269
}
270+
271+
app.commands.addCommand(CommandIDs.toggleFullWidth, {
272+
label: trans.__('Enable Full Width Notebook'),
273+
execute: () => {
274+
toggleFullWidth();
275+
if (notebookSettings) {
276+
notebookSettings.set('fullWidthNotebook', fullWidth);
277+
}
278+
},
279+
isEnabled: () => tracker.currentWidget !== null,
280+
isToggled: () => fullWidth,
281+
});
282+
283+
if (palette) {
284+
palette.addItem({
285+
command: CommandIDs.toggleFullWidth,
286+
category: 'Notebook Operations',
287+
});
288+
}
255289
},
256290
};
257291

0 commit comments

Comments
 (0)