Skip to content

Commit

Permalink
Create a new notebook with a specific kernel from the new dropdown (#…
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
jtpio and github-actions[bot] authored Feb 13, 2024
1 parent e49f77e commit d43911b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
8 changes: 7 additions & 1 deletion packages/docmanager-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
37 changes: 27 additions & 10 deletions packages/tree-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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',
});
}

const baseCommands = [
'terminal:create-new',
'console:create',
'filebrowser:create-new-file',
'filebrowser:create-new-directory',
];

newCommands.forEach((command) => {
newMenu.addItem({ command });
baseCommands.forEach((command) => {
newMenu.addItem({ command });
});
};

serviceManager.kernelspecs?.specsChanged.connect(() => {
newMenu.clearItems();
populateNewMenu();
});

populateNewMenu();

if (toolbarRegistry) {
toolbarRegistry.addFactory(
FILE_BROWSER_FACTORY,
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.
2 changes: 1 addition & 1 deletion ui-tests/test/smoke.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d43911b

Please sign in to comment.