Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading