Skip to content

Commit

Permalink
Explicitely fetch the overrides from the settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpio committed Jun 19, 2023
1 parent c7fc3d2 commit 4fb40f2
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions packages/application-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,18 @@ const opener: JupyterFrontEndPlugin<void> = {
id: '@jupyter-notebook/application-extension:opener',
autoStart: true,
requires: [IRouter, IDocumentManager],
optional: [ISettingRegistry],
activate: (
app: JupyterFrontEnd,
router: IRouter,
docManager: IDocumentManager
docManager: IDocumentManager,
settingRegistry: ISettingRegistry | null
): void => {
const { commands, docRegistry } = app;

const command = 'router:tree';
commands.addCommand(command, {
execute: (args: any) => {
execute: async (args: any) => {
const parsed = args as IRouter.ILocation;
const matches = parsed.path.match(TREE_PATTERN) ?? [];
const [, , path] = matches;
Expand All @@ -198,8 +200,32 @@ const opener: JupyterFrontEndPlugin<void> = {
app.started.then(async () => {
const file = decodeURIComponent(path);
const urlParams = new URLSearchParams(parsed.search);
const defaultFactory = docRegistry.defaultWidgetFactory(path);
const factory = urlParams.get('factory') ?? defaultFactory.name;
let defaultFactory = docRegistry.defaultWidgetFactory(path).name;

// Explicitely get the default viewers from the settings because
// JupyterLab might not have had the time to load the settings yet (race condition)
if (settingRegistry) {
const settings = await settingRegistry.load(
'@jupyterlab/docmanager-extension:plugin'
);
// Handle default widget factory overrides.
const defaultViewers = settings.get('defaultViewers').composite as {
[ft: string]: string;
};

// get the file types for the path
const types = docRegistry.getFileTypesForPath(path);
types.forEach((ft) => {
if (
defaultViewers[ft.name] !== undefined &&
docRegistry.getWidgetFactory(defaultViewers[ft.name])
) {
defaultFactory = defaultViewers[ft.name];
}
});
}

const factory = urlParams.get('factory') ?? defaultFactory;
docManager.open(file, factory, undefined, {
ref: '_noref',
});
Expand Down

0 comments on commit 4fb40f2

Please sign in to comment.