Skip to content

Commit

Permalink
Create a specialized MimeDocument document widget type.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongrout committed May 12, 2018
1 parent 3fc6bde commit 1107f69
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/application/src/mimerenderers.ts
Expand Up @@ -6,7 +6,7 @@ import {
} from '@jupyterlab/apputils';

import {
IDocumentWidget, MimeDocumentFactory, DocumentRegistry, MimeContent
MimeDocumentFactory, DocumentRegistry, MimeDocument
} from '@jupyterlab/docregistry';

import {
Expand Down Expand Up @@ -104,7 +104,7 @@ function createRendermimePlugin(item: IRenderMime.IExtension): JupyterLabPlugin<

const factoryName = factory.name;
const namespace = `${factoryName}-renderer`;
const tracker = new InstanceTracker<IDocumentWidget<MimeContent>>({ namespace });
const tracker = new InstanceTracker<MimeDocument>({ namespace });

// Handle state restoration.
restorer.restore(tracker, {
Expand Down
11 changes: 7 additions & 4 deletions packages/docregistry/src/mimedocument.ts
Expand Up @@ -30,7 +30,7 @@ import {
} from './default';

import {
DocumentRegistry, IDocumentWidget
DocumentRegistry
} from './registry';


Expand Down Expand Up @@ -216,12 +216,15 @@ namespace MimeContent {
}
}

export
class MimeDocument extends DocumentWidget<MimeContent> {
}

/**
* An implementation of a widget factory for a rendered mimetype document.
*/
export
class MimeDocumentFactory extends ABCWidgetFactory<IDocumentWidget<MimeContent>, DocumentRegistry.IModel> {
class MimeDocumentFactory extends ABCWidgetFactory<MimeDocument, DocumentRegistry.IModel> {
/**
* Construct a new markdown widget factory.
*/
Expand All @@ -236,7 +239,7 @@ class MimeDocumentFactory extends ABCWidgetFactory<IDocumentWidget<MimeContent>,
/**
* Create a new widget given a context.
*/
protected createNewWidget(context: DocumentRegistry.Context): IDocumentWidget<MimeContent> {
protected createNewWidget(context: DocumentRegistry.Context): MimeDocument {
const ft = this._fileType;
const mimeType = ft.mimeTypes.length ? ft.mimeTypes[0] : 'text/plain';

Expand All @@ -256,7 +259,7 @@ class MimeDocumentFactory extends ABCWidgetFactory<IDocumentWidget<MimeContent>,
content.title.iconClass = ft.iconClass;
content.title.iconLabel = ft.iconLabel;

const widget = new DocumentWidget({ content, context });
const widget = new MimeDocument({ content, context });

return widget;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/markdownviewer-extension/src/index.ts
Expand Up @@ -10,7 +10,7 @@ import {
} from '@jupyterlab/apputils';

import {
MimeDocumentFactory, MimeContent, IDocumentWidget
MimeDocumentFactory, MimeDocument
} from '@jupyterlab/docregistry';

import {
Expand Down Expand Up @@ -58,7 +58,7 @@ function activate(app: JupyterLab, restorer: ILayoutRestorer, rendermime: IRende
});
const { commands } = app;
const namespace = 'rendered-markdown';
const tracker = new InstanceTracker<IDocumentWidget<MimeContent>>({ namespace });
const tracker = new InstanceTracker<MimeDocument>({ namespace });

app.docRegistry.addWidgetFactory(factory);

Expand Down

0 comments on commit 1107f69

Please sign in to comment.