Skip to content

Commit

Permalink
enable more ways to toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpio committed Oct 22, 2024
1 parent c5f109c commit 00cfb64
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
17 changes: 15 additions & 2 deletions packages/notebook-extension/schema/full-width-notebook.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
44 changes: 39 additions & 5 deletions packages/notebook-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,29 +220,44 @@ const fullWidthNotebook: JupyterFrontEndPlugin<void> = {
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);
Expand All @@ -252,6 +267,25 @@ const fullWidthNotebook: JupyterFrontEndPlugin<void> = {
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',
});
}
},
};

Expand Down

0 comments on commit 00cfb64

Please sign in to comment.