Skip to content

Commit 8e72c5e

Browse files
Fix toolbar buttons for notebook (#50)
* Fix toolbar buttons for share/download position, restore add Text button, use themed icon for download caret * Update Playwright Snapshots * Try to fix download icon * Update Playwright Snapshots * Trigger CI * Update Playwright Snapshots * Trigger CI --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 333d19b commit 8e72c5e

File tree

8 files changed

+71
-51
lines changed

8 files changed

+71
-51
lines changed

schema/plugin.json

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@
5151
"name": "restart-and-run",
5252
"caption": "Restart and run all cells"
5353
},
54+
{
55+
"name": "share",
56+
"rank": 35
57+
},
58+
{
59+
"name": "downloadDropdown",
60+
"rank": 36
61+
},
5462
{
5563
"name": "cellType",
5664
"command": "",
@@ -70,8 +78,13 @@
7078
},
7179
{
7280
"name": "insert-text",
73-
"command": "jupytereverywhere:insert-markdown-cell",
74-
"disabled": false,
81+
"command": "apputils:run-all-enabled",
82+
"args": {
83+
"commands": ["notebook:insert-cell-below", "notebook:change-cell-to-markdown"],
84+
"args": {
85+
"toolbar": true
86+
}
87+
},
7588
"rank": 13,
7689
"icon": "ui-components:add",
7790
"label": "Text"

src/icons.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import runSvg from '../style/icons/run.svg';
2424
import refreshSvg from '../style/icons/refresh.svg';
2525
import stopSvg from '../style/icons/stop.svg';
2626
import fastForwardSvg from '../style/icons/fast-forward.svg';
27+
import downloadCaretSvg from '../style/icons/download-caret.svg';
2728

2829
export namespace EverywhereIcons {
2930
// Overwrite Jupyter default icons
@@ -80,4 +81,8 @@ export namespace EverywhereIcons {
8081
name: 'everywhere:logo',
8182
svgstr: logoSvg
8283
});
84+
export const downloadCaret = new LabIcon({
85+
name: 'everywhere:download-caret',
86+
svgstr: downloadCaretSvg
87+
});
8388
}

src/pages/notebook.tsx

Lines changed: 24 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ import { JupyterFrontEnd, JupyterFrontEndPlugin } from '@jupyterlab/application'
22
import { INotebookTracker } from '@jupyterlab/notebook';
33
import { SidebarIcon } from '../ui-components/SidebarIcon';
44
import { EverywhereIcons } from '../icons';
5-
import { ToolbarButton } from '@jupyterlab/apputils';
5+
import { ToolbarButton, IToolbarWidgetRegistry } from '@jupyterlab/apputils';
66
import { DownloadDropdownButton } from '../ui-components/DownloadDropdownButton';
77
import { Commands } from '../commands';
88

99
export const notebookPlugin: JupyterFrontEndPlugin<void> = {
1010
id: 'jupytereverywhere:notebook',
1111
autoStart: true,
12-
requires: [INotebookTracker],
13-
activate: (app: JupyterFrontEnd, tracker: INotebookTracker) => {
12+
requires: [INotebookTracker, IToolbarWidgetRegistry],
13+
activate: (
14+
app: JupyterFrontEnd,
15+
tracker: INotebookTracker,
16+
toolbarRegistry: IToolbarWidgetRegistry
17+
) => {
1418
const { commands, shell } = app;
1519
const contents = app.serviceManager.contents;
1620

@@ -82,51 +86,24 @@ export const notebookPlugin: JupyterFrontEndPlugin<void> = {
8286
app.shell.activateById(sidebarItem.id);
8387
app.restored.then(() => app.shell.activateById(sidebarItem.id));
8488

85-
/**
86-
* Create a "Share" button
87-
*/
88-
const shareButton = new ToolbarButton({
89-
label: 'Share',
90-
icon: EverywhereIcons.link,
91-
tooltip: 'Share this notebook',
92-
onClick: () => {
93-
void commands.execute(Commands.shareNotebookCommand);
94-
}
95-
});
96-
97-
/**
98-
* Create the Download dropdown
99-
*/
100-
const downloadDropdownButton = new DownloadDropdownButton(commands);
89+
toolbarRegistry.addFactory(
90+
'Notebook',
91+
'downloadDropdown',
92+
() => new DownloadDropdownButton(commands)
93+
);
10194

102-
tracker.widgetAdded.connect((_, notebookPanel) => {
103-
if (notebookPanel) {
104-
// Look for the right position to insert the buttons (after the run buttons)
105-
let insertIndex = 5;
106-
const toolbar = notebookPanel.toolbar;
107-
108-
Array.from(toolbar.names()).forEach((name, index) => {
109-
if (name === 'run-all') {
110-
insertIndex = index + 1;
95+
toolbarRegistry.addFactory(
96+
'Notebook',
97+
'share',
98+
() =>
99+
new ToolbarButton({
100+
label: 'Share',
101+
icon: EverywhereIcons.link,
102+
tooltip: 'Share this notebook',
103+
onClick: () => {
104+
void commands.execute(Commands.shareNotebookCommand);
111105
}
112-
});
113-
114-
// Add download dropdown button
115-
try {
116-
toolbar.insertItem(insertIndex, 'downloadDropdownButton', downloadDropdownButton);
117-
insertIndex++;
118-
} catch (error) {
119-
toolbar.addItem('downloadDropdownButton', downloadDropdownButton);
120-
}
121-
122-
// Add the share button
123-
try {
124-
toolbar.insertItem(insertIndex, 'shareButton', shareButton);
125-
} catch (error) {
126-
// Fallback: add at the end
127-
toolbar.addItem('shareButton', shareButton);
128-
}
129-
}
130-
});
106+
})
107+
);
131108
}
132109
};

src/ui-components/DownloadDropdownButton.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { ReactWidget, ToolbarButtonComponent, caretDownIcon } from '@jupyterlab/ui-components';
1+
import { ReactWidget, ToolbarButtonComponent } from '@jupyterlab/ui-components';
22
import { CommandRegistry } from '@lumino/commands';
33
import { Menu } from '@lumino/widgets';
44
import React from 'react';
5+
import { EverywhereIcons } from '../icons';
56

67
export class DownloadDropdownButton extends ReactWidget {
78
constructor(commands: CommandRegistry) {
@@ -19,7 +20,7 @@ export class DownloadDropdownButton extends ReactWidget {
1920
return (
2021
<ToolbarButtonComponent
2122
className="je-DownloadButton"
22-
icon={caretDownIcon}
23+
icon={EverywhereIcons.downloadCaret}
2324
label="Download"
2425
tooltip="Download notebook"
2526
onClick={this._showMenu.bind(this)}

style/icons/download-caret.svg

Lines changed: 24 additions & 0 deletions
Loading
603 Bytes
Loading
-29 Bytes
Loading
522 Bytes
Loading

0 commit comments

Comments
 (0)