Add support for opening a document with a factory

Jeremy Tuloup 4 years ago
parent 3d058906ae
commit 798c249d52

@ -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<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'
});
});
}
});

@ -40,8 +40,9 @@ const opener: JupyterFrontEndPlugin<void> = {
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;
};
}

Loading…
Cancel
Save