Skip to content

Commit

Permalink
settings only
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpio committed Oct 22, 2024
1 parent abd2c65 commit c5f109c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 33 deletions.
17 changes: 2 additions & 15 deletions packages/notebook-extension/schema/full-width-notebook.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
{
"title": "Jupyter Notebook Full Width Notebook",
"description": "Jupyter Notebook Full Width Notebook",
"jupyter.lab.menus": {
"main": [
{
"id": "jp-mainmenu-view",
"items": [
{
"command": "notebook:toggle-full-width",
"rank": 4
}
]
}
]
},
"title": "Jupyter Notebook Width Settings",
"description": "Jupyter Notebook Width Settings",
"properties": {
"fullWidthNotebook": {
"type": "boolean",
Expand Down
38 changes: 20 additions & 18 deletions packages/notebook-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,35 +220,37 @@ const fullWidthNotebook: JupyterFrontEndPlugin<void> = {
description: 'A plugin to set the notebook to full width.',
autoStart: true,
requires: [INotebookTracker],
optional: [ICommandPalette, ISettingRegistry, ITranslator],
optional: [ISettingRegistry],
activate: (
app: JupyterFrontEnd,
tracker: INotebookTracker,
palette: ICommandPalette | null,
settingRegistry: ISettingRegistry | null,
translator: ITranslator | null
settingRegistry: ISettingRegistry | null
) => {
const trans = (translator ?? nullTranslator).load('notebook');

const toggleFullWidth = () => {
const setFullWidth = (value: boolean) => {
const current = tracker.currentWidget;
if (!current) {
return;
}
current.content.toggleClass(FULL_WIDTH_NOTEBOOK_CLASS);
current.content.toggleClass(FULL_WIDTH_NOTEBOOK_CLASS, value);
};

// add a command to toggle full width
app.commands.addCommand(CommandIDs.toggleFullWidth, {
label: trans.__('Toggle Full Width'),
execute: toggleFullWidth,
});
if (settingRegistry) {
const loadSettings = settingRegistry.load(fullWidthNotebook.id);

if (palette) {
palette.addItem({
command: CommandIDs.toggleFullWidth,
category: 'Notebook Operations',
});
const updateSettings = (settings: ISettingRegistry.ISettings): void => {
setFullWidth(settings.get('fullWidthNotebook').composite as boolean);
};

Promise.all([loadSettings, app.restored])
.then(([settings]) => {
updateSettings(settings);
settings.changed.connect((settings) => {
updateSettings(settings);
});
})
.catch((reason: Error) => {
console.error(reason.message);
});
}
},
};
Expand Down

0 comments on commit c5f109c

Please sign in to comment.