Create a new notebook with a specific kernel from the new dropdown (#7255)

* Create a new notebook with a specific kernel from the new dropdown

* update smoke test

* Update Playwright Snapshots

* Update Playwright Snapshots

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Jeremy Tuloup 2024-02-13 09:45:14 +01:00 committed by GitHub
parent e49f77ea12
commit d43911b23e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 35 additions and 12 deletions

View File

@ -40,7 +40,10 @@ const opener: JupyterFrontEndPlugin<IDocumentWidgetOpener> = {
const pathOpener = notebookPathOpener ?? defaultNotebookPathOpener;
let id = 0;
return new (class {
open(widget: IDocumentWidget, options?: DocumentRegistry.IOpenOptions) {
async open(
widget: IDocumentWidget,
options?: DocumentRegistry.IOpenOptions
) {
const widgetName = options?.type ?? '';
const ref = options?.ref;
// check if there is an setting override and if it would add the widget in the main area
@ -54,6 +57,9 @@ const opener: JupyterFrontEndPlugin<IDocumentWidgetOpener> = {
(widgetName === 'default' && ext === '.ipynb') ||
widgetName.includes('Notebook')
) {
// make sure to save the notebook before opening it in a new tab
// so the kernel info is saved
await widget.context.save();
route = 'notebooks';
}
// append ?factory only if it's not the default

View File

@ -87,7 +87,7 @@ const createNew: JupyterFrontEndPlugin<void> = {
translator: ITranslator,
toolbarRegistry: IToolbarWidgetRegistry | null
) => {
const { commands } = app;
const { commands, serviceManager } = app;
const trans = translator.load('notebook');
const overflowOptions = {
@ -99,18 +99,35 @@ const createNew: JupyterFrontEndPlugin<void> = {
newMenu.title.icon = caretDownIcon;
menubar.addMenu(newMenu);
const newCommands = [
'notebook:create-new',
'terminal:create-new',
'console:create',
'filebrowser:create-new-file',
'filebrowser:create-new-directory',
];
const populateNewMenu = () => {
// create an entry per kernel spec for creating a new notebook
const specs = serviceManager.kernelspecs?.specs?.kernelspecs;
for (const name in specs) {
newMenu.addItem({
args: { kernelName: name, isLauncher: true },
command: 'notebook:create-new',
});
}
newCommands.forEach((command) => {
newMenu.addItem({ command });
const baseCommands = [
'terminal:create-new',
'console:create',
'filebrowser:create-new-file',
'filebrowser:create-new-directory',
];
baseCommands.forEach((command) => {
newMenu.addItem({ command });
});
};
serviceManager.kernelspecs?.specsChanged.connect(() => {
newMenu.clearItems();
populateNewMenu();
});
populateNewMenu();
if (toolbarRegistry) {
toolbarRegistry.addFactory(
FILE_BROWSER_FACTORY,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 7.9 KiB

View File

@ -27,7 +27,7 @@ test.describe('Smoke', () => {
const [notebook] = await Promise.all([
page.waitForEvent('popup'),
page.click('text="New"'),
page.click('text="Notebook"'),
page.click('text="Python 3 (ipykernel)"'),
]);
try {