Skip to content

Commit

Permalink
Add support for opening a document with a factory
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpio committed Mar 18, 2022
1 parent c133317 commit a0d17d0
Show file tree
Hide file tree
Showing 2 changed files with 8 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
5 changes: 3 additions & 2 deletions packages/docmanager-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
Expand Down

0 comments on commit a0d17d0

Please sign in to comment.