Skip to content

Commit c5f109c

Browse files
committed
settings only
1 parent abd2c65 commit c5f109c

File tree

2 files changed

+22
-33
lines changed

2 files changed

+22
-33
lines changed

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
{
2-
"title": "Jupyter Notebook Full Width Notebook",
3-
"description": "Jupyter Notebook Full Width Notebook",
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-
},
2+
"title": "Jupyter Notebook Width Settings",
3+
"description": "Jupyter Notebook Width Settings",
174
"properties": {
185
"fullWidthNotebook": {
196
"type": "boolean",

packages/notebook-extension/src/index.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -220,35 +220,37 @@ const fullWidthNotebook: JupyterFrontEndPlugin<void> = {
220220
description: 'A plugin to set the notebook to full width.',
221221
autoStart: true,
222222
requires: [INotebookTracker],
223-
optional: [ICommandPalette, ISettingRegistry, ITranslator],
223+
optional: [ISettingRegistry],
224224
activate: (
225225
app: JupyterFrontEnd,
226226
tracker: INotebookTracker,
227-
palette: ICommandPalette | null,
228-
settingRegistry: ISettingRegistry | null,
229-
translator: ITranslator | null
227+
settingRegistry: ISettingRegistry | null
230228
) => {
231-
const trans = (translator ?? nullTranslator).load('notebook');
232-
233-
const toggleFullWidth = () => {
229+
const setFullWidth = (value: boolean) => {
234230
const current = tracker.currentWidget;
235231
if (!current) {
236232
return;
237233
}
238-
current.content.toggleClass(FULL_WIDTH_NOTEBOOK_CLASS);
234+
current.content.toggleClass(FULL_WIDTH_NOTEBOOK_CLASS, value);
239235
};
240236

241-
// add a command to toggle full width
242-
app.commands.addCommand(CommandIDs.toggleFullWidth, {
243-
label: trans.__('Toggle Full Width'),
244-
execute: toggleFullWidth,
245-
});
237+
if (settingRegistry) {
238+
const loadSettings = settingRegistry.load(fullWidthNotebook.id);
246239

247-
if (palette) {
248-
palette.addItem({
249-
command: CommandIDs.toggleFullWidth,
250-
category: 'Notebook Operations',
251-
});
240+
const updateSettings = (settings: ISettingRegistry.ISettings): void => {
241+
setFullWidth(settings.get('fullWidthNotebook').composite as boolean);
242+
};
243+
244+
Promise.all([loadSettings, app.restored])
245+
.then(([settings]) => {
246+
updateSettings(settings);
247+
settings.changed.connect((settings) => {
248+
updateSettings(settings);
249+
});
250+
})
251+
.catch((reason: Error) => {
252+
console.error(reason.message);
253+
});
252254
}
253255
},
254256
};

0 commit comments

Comments
 (0)