本文整理汇总了TypeScript中@jupyterlab/docregistry.IDocumentRegistry.addModelFactory方法的典型用法代码示例。如果您正苦于以下问题:TypeScript IDocumentRegistry.addModelFactory方法的具体用法?TypeScript IDocumentRegistry.addModelFactory怎么用?TypeScript IDocumentRegistry.addModelFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@jupyterlab/docregistry.IDocumentRegistry
的用法示例。
在下文中一共展示了IDocumentRegistry.addModelFactory方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: activateNotebookHandler
/**
* Activate the notebook handler extension.
*/
function activateNotebookHandler(app: JupyterLab, registry: IDocumentRegistry, services: IServiceManager, rendermime: IRenderMime, mainMenu: IMainMenu, palette: ICommandPalette, contentFactory: NotebookPanel.IContentFactory, editorServices: IEditorServices, restorer: ILayoutRestorer, launcher: ILauncher | null): INotebookTracker {
const factory = new NotebookWidgetFactory({
name: FACTORY,
fileExtensions: ['.ipynb'],
modelName: 'notebook',
defaultFor: ['.ipynb'],
preferKernel: true,
canStartKernel: true,
rendermime,
contentFactory,
mimeTypeService: editorServices.mimeTypeService
});
const shell = app.shell;
const tracker = new NotebookTracker({ namespace: 'notebook', shell });
// Handle state restoration.
restorer.restore(tracker, {
command: 'file-operations:open',
args: panel => ({ path: panel.context.path, factory: FACTORY }),
name: panel => panel.context.path,
when: services.ready
});
registry.addModelFactory(new NotebookModelFactory({}));
registry.addWidgetFactory(factory);
registry.addFileType({
name: 'Notebook',
extension: '.ipynb',
contentType: 'notebook',
fileFormat: 'json'
});
registry.addCreator({
name: 'Notebook',
fileType: 'Notebook',
widgetName: 'Notebook'
});
addCommands(app, services, tracker);
populatePalette(palette);
let id = 0; // The ID counter for notebook panels.
factory.widgetCreated.connect((sender, widget) => {
// If the notebook panel does not have an ID, assign it one.
widget.id = widget.id || `notebook-${++id}`;
widget.title.icon = NOTEBOOK_ICON_CLASS;
// Notify the instance tracker if restore data needs to update.
widget.context.pathChanged.connect(() => { tracker.save(widget); });
// Add the notebook panel to the tracker.
tracker.add(widget);
});
// Add main menu notebook menu.
mainMenu.addMenu(createMenu(app), { rank: 20 });
// Add a launcher item if the launcher is available.
if (launcher) {
launcher.add({
args: { creatorName: 'Notebook' },
command: 'file-operations:create-from',
name: 'Notebook'
});
}
app.contextMenu.addItem({command: CommandIDs.clearOutputs, selector: '.jp-Notebook .jp-Cell'});
app.contextMenu.addItem({command: CommandIDs.split, selector: '.jp-Notebook .jp-Cell'});
app.contextMenu.addItem({ type: 'separator', selector: '.jp-Notebook', rank: 0 });
app.contextMenu.addItem({command: CommandIDs.undo, selector: '.jp-Notebook', rank: 1});
app.contextMenu.addItem({command: CommandIDs.redo, selector: '.jp-Notebook', rank: 2});
app.contextMenu.addItem({ type: 'separator', selector: '.jp-Notebook', rank: 0 });
app.contextMenu.addItem({command: CommandIDs.createConsole, selector: '.jp-Notebook', rank: 3});
return tracker;
}