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

Add support for opening a document with a different factory #6315

Merged
merged 3 commits into from
Mar 21, 2022
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
26 changes: 5 additions & 21 deletions packages/application-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,6 @@ import { DisposableDelegate, DisposableSet } from '@lumino/disposable';

import { Widget } from '@lumino/widgets';

/**
* The default notebook factory.
*/
const NOTEBOOK_FACTORY = 'Notebook';

/**
* The editor factory.
*/
const EDITOR_FACTORY = 'Editor';

/**
* A regular expression to match path to notebooks and documents
*/
Expand Down Expand Up @@ -179,18 +169,12 @@ const opener: JupyterFrontEndPlugin<void> = {
}

const file = decodeURIComponent(path);
const ext = PathExt.extname(file);
const urlParams = new URLSearchParams(parsed.search);
const factory = urlParams.get('factory') ?? 'default';
app.restored.then(async () => {
// TODO: get factory from file type instead?
if (ext === '.ipynb') {
docManager.open(file, NOTEBOOK_FACTORY, undefined, {
ref: '_noref'
});
} else {
docManager.open(file, EDITOR_FACTORY, undefined, {
ref: '_noref'
});
}
docManager.open(file, factory, undefined, {
ref: '_noref'
});
});
}
});
Expand Down
15 changes: 13 additions & 2 deletions packages/docmanager-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,19 @@ const opener: JupyterFrontEndPlugin<void> = {
return;
}
const ext = PathExt.extname(path);
const route = ext === '.ipynb' ? 'notebooks' : 'edit';
window.open(`${baseUrl}${route}/${path}`);
let route = 'edit';
if (
(widgetName === 'default' && ext === '.ipynb') ||
widgetName === 'Notebook'
) {
route = 'notebooks';
}
let url = `${baseUrl}${route}/${path}`;
// append ?factory only if it's not the default
if (widgetName !== 'default') {
url = `${url}?factory=${widgetName}`;
}
window.open(url);
return undefined;
};
}
Expand Down