Skip to content

Commit

Permalink
Merge pull request #6315 from jtpio/factories
Browse files Browse the repository at this point in the history
Add support for opening a document with a different factory
  • Loading branch information
jtpio committed Mar 21, 2022
2 parents 3d05890 + d9e050f commit 9be03f5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
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

0 comments on commit 9be03f5

Please sign in to comment.