Skip to content

Commit f552d3d

Browse files
committed
add open in voila button
1 parent f76ed7d commit f552d3d

6 files changed

Lines changed: 2022 additions & 63 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
},
5858
"dependencies": {
5959
"@jupyterlab/application": "^4.0.0",
60-
"@jupyterlab/filebrowser": "^4.5.6"
60+
"@jupyterlab/filebrowser": "^4.5.6",
61+
"@jupyterlab/notebook": "^4.5.6"
6162
},
6263
"devDependencies": {
6364
"@jupyterlab/builder": "^4.0.0",

schema/open-in-voila-plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{
77
"command": "jupyter-ui-tweak/open-in-voila-command",
88
"selector": ".jp-DirListing-item[data-file-type=\"notebook\"]",
9-
"rank": 0
9+
"rank": 3
1010
}
1111
]
1212
},

src/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import {
44
} from '@jupyterlab/application';
55
import { IToolbarWidgetRegistry } from '@jupyterlab/apputils';
66
import { ITranslator } from '@jupyterlab/translation';
7-
import { caretDownIcon, tabIcon } from '@jupyterlab/ui-components';
7+
import { caretDownIcon, launchIcon } from '@jupyterlab/ui-components';
88
import { Menu, MenuBar } from '@lumino/widgets';
99
import { IFileBrowserFactory } from '@jupyterlab/filebrowser';
1010
import { getVoilaUrl } from './tools';
11+
import { VoilaButton } from './voilabutton';
1112
const FILE_BROWSER_FACTORY = 'FileBrowser';
1213

1314
/**
@@ -108,7 +109,7 @@ const openInVoila: JupyterFrontEndPlugin<void> = {
108109
caption: 'Open selected notebook in Voila',
109110
isEnabled: () => true,
110111
isVisible: () => true,
111-
icon: tabIcon,
112+
icon: launchIcon,
112113
execute: () => {
113114
const file = factory.tracker.currentWidget
114115
?.selectedItems()
@@ -119,6 +120,11 @@ const openInVoila: JupyterFrontEndPlugin<void> = {
119120
}
120121
}
121122
});
123+
124+
const { commands, docRegistry } = app;
125+
126+
const voilaButton = new VoilaButton(commands);
127+
docRegistry.addWidgetExtension('Notebook', voilaButton);
122128
}
123129
};
124130

src/voilabutton.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { ToolbarButton } from '@jupyterlab/apputils';
2+
import { DocumentRegistry } from '@jupyterlab/docregistry';
3+
import { INotebookModel, NotebookPanel } from '@jupyterlab/notebook';
4+
import { CommandRegistry } from '@lumino/commands';
5+
import { IDisposable } from '@lumino/disposable';
6+
import { launchIcon } from '@jupyterlab/ui-components';
7+
8+
export class VoilaButton implements DocumentRegistry.IWidgetExtension<
9+
NotebookPanel,
10+
INotebookModel
11+
> {
12+
/**
13+
* Instantiate a new VoilaRenderButton.
14+
* @param commands The command registry.
15+
*/
16+
constructor(commands: CommandRegistry) {
17+
this._commands = commands;
18+
}
19+
20+
/**
21+
* Create a new extension object.
22+
*/
23+
createNew(panel: NotebookPanel): IDisposable {
24+
const button = new ToolbarButton({
25+
tooltip: 'Open with Voilà',
26+
className: 'jp-tweak-open-in-voila-button',
27+
icon: launchIcon,
28+
pressed: false,
29+
noFocusOnClick: true,
30+
onClick: () => {
31+
this._commands.execute('notebook:open-with-voila');
32+
}
33+
});
34+
panel.toolbar.insertAfter('cellType', 'openInVoila', button);
35+
return button;
36+
}
37+
38+
private _commands: CommandRegistry;
39+
}

style/base.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
44
https://jupyterlab.readthedocs.io/en/stable/developer/css.html
55
*/
6+
7+
.jp-tweak-open-in-voila-button[aria-pressed='true'] {
8+
box-shadow: none !important;
9+
}

0 commit comments

Comments
 (0)