Skip to content

Commit

Permalink
Auto-generate a help string for the setting with available viewers and
Browse files Browse the repository at this point in the history
file types.
  • Loading branch information
ian-r-rose authored and afshin committed Aug 22, 2019
1 parent a210fa5 commit cf7dc8b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/docmanager-extension/package.json
Expand Up @@ -45,6 +45,7 @@
"@jupyterlab/services": "^4.1.0-alpha.2",
"@jupyterlab/statusbar": "^1.1.0-alpha.2",
"@phosphor/algorithm": "^1.1.3",
"@phosphor/coreutils": "^1.3.1",
"@phosphor/disposable": "^1.2.0",
"@phosphor/widgets": "^1.8.0"
},
Expand Down
1 change: 1 addition & 0 deletions packages/docmanager-extension/schema/plugin.json
Expand Up @@ -3,6 +3,7 @@
"description": "Document Manager settings.",
"jupyter.lab.setting-icon-class": "jp-FileIcon",
"jupyter.lab.setting-icon-label": "Document Manager",
"jupyter.lab.transform": true,
"jupyter.lab.shortcuts": [
{
"command": "docmanager:save",
Expand Down
49 changes: 45 additions & 4 deletions packages/docmanager-extension/src/index.ts
@@ -1,10 +1,6 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import { some, map, each } from '@phosphor/algorithm';

import { Widget } from '@phosphor/widgets';

import {
ILabShell,
ILabStatus,
Expand Down Expand Up @@ -37,8 +33,14 @@ import { Contents, Kernel } from '@jupyterlab/services';

import { IStatusBar } from '@jupyterlab/statusbar';

import { each, map, some, toArray } from '@phosphor/algorithm';

import { JSONExt } from '@phosphor/coreutils';

import { IDisposable } from '@phosphor/disposable';

import { Widget } from '@phosphor/widgets';

/**
* The command IDs used by the document manager plugin.
*/
Expand Down Expand Up @@ -189,6 +191,45 @@ const docManagerPlugin: JupyterFrontEndPlugin<IDocumentManager> = {
console.error(reason.message);
});

// Register a fetch transformer for the settings registry,
// allowing us to dynamically populate a help string with the
// available document viewers and file types for the default
// viewer overrides.
settingRegistry.transform(pluginId, {
fetch: plugin => {
// Get the available file types.
const fileTypes = toArray(registry.fileTypes())
.map(ft => ft.name)
.join(' \n');
// Get the available widget factories.
const factories = toArray(registry.widgetFactories())
.map(f => f.name)
.join(' \n');
// Generate the help string.
const description = `Overrides for the default viewers for file types.
Specify a mapping from file type name to document viewer name, for example:
defaultViewers: {
markdown: "Markdown Preview"
}
If you specify non-existent file types or viewers, or if a viewer cannot
open a given file type, the override will not function.
Available viewers:
${factories}
Available file types:
${fileTypes}`;
const schema = JSONExt.deepCopy(plugin.schema);
schema.properties.defaultViewers.description = description;
return { ...plugin, schema };
}
});
// If the document registry gains or loses a factory or file type,
// regenerate the settings description with the available options.
registry.changed.connect(() => settingRegistry.reload(pluginId));

return docManager;
}
};
Expand Down

0 comments on commit cf7dc8b

Please sign in to comment.