Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions packages/application/src/panelhandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,17 @@ export class SidePanelHandler extends PanelHandler {
* if there is no most recently used.
*/
expand(id?: string): void {
if (this._currentWidget) {
this.collapse();
}
if (id) {
if (this._currentWidget && this._currentWidget.id === id) {
this.collapse();
this.hide();
} else {
this.collapse();
this.hide();
this.activate(id);
this.show();
this.activate(id);
} else {
const visibleWidget = this.currentWidget;
if (visibleWidget) {
this._currentWidget = visibleWidget;
this.activate(visibleWidget.id);
}
} else if (this.currentWidget) {
this._currentWidget = this.currentWidget;
this.activate(this._currentWidget.id);
this.show();
}
}

Expand Down
63 changes: 63 additions & 0 deletions packages/application/src/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,69 @@ export class NotebookShell extends Widget implements JupyterFrontEnd.IShell {
}
}

/**
* Return a boolean whether the side panel is visible.
*/
isSidePanelVisible(area: string): boolean {
if (area === 'left') {
return this._leftHandler.isVisible;
} else if (area === 'right') {
return this._rightHandler.isVisible;
}
return false;
}

/**
* Get the area of a widget, given its id.
*
* @param id - the widget id
* @returns the area where the widget belongs, or null.
*/
getWidgetArea(id: string): string | null {
for (const area of ['main', 'top', 'left', 'right', 'menu', 'down']) {
const widget = find(
this.widgets(area as INotebookShell.Area),
(w) => w.id === id
);
if (widget) {
return area;
}
}
return null;
}

/**
* Expand an area.
*/
expand(area: string): void {
if (!['top', 'left', 'right'].includes(area)) {
return;
}
if (area === 'top') {
this.expandTop();
} else if (area === 'left') {
this.expandLeft();
} else if (area === 'right') {
this.expandRight();
}
}

/**
* Collapse an area.
*/
collapse(area: string): void {
if (!['top', 'left', 'right'].includes(area)) {
return;
}
if (area === 'top') {
this.collapseTop();
} else if (area === 'left') {
this.collapseLeft();
} else if (area === 'right') {
this.collapseRight();
}
}

/**
* Collapse the top area and the spacer to make the view more compact.
*/
Expand Down
3 changes: 3 additions & 0 deletions packages/notebook-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@
"@jupyterlab/application": "~4.6.0-alpha.0",
"@jupyterlab/apputils": "~4.7.0-alpha.0",
"@jupyterlab/cells": "~4.6.0-alpha.0",
"@jupyterlab/debugger": "~4.6.0-alpha.0",
"@jupyterlab/docmanager": "~4.6.0-alpha.0",
"@jupyterlab/notebook": "~4.6.0-alpha.0",
"@jupyterlab/settingregistry": "~4.6.0-alpha.0",
"@jupyterlab/toc": "~6.6.0-alpha.0",
"@jupyterlab/translation": "~4.6.0-alpha.0",
"@lumino/algorithm": "2.0.4",
"@lumino/polling": "^2.1.5",
"@lumino/widgets": "^2.7.2",
"react": "^18.2.0",
Expand Down
32 changes: 32 additions & 0 deletions packages/notebook-extension/schema/menu-override.json
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried unsuccessfully to replace the upstream shortcuts, but it seems to also disable the new shortcuts

"jupyter.lab.shortcuts": [
    {
      "command": "toc:show-panel",
      "disabled": true,
      "keys": ["Accel Shift K"],
      "selector": "body"
    },
    {
      "command": "toc:toggle-panel",
      "keys": ["Accel Shift K"],
      "selector": "body"
    },
    {
      "command": "debugger:show-panel",
      "disabled": true,
      "keys": ["Accel Shift E"],
      "selector": "body"
    },
    {
      "command": "debugger:toggle-panel",
      "keys": ["Accel Shift E"],
      "selector": "body"
    }
  ]

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"title": "Menu override",
"description": "Override some menu items",
"jupyter.lab.menus": {
"main": [
{
"id": "jp-mainmenu-view",
"items": [
{
"command": "toc:show-panel",
"disabled": true
},
{
"command": "toc:toggle-panel",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this menu entry show up if the TOC extension is disabled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the command is created only if the TOC tracker token (ITableOfContentsTracker) is provided https://github.com/jupyter/notebook/pull/7799/files#diff-9bfcf1dd55d0d858225f19d220d93e635e9f83f14bd735a3958156a244345d24R786.
This is the same for the debugger, which expects IDebuggerSidebar token.

"rank": 4
},
{
"command": "debugger:show-panel",
"disabled": true
},
{
"command": "debugger:toggle-panel",
"rank": 5
}
]
}
]
},
"properties": {},
"additionalProperties": false,
"type": "object"
}
123 changes: 123 additions & 0 deletions packages/notebook-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { Cell, CodeCell } from '@jupyterlab/cells';

import { PageConfig, Text, Time, URLExt } from '@jupyterlab/coreutils';

import { IDebugger, IDebuggerSidebar } from '@jupyterlab/debugger';

import { IDocumentManager } from '@jupyterlab/docmanager';

import { DocumentRegistry } from '@jupyterlab/docregistry';
Expand All @@ -31,10 +33,14 @@ import {

import { ISettingRegistry } from '@jupyterlab/settingregistry';

import { ITableOfContentsTracker } from '@jupyterlab/toc';

import { ITranslator, nullTranslator } from '@jupyterlab/translation';

import { INotebookShell } from '@jupyter-notebook/application';

import { find } from '@lumino/algorithm';

import { Poll } from '@lumino/polling';

import { Widget } from '@lumino/widgets';
Expand Down Expand Up @@ -749,6 +755,122 @@ const editNotebookMetadata: JupyterFrontEndPlugin<void> = {
},
};

/**
* A plugin to replace the menu item activating the TOC panel, to allow toggling it.
*/
const overrideMenuItems: JupyterFrontEndPlugin<void> = {
id: '@jupyter-notebook/notebook-extension:menu-override',
description: 'A plugin to override some menu items',
autoStart: true,
optional: [
IDebuggerSidebar,
IMainMenu,
INotebookShell,
ITableOfContentsTracker,
ITranslator,
],
activate: (
app: JupyterFrontEnd,
debuggerSidebar: IDebugger.ISidebar | null,
mainMenu: IMainMenu | null,
shell: INotebookShell | null,
tocTracker: ITableOfContentsTracker | null,
translator: ITranslator | null
) => {
if (!mainMenu || !shell) {
return;
}
const trans = (translator ?? nullTranslator).load('notebook');
const { commands } = app;

if (tocTracker) {
const TOC_PANEL_ID = 'table-of-contents';
commands.addCommand('toc:toggle-panel', {
label: trans.__('Table of Contents'),
isToggleable: true,
isToggled: () => {
const area = shell.getWidgetArea(TOC_PANEL_ID);
if (!area) {
return false;
}
const widget = find(
shell.widgets(area as INotebookShell.Area),
(w) => w.id === TOC_PANEL_ID
);
if (!widget) {
return false;
}
return shell.isSidePanelVisible(area) && widget.isVisible;
},
execute: () => {
const area = shell.getWidgetArea(TOC_PANEL_ID);
if (!area) {
return;
}
const widget = find(
shell.widgets(area as INotebookShell.Area),
(w) => w.id === TOC_PANEL_ID
);
if (shell.isSidePanelVisible(area) && widget?.isVisible) {
shell.collapse(area);
} else {
shell.activateById(TOC_PANEL_ID);
}
},
describedBy: {
args: {
type: 'object',
properties: {},
},
},
});
}

if (debuggerSidebar) {
const DEBUGGER_PANEL_ID = 'jp-debugger-sidebar';
commands.addCommand('debugger:toggle-panel', {
label: trans.__('Debugger Panel'),
isToggleable: true,
isToggled: () => {
const area = shell.getWidgetArea(DEBUGGER_PANEL_ID);
if (!area) {
return false;
}
const widget = find(
shell.widgets(area as INotebookShell.Area),
(w) => w.id === DEBUGGER_PANEL_ID
);
if (!widget) {
return false;
}
return shell.isSidePanelVisible(area) && widget.isVisible;
},
execute: () => {
const area = shell.getWidgetArea(DEBUGGER_PANEL_ID);
if (!area) {
return;
}
const widget = find(
shell.widgets(area as INotebookShell.Area),
(w) => w.id === DEBUGGER_PANEL_ID
);
if (shell.isSidePanelVisible(area) && widget?.isVisible) {
shell.collapse(area);
} else {
shell.activateById(DEBUGGER_PANEL_ID);
}
},
describedBy: {
args: {
type: 'object',
properties: {},
},
},
});
}
},
};

/**
* Export the plugins as default.
*/
Expand All @@ -761,6 +883,7 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
kernelLogo,
kernelStatus,
notebookToolsWidget,
overrideMenuItems,
scrollOutput,
tabIcon,
trusted,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2485,10 +2485,13 @@ __metadata:
"@jupyterlab/application": ~4.6.0-alpha.0
"@jupyterlab/apputils": ~4.7.0-alpha.0
"@jupyterlab/cells": ~4.6.0-alpha.0
"@jupyterlab/debugger": ~4.6.0-alpha.0
"@jupyterlab/docmanager": ~4.6.0-alpha.0
"@jupyterlab/notebook": ~4.6.0-alpha.0
"@jupyterlab/settingregistry": ~4.6.0-alpha.0
"@jupyterlab/toc": ~6.6.0-alpha.0
"@jupyterlab/translation": ~4.6.0-alpha.0
"@lumino/algorithm": 2.0.4
"@lumino/polling": ^2.1.5
"@lumino/widgets": ^2.7.2
react: ^18.2.0
Expand Down Expand Up @@ -3203,7 +3206,7 @@ __metadata:
languageName: node
linkType: hard

"@jupyterlab/debugger@npm:^4.6.0-alpha.0":
"@jupyterlab/debugger@npm:^4.6.0-alpha.0, @jupyterlab/debugger@npm:~4.6.0-alpha.0":
version: 4.6.0-alpha.0
resolution: "@jupyterlab/debugger@npm:4.6.0-alpha.0"
dependencies:
Expand Down Expand Up @@ -4466,7 +4469,7 @@ __metadata:
languageName: node
linkType: hard

"@jupyterlab/toc@npm:^6.6.0-alpha.0":
"@jupyterlab/toc@npm:^6.6.0-alpha.0, @jupyterlab/toc@npm:~6.6.0-alpha.0":
version: 6.6.0-alpha.0
resolution: "@jupyterlab/toc@npm:6.6.0-alpha.0"
dependencies:
Expand Down Expand Up @@ -4880,7 +4883,7 @@ __metadata:
languageName: node
linkType: hard

"@lumino/algorithm@npm:^2.0.4":
"@lumino/algorithm@npm:2.0.4, @lumino/algorithm@npm:^2.0.4":
version: 2.0.4
resolution: "@lumino/algorithm@npm:2.0.4"
checksum: ec1532fc294666fb483dd35082ec50ad979d0e9e1daf7a951ca045fd36a1ae88c7c73bf09c1aafed1ea826319f038ec2ed7058f58d214d5ed9f6a4cf61f232e8
Expand Down
Loading