Skip to content

Commit beba237

Browse files
authored
Merge pull request #6625 from brichet/sidepanel_followup
Moves panel related objects to a dedicated module file
2 parents 707e9c4 + c4a6e8b commit beba237

File tree

7 files changed

+510
-510
lines changed

7 files changed

+510
-510
lines changed

packages/application-extension/src/index.ts

+47-46
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ import {
3535
NotebookApp,
3636
NotebookShell,
3737
INotebookShell,
38-
SideBarPanel,
39-
SideBarHandler
38+
SidePanel,
39+
SidePanelHandler,
40+
SidePanelPalette
4041
} from '@jupyter-notebook/application';
4142

4243
import { jupyterIcon } from '@jupyter-notebook/ui-components';
@@ -51,8 +52,6 @@ import {
5152

5253
import { Menu, Widget } from '@lumino/widgets';
5354

54-
import { SideBarPalette } from './sidebarpalette';
55-
5655
/**
5756
* A regular expression to match path to notebooks and documents
5857
*/
@@ -73,7 +72,7 @@ namespace CommandIDs {
7372
export const toggleTop = 'application:toggle-top';
7473

7574
/**
76-
* Toggle sidebar visibility
75+
* Toggle side panel visibility
7776
*/
7877
export const togglePanel = 'application:toggle-panel';
7978

@@ -543,10 +542,10 @@ const topVisibility: JupyterFrontEndPlugin<void> = {
543542
};
544543

545544
/**
546-
* Plugin to toggle the left or right sidebar's visibility.
545+
* Plugin to toggle the left or right side panel's visibility.
547546
*/
548-
const sidebarVisibility: JupyterFrontEndPlugin<void> = {
549-
id: '@jupyter-notebook/application-extension:sidebar',
547+
const sidePanelVisibility: JupyterFrontEndPlugin<void> = {
548+
id: '@jupyter-notebook/application-extension:sidepanel',
550549
requires: [INotebookShell, ITranslator],
551550
optional: [IMainMenu, ICommandPalette],
552551
autoStart: true,
@@ -562,7 +561,7 @@ const sidebarVisibility: JupyterFrontEndPlugin<void> = {
562561
/* Arguments for togglePanel command:
563562
* side, left or right area
564563
* title, widget title to show in the menu
565-
* id, widget ID to activate in the sidebar
564+
* id, widget ID to activate in the side panel
566565
*/
567566
app.commands.addCommand(CommandIDs.togglePanel, {
568567
label: args => args['title'] as string,
@@ -643,33 +642,33 @@ const sidebarVisibility: JupyterFrontEndPlugin<void> = {
643642
}
644643
});
645644

646-
const sideBarMenu: { [area in SideBarPanel.Area]: IDisposable | null } = {
645+
const sidePanelMenu: { [area in SidePanel.Area]: IDisposable | null } = {
647646
left: null,
648647
right: null
649648
};
650649

651650
/**
652-
* The function which adds entries to the View menu for each widget of a sidebar.
651+
* The function which adds entries to the View menu for each widget of a side panel.
653652
*
654-
* @param area - 'left' or 'right', the area of the side bar.
655-
* @param entryLabel - the name of the main entry in the View menu for that sidebar.
653+
* @param area - 'left' or 'right', the area of the side panel.
654+
* @param entryLabel - the name of the main entry in the View menu for that side panel.
656655
* @returns - The disposable menu added to the View menu or null.
657656
*/
658-
const updateMenu = (area: SideBarPanel.Area, entryLabel: string) => {
657+
const updateMenu = (area: SidePanel.Area, entryLabel: string) => {
659658
if (menu === null) {
660659
return null;
661660
}
662661

663-
// Remove the previous menu entry for this sidebar.
664-
sideBarMenu[area]?.dispose();
662+
// Remove the previous menu entry for this side panel.
663+
sidePanelMenu[area]?.dispose();
665664

666-
// Creates a new menu entry and populates it with sidebar widgets.
665+
// Creates a new menu entry and populates it with side panel widgets.
667666
const newMenu = new Menu({ commands: app.commands });
668667
newMenu.title.label = entryLabel;
669668
const widgets = notebookShell.widgets(area);
670669
let menuToAdd = false;
671670

672-
for (let widget of widgets) {
671+
for (const widget of widgets) {
673672
newMenu.addItem({
674673
command: CommandIDs.togglePanel,
675674
args: {
@@ -683,7 +682,7 @@ const sidebarVisibility: JupyterFrontEndPlugin<void> = {
683682

684683
// If there are widgets, add the menu to the main menu entry.
685684
if (menuToAdd) {
686-
sideBarMenu[area] = menu.viewMenu.addItem({
685+
sidePanelMenu[area] = menu.viewMenu.addItem({
687686
type: 'submenu',
688687
submenu: newMenu
689688
});
@@ -693,63 +692,65 @@ const sidebarVisibility: JupyterFrontEndPlugin<void> = {
693692
app.restored.then(() => {
694693
// Create menu entries for the left and right panel.
695694
if (menu) {
696-
const getSideBarLabel = (area: SideBarPanel.Area): string => {
695+
const getSidePanelLabel = (area: SidePanel.Area): string => {
697696
if (area === 'left') {
698-
return trans.__(`Left Sidebar`);
697+
return trans.__('Left Sidebar');
699698
} else {
700-
return trans.__(`Right Sidebar`);
699+
return trans.__('Right Sidebar');
701700
}
702701
};
703702
const leftArea = notebookShell.leftHandler.area;
704-
const leftLabel = getSideBarLabel(leftArea);
703+
const leftLabel = getSidePanelLabel(leftArea);
705704
updateMenu(leftArea, leftLabel);
706705

707706
const rightArea = notebookShell.rightHandler.area;
708-
const rightLabel = getSideBarLabel(rightArea);
707+
const rightLabel = getSidePanelLabel(rightArea);
709708
updateMenu(rightArea, rightLabel);
710709

711-
const handleSideBarChange = (
712-
sidebar: SideBarHandler,
710+
const handleSidePanelChange = (
711+
sidePanel: SidePanelHandler,
713712
widget: Widget
714713
) => {
715-
const label = getSideBarLabel(sidebar.area);
716-
updateMenu(sidebar.area, label);
714+
const label = getSidePanelLabel(sidePanel.area);
715+
updateMenu(sidePanel.area, label);
717716
};
718717

719-
notebookShell.leftHandler.widgetAdded.connect(handleSideBarChange);
720-
notebookShell.leftHandler.widgetRemoved.connect(handleSideBarChange);
721-
notebookShell.rightHandler.widgetAdded.connect(handleSideBarChange);
722-
notebookShell.rightHandler.widgetRemoved.connect(handleSideBarChange);
718+
notebookShell.leftHandler.widgetAdded.connect(handleSidePanelChange);
719+
notebookShell.leftHandler.widgetRemoved.connect(handleSidePanelChange);
720+
notebookShell.rightHandler.widgetAdded.connect(handleSidePanelChange);
721+
notebookShell.rightHandler.widgetRemoved.connect(handleSidePanelChange);
723722
}
724723

725724
// Add palette entries for side panels.
726725
if (palette) {
727-
const sideBarPalette = new SideBarPalette({
726+
const sidePanelPalette = new SidePanelPalette({
728727
commandPalette: palette as ICommandPalette,
729728
command: CommandIDs.togglePanel
730729
});
731730

732731
notebookShell.leftHandler.widgets.forEach(widget => {
733-
sideBarPalette.addItem(widget, notebookShell.leftHandler.area);
732+
sidePanelPalette.addItem(widget, notebookShell.leftHandler.area);
734733
});
735734

736735
notebookShell.rightHandler.widgets.forEach(widget => {
737-
sideBarPalette.addItem(widget, notebookShell.rightHandler.area);
736+
sidePanelPalette.addItem(widget, notebookShell.rightHandler.area);
738737
});
739738

740-
// Update menu and palette when widgets are added or removed from sidebars.
741-
notebookShell.leftHandler.widgetAdded.connect((sidebar, widget) => {
742-
sideBarPalette.addItem(widget, sidebar.area);
743-
});
744-
notebookShell.leftHandler.widgetRemoved.connect((sidebar, widget) => {
745-
sideBarPalette.removeItem(widget, sidebar.area);
739+
// Update menu and palette when widgets are added or removed from side panels.
740+
notebookShell.leftHandler.widgetAdded.connect((sidePanel, widget) => {
741+
sidePanelPalette.addItem(widget, sidePanel.area);
746742
});
747-
notebookShell.rightHandler.widgetAdded.connect((sidebar, widget) => {
748-
sideBarPalette.addItem(widget, sidebar.area);
743+
notebookShell.leftHandler.widgetRemoved.connect((sidePanel, widget) => {
744+
sidePanelPalette.removeItem(widget, sidePanel.area);
749745
});
750-
notebookShell.rightHandler.widgetRemoved.connect((sidebar, widget) => {
751-
sideBarPalette.removeItem(widget, sidebar.area);
746+
notebookShell.rightHandler.widgetAdded.connect((sidePanel, widget) => {
747+
sidePanelPalette.addItem(widget, sidePanel.area);
752748
});
749+
notebookShell.rightHandler.widgetRemoved.connect(
750+
(sidePanel, widget) => {
751+
sidePanelPalette.removeItem(widget, sidePanel.area);
752+
}
753+
);
753754
}
754755
});
755756
}
@@ -908,7 +909,7 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
908909
paths,
909910
sessionDialogs,
910911
shell,
911-
sidebarVisibility,
912+
sidePanelVisibility,
912913
status,
913914
tabTitle,
914915
title,

packages/application-extension/src/sidebarpalette.ts

-114
This file was deleted.

packages/application/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33

44
export * from './app';
55
export * from './shell';
6+
export * from './panelhandler';

0 commit comments

Comments
 (0)