From a0d17d036aea4f175054463bd139eb6ec55250d4 Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Fri, 18 Mar 2022 17:38:36 +0100 Subject: [PATCH] Add support for opening a document with a factory --- packages/application-extension/src/index.ts | 26 ++++----------------- packages/docmanager-extension/src/index.ts | 5 ++-- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/packages/application-extension/src/index.ts b/packages/application-extension/src/index.ts index 7b567383a2f..40f3b2d00d8 100644 --- a/packages/application-extension/src/index.ts +++ b/packages/application-extension/src/index.ts @@ -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 */ @@ -179,18 +169,12 @@ const opener: JupyterFrontEndPlugin = { } 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' + }); }); } }); diff --git a/packages/docmanager-extension/src/index.ts b/packages/docmanager-extension/src/index.ts index 7c9dd1dce1c..cc8da84d8f3 100644 --- a/packages/docmanager-extension/src/index.ts +++ b/packages/docmanager-extension/src/index.ts @@ -40,8 +40,9 @@ const opener: JupyterFrontEndPlugin = { return; } const ext = PathExt.extname(path); - const route = ext === '.ipynb' ? 'notebooks' : 'edit'; - window.open(`${baseUrl}${route}/${path}`); + const route = + widgetName !== 'Notebook' || ext !== '.ipynb' ? 'edit' : 'notebooks'; + window.open(`${baseUrl}${route}/${path}?factory=${widgetName}`); return undefined; }; }